Giter Site home page Giter Site logo

haizhiyun / log4a Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pqpo/log4a

0.0 2.0 0.0 5.71 MB

:octocat:Log4a is an mmap based, high-performance, highly available Android log collection library

Home Page: https://pqpo.me

License: Apache License 2.0

Java 73.69% CMake 3.44% C++ 22.86%

log4a's Introduction

Log4a

(English | 中文)

Log4a is an mmap based, high-performance, highly available Android log collection framework

WHY Log4a:

If you like, welcome start, fork or follow me.

Log4a uses file mapping memory(mmap) as a cache, that the integrity of the log can be guaranteed without sacrificing performance. The log will be first written to file mapping memory, based on the mmap feature, even if the user kill the process, the log data will not be lost, and will write back to the log file at the next time Log4a is initialized.

For mobile developers, with some users's online feedback which is difficult to reproduce the problem, analysis of the log is sometimes necessary to solve the problem. However, the collection of logs has always been a pain point, that is, performance and log integrity can not have both. To achieve high-performance log collection, it is bound to use a lot of memory, the first write the log into memory, and then at the right time to write the log which in memory to the file system (flush) If flushing before the user kill the process, then the contents of the memory will be lost. Real-time write log to file can be written to ensure the integrity of the log, but the write file is a IO operation, involves the user mode and kernel state switch, compared to write directly to the memory will be more time-consuming, frequent writes in the UI thread file will cause Caton , Affect the user experience.

HOW:

Use the same way as the android.util.Log, the difference is that you need a simple configuration, of course, also reserves a wealth of interfaces for expansion of use, more advanced configuration can view Sample;

  1. Add dependencies in the build.gradle file:
allprojects {
	repositories {
		maven { url 'https://jitpack.io' }
	}
}
	
dependencies {
    compile 'com.github.pqpo:Log4a:{last-version}'
}
  1. Set and initialize Log4a::
AndroidAppender.Builder androidBuild = new AndroidAppender.Builder();

File log = FileUtils.getLogDir(context);
String log_path = log.getAbsolutePath() + File.separator + "log.txt";
FileAppender.Builder fileBuild = new FileAppender.Builder(context)
                          .setLogFilePath(log_path);
                          
Logger logger = new Logger.Builder()
          .enableAndroidAppender(androidBuild)
          .enableFileAppender(fileBuild)
          .create();
          
Log4a.setLogger(logger);
  1. Use the same way as the android.util.Log:
Log4a.i(TAG, "Hello,Log4a!");
  1. Choose to refresh the cache ** or ** free the memory at the right time
Log4a.flush();
//or
Log4a.release();

Performance Testing

you can download Sample APK for testing on your device.。

The following are the test cases for writing 1w logs in Google Pixel and Moto X:

Google Pixel Moto X

Google pixel on the chart test data as follows (sorted by elapsed time):

device test type time consumed complete? persistent? complete after kill the process?
Google Pixel Mem 13ms Y N N
Google Pixel Log4a 50ms Y Y Y
Google Pixel File with Buffer 61ms Y Y N
Google Pixel Android Log 184ms N N N
Google Pixel File no Buffer 272ms Y Y Y

Log4a can be seen writing the performance of the log behind direct write memory, and the use of BufferOutputStream write the same file, in fact, in order to ensure multi-threaded security, Log4a write mmap memory are locked, unlocked Case can be closer to write the speed of memory (interested are free to test). BufferOutputStream is the first data cache in memory, and then refresh the file, if the power was removed before the refresh or kill the process, then the memory data will be lost can not be restored. Log4a will restore the log file the next time you start to ensure the integrity of the log.

CHANGE LOG

see change log file

Thanks


About Me:

License

Copyright 2017 pqpo

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

log4a's People

Contributors

pqpo avatar

Watchers

 avatar  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.