Giter Site home page Giter Site logo

xiamingling / coolog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ryanleely/coolog

0.0 0.0 0.0 3.49 MB

A expandable and flexible log framework for iOS. iOS一个灵活、可扩展的日志组件。

Home Page: https://github.com/RyanLeeLY/Coolog

License: MIT License

Ruby 2.06% Objective-C 76.96% HTML 1.07% Vue 16.57% JavaScript 3.34%

coolog's Introduction

Coolog

Coolog is a expandable and flexible log framework for iOS. It provides a browser logging tool that can replace xcode console.

CI Status Version License Platform

Features

  • Simple Coolog has a simple usage. We make it as simple as possible to setup Coolog. Also, we provides some simplified methods of basic function.

  • Flexible Coolog provides multiple log methods (Console, NSLog and File) and log-level.

  • Expandable You can even customize your own logger and formatter, which are components of log-driver. Then your customized log-driver can also be added to log-engine. Do whatever you want in your customized logger.

  • Web Browser Tool Coolog provides a web browser tool, which makes it easy to debug.

BrowserTool

Installation

cocoapods

pod 'Coolog'

Architecture

Architecture

Usage

Setup

[[COLLogManager sharedInstance] setup];
    
[[COLLogManager sharedInstance] enableFileLog];  // open file log
[[COLLogManager sharedInstance] enableConsoleLog];  // open xcode console log
//    [[COLLogManager sharedInstance] enableNSLog];
    
#ifdef DEBUG
    [COLLogManager sharedInstance].level = COLLogLevelAll;
#else
    [COLLogManager sharedInstance].level = COLLogLevelInfo;
#endif

Log

CLogError(@"tag", @"%@", @"log content");
	
CLogWarning(@"tag", @"%@", @"log content");
	
CLogInfo(@"tag", @"%@", @"log content");
	
CLogDefault(@"tag", @"%@", @"log content");
	
CLogDebug(@"tag", @"%@", @"log content");

Web Browser Tool

[[COLLogManager sharedInstance] enableRemoteConsole];

Make sure your pc and your phone under the same wifi. Open your web browser and visit [http://coolog.oss-cn-hangzhou.aliyuncs.com/index.html?host=ws://YourPhoneIPAddr:9001/coolog]

Advanced

The section below will introduce how to customize your own logger. You can follow 3 steps below.

  • Step 1: Implement your own logger.
#import "COLLogger.h"
@interface MyLogger : NSObject <COLLogger>

@end
#import "MyLogger.h"
#import <os/log.h>

@implementation MyLogger
@synthesize formatterClass = _formatterClass;

+ (instancetype)logger {
    return [[MyLogger alloc] init];
}

// This is your own log method. It will be called by log engine. 
- (void)log:(NSString *)logString {
	//For example, here below uses os_log as its implementation.
    os_log(OS_LOG_DEFAULT, "%{public}s", [logString UTF8String]);
}
@end
  • Step 2: Implement your own formatter.
#import "COLLogFormatter.h"

@interface MyLogFormatter : NSObject <COLFormatable>

@end
#import "MyLogFormatter.h"

@implementation MyLogFormatter
// The log's format depends on this method.
- (NSString *)completeLogWithType:(COLLogType)type tag:(NSString *)tag message:(NSString *)message date:(NSDate *)date {
    return [NSString stringWithFormat:@"tag=[%@], type=[%zd], message=[%@], date=[%@]", tag, type, message, date];
}
@end
  • Step 3: Add your logger to log engine.
COLLoggerDriver *myDriver = [[COLLoggerDriver alloc] initWithLogger:[MyLogger logger]
                                                              formatter:[[MyLogFormatter alloc] init]
                                                                  level:COLLogLevelInfo];
[[COLLogManager sharedInstance].logEngine addDriver:myDriver];

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

TODO

  • Web browser Tool UI
  • Performance
  • Unit test
  • Swift version

Author

yao.li, [email protected]

Thanks

Coolog start a WebSocket server on your phone to send log data to your browser. We built this server using PocketSocket. Special thanks to PocketSocket and its contributors.

License

Coolog is available under the MIT license. See the LICENSE file for more info.

coolog's People

Contributors

ryanliyao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.