coo

Coolog

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

Showing:

Popularity

Downloads/wk

0

GitHub Stars

86

Maintenance

Last Commit

3yrs ago

Contributors

0

Package

Dependencies

1

License

MIT

Categories

Readme

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, liyaoxjtu2013@gmail.com

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.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100