• Stars
    star
    963
  • Rank 47,492 (Top 1.0 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 7 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

:octocat:Log4a is an mmap based, high-performance, highly available Android log collection library / Log4a 是一个基于 mmap, 高性能、高可用的 Android 日志收集框架

Log4a

(English | 中文)

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

WHY Log4a:

If you like, welcome to star/fork it 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:
    https://github.com/pqpo/Log4a/blob/master/app/src/main/java/me/pqpo/log4a/LogInit.java

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

More Repositories

1

SmartCropper

🔥 A library for cropping image in a smart way that can identify the border and correct the cropped image. 智能图片裁剪框架。自动识别边框,手动调节选区,使用透视变换裁剪并矫正选区;适用于身份证,名片,文档等照片的裁剪。
Java
3,924
star
2

SmartCamera

📷SmartCamera 是一个 Android 相机拓展库,能够实时采集并且识别相机内物体边框是否吻合指定区域。SmartCamera is an Android camera extension library,provides a scanning module that can recognizes whether the object's border inside the camera matches the area in real time.
Java
1,254
star
3

InputMethodHolder

A keyboard listener for Android which by hooking the InputMethodManager. 通过hook监听系统键盘显示
Java
424
star
4

MethodHook

hook java methods
Java
134
star
5

PLock

🔐PLock is a simple and efficient cross-process lock, also support read-write lock. (简单高效的跨进程锁,支持读写锁分离)
Java
105
star
6

AIPoet

基于人工智能(障)的 Android 写诗应用,无须联网随时随地写藏头诗,意境诗。娱乐、学习为主!
Kotlin
91
star
7

CppPrimer

c++学习代码
C++
18
star
8

ServiceAndIpcDemo

Service lifecycle and IPC Demo
Java
11
star
9

MvpGenerator

IntelliJ Idea 插件,生成Mvp模板代码
Java
7
star
10

load_another_app_resource

Load another application's resource like RemoteView do, just for fun!(像 RemoteView 一样加载其他应用的资源)
Java
6
star
11

start_undeclared_activity

Start an activity that is not declared in the AndroidManifest.xml (It's a demo, just for fun) 启动一个未注册的 Activity
Java
4
star
12

appiumn_auto_re-develope

Louis-me/appiumn_auto 该项目二次开发,以适应测试人员使用(无需编写任何python代码)
Python
3
star
13

registration_api

远程挂号系统api
Java
2
star
14

SimpleEncrypt

简单文件加密
Java
1
star
15

pqpo.github.io

HTML
1
star
16

android.asyncImageLoader

异步图像加载工具,可设置本地缓存,内存缓存,内存缓存使用弱引用防止内存溢出
Java
1
star