Git Product home page Git Product logo

logan's Introduction

Logan

license Release Version PRs Welcome Platform Support

Logan is a lightweight case logging system based on mobile platform.

中文说明

Logan

Getting started

Android

Prerequisites

If you want to build the source, make sure your NDK version is not higher than 16.1.4479499.

Installation

Add the following content in the project build.gradle file:

compile 'com.dianping.android.sdk:logan:1.2.2'

Usage

You must init Logan before you use it. For example:

LoganConfig config = new LoganConfig.Builder()
        .setCachePath(getApplicationContext().getFilesDir().getAbsolutePath())
        .setPath(getApplicationContext().getExternalFilesDir(null).getAbsolutePath()
                + File.separator + "logan_v1")
        .setEncryptKey16("0123456789012345".getBytes())
        .setEncryptIV16("0123456789012345".getBytes())
        .build();
Logan.init(config);

After you init Logan, you can use Logan to write a log. Like this:

Logan.w("test logan", 1);

Logan.w method has two parameters:

  • String log: What you want to write;
  • int type: Log type. This is very important, best practices below content will show you how to using log type parameter.

If you want to write log to file immediately, you need to call flush function:

Logan.f();

If you want to see all of the log file information, you need to call getAllFilesInfo function:

Map<String, Long> map = Logan.getAllFilesInfo();
  • key: Log file date;
  • value: Log file size(Bytes).

Upload

Logan internal provides logging upload mechanism, in view of the need to upload the log to do the preprocessing. If you want to upload log file, you need to implement a SendLogRunnable:

public class RealSendLogRunnable extends SendLogRunnable {

    @Override
    public void sendLog(File logFile) {
      // logFile: After the pretreatment is going to upload the log file
      // Must Call finish after send log
      finish();
      if (logFile.getName().contains(".copy")) {
				logFile.delete();
			}
    }
}

NOTE: You must call finish method after send log. As written in the code above

Finally you need to call Logan.s method:

Logan.s(date, mSendLogRunnable);

One of the first parameter is date array(yyyy-MM-dd).

Permission

If you upload log file to server, you need INTERNET permission.

If you write log to SD card or read log info from SD card, you need WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permission

iOS & macOS

Installation

Logan supports CocoaPods methods for installing the library in a project.

Podfile

Import Logan in Xcode project, add Logan in podfile.

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

target 'TargetName' do
pod 'Logan', '~> 1.2.5'
end

Then run the following command:

$ pod install

Logan Init

You must init Logan before you use it:

#import "Logan.h"

NSData *keydata = [@"0123456789012345" dataUsingEncoding:NSUTF8StringEncoding]; 
NSData *ivdata = [@"0123456789012345" dataUsingEncoding:NSUTF8StringEncoding];
uint64_t file_max = 10 * 1024 * 1024;
// logan init,incoming 16-bit key,16-bit iv,largest written to the file size(byte)
loganInit(keydata, ivdata, file_max);

#if DEBUG
loganUseASL(YES);
#endif

Usage

Write a log:

logan(1, @"this is a test");

logan method has two parameters:

  • String log:What you want to write;
  • int type:Log type. This is very important, best practices below content will show you how to using log type parameter.

If you want to write log to file immediately, you need to call flush function:

loganFlush();

If you want to see all of the log file information, you need to call loganAllFilesInfo function:

NSDictionary *map = loganAllFilesInfo();
  • key Log file date;
  • value: Log file size(Bytes).

Upload

Logan provides a method for obtaining log files and performs preprocessing operations on the logs that need to be uploaded. Log can be uploaded by implementing the network upload function.

    loganUploadFilePath(loganTodaysDate(), ^(NSString *_Nullable filePatch) {
        if (filePatch == nil) {
            return;
        }
        NSString *urlStr = @"http://127.0.0.1:3000/logupload";
        NSURL *url = [NSURL URLWithString:urlStr];
        NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];
        [req setHTTPMethod:@"POST"];
        [req addValue:@"binary/octet-stream" forHTTPHeaderField:@"Content-Type"];
        NSURL *fileUrl = [NSURL fileURLWithPath:filePatch];
        NSURLSessionUploadTask *task = [[NSURLSession sharedSession] uploadTaskWithRequest:req fromFile:fileUrl completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error) {
            if (error == nil) {
                NSLog(@"upload success");
            } else {
                NSLog(@"upload failed. error:%@", error);
            }
        }];
        [task resume];
    });

Log parsing

java

Copy Logan/parser-java to your project.

Parsing log data

new LoganParser(Key16.getBytes(),Iv16.getBytes()).parse(InputStream, OutputStream)

node.js

Please refer to Example/Logan-Server/server.js.

Demo

How to use demo

Log protocol

Best Practices

Before Logan available, log report system is relatively scattered.

Before_Logan

To put it simply, the traditional idea is to piece together the problems that appear in the logs of each system, but the new idea is to aggregate and analyze all the logs generated by the user to find the scenes with problems.

The Logan core system consists of four modules:

  • Input
  • Storage
  • BackEnd
  • FrontEnd

Logan_Process

The new case analysis process is as follows:

Logan_Case

Article

A lightweight case logging system based on mobile platform developed by Meituan-Dianping — Logan

Logan: Open Source

Feature

In the future, we will provide a data platform based on Logan big data, including advanced functions such as machine learning, troubleshooting log solution, and big data feature analysis.

Finally, we hope to provide a more complete integrated case analysis ecosystem.

Logan_System

Module Open Source Processing Planning
iOS & macOS
Android
Web
Mini Programs
Back End
Front End

Contributing

For more information about contributing PRs and issues, see our Contribution Guidelines.

Authors

See also the list of contributors who participated in this project.

License

Logan is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

logan's People

Contributors

jiangteng avatar richard-cao avatar chenyihu avatar kemchenj avatar wrbug avatar lizhangqu avatar

Watchers

James Cloos 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.