jlog


Source link: https://github.com/JiongBull/jlog

jlog

jlog is a useful log tool for android developers which was inspired by these projects:

Combining with work experience, i made this libriary.

Hope you enjoy it. ( ^_^ )

????

Features

  • Compatible with android logcat, you can use VERBOSE, DEBUG, INFO, WARN, ERROR and WTF as well
  • In JSON mode, formats json content in a pretty way
  • Jlog provides caller's class, method and line information, you can even jump to source from the console
  • Simplify logcat, uses caller's class name as TAG(custom TAG supported as well).
  • Overcome logcat's 4000 words limit
  • Jlog can output logs to a specified file in a specified directory
  • You can decide logs in which level can be outputted to file
  • At the top of log file, provides a lot of useful information about running environment, such os information, device information, apk information
  • Jlog formats logs in files in a pretty way, and provides enough information, such as time, level, thread and caller's positon
  • Jlog works well with proguard
  • Support setting log file's time format
  • Support setting log file's timezone
  • Logs are divied into separate files by time segment, default is 24H, file's name is like 2016-01-19.log, you can set prefix and segment of time, such as ${ userid } _2016-01-19_2021.log
  • Support setting disk's capacity for logs
  • Support uploading logs to qiniu
  • Support extending
  • TimingLogger can log the time of method proceeding

Dependency

Add the repository to the root's build.gradle.

allprojects {
  repositories {

  jcenter()
  maven {
 url "https://jitpack.io" 
}
  
}

And add dependencies to the module's build.gradle.

dependencies {

compile 'com.github.JiongBull:jlog:0.1.0' 
}

Configuration

Initialization

It is recommend that initializing jlog's global configuration in your application's onCreate() method, then we can use it everywhere.

public class RootApp extends Application {

private static Logger sLogger;

@Override
  public void onCreate() {

super.onCreate();

List<String> logLevels = new ArrayList<>();

logLevels.add(LogLevel.ERROR);

logLevels.add(LogLevel.WTF);

 sLogger = Logger.Builder.newBuilder(getApplicationContext(), "jlog")

  /* properties below are default value, you can modify them or not. */

  .setDebug(true)

  .setWriteToFile(false)

  .setLogDir("jlog")

  .setLogPrefix("")

  .setLogSegment(LogSegment.TWELVE_HOURS)

  .setLogLevelsForFile(logLevels)

  .setZoneOffset(TimeUtils.ZoneOffset.P0800)

  .setTimeFormat("yyyy-MM-dd HH:mm:ss")

  .setPackagedLevel(0)

  .setStorage(null)

  .build();

  
}

public static Logger getLogger() {

return sLogger;
  
}
 
}

All properties are saved in Logger's object after build . Modify it's properties, it will work next time.

For example:

logger.setWriteToFile(true);

If your app's targetSdkVersion is 23+, don't forget to apply for android.permission.WRITE_EXTERNAL_STORAGE permission in your splash or main activity.

setDebug(boolean)

Default is true, logs will be outputed to the console. Pls set this variable as false when release your app.

logger.setDebug(false);

or

logger.setDebug(BuildConfig.DEBUG);

writeToFile(boolean)

If true, logs will output to file, default is false.

  logger.writeToFile(true);

setLogDir(String)

Configure the directory which saving logs, the directory is located in external sdcard and default name is jlog.

You can use your app's name as directory's name.

logger.setLogDir(getString(R.string.app_name));

Sub directory is supported as well, you can use some unique words as sub directory's name, such as user id.

logger.setLogDir(getString(R.string.app_name) + File.separator + ${
userid
}
);

setLogPrefix(String)

If you don't want use sub directory for logs, you may try prefix for log file.

logger.setLogPrefix("JiongBull");

setLogSegment(LogSegment)

Logs are divied into separate files by time segment, default is 24H, file's name is like 2016-01-19.log, if it is setted to LogSegment.ONE_HOUR, file's name is like 2016-01-19_0203, which means logs were recorded from 2:00 to 3:00.

logger.setLogSegment(LogSegment.ONE_HOUR);

setLogLevelsForFile(List)

This method decides logs in which level can be outputted to file. Default are LogLevel.ERROR and LogLevel.WTF.

List<LogLevel> logLevels = new ArrayList<>();
 logLevels.add(LogLevel.INFO);
 logLevels.add(LogLevel.ERROR);
 logger.setLogLevelsForFile(logLevels);

setZoneOffset(ZoneOffset)

We can specify log's time zone no matter where user from, this method make it easy to find bugs, default is ZoneOffset.P0800(+0800), which means "Beijing time".

logger.setZoneOffset(ZoneOffset.P0800);

setTimeFormat(String)

Default time format is yyyy-MM-dd HH:mm:ss, you can use this method to make it easy to understand.

logger.setTimeFormat("yyyy?MM?dd? HH?mm?ss?");

setPackagedLevel(int)

If you want to extend jlog, please set package's level(hierarchy), otherwise, jlog can't get invoker's info.

logger.setPackagedLevel(1);

setStorage(IStorage)

You can implement IStorage interface, upload logs to remote server in upload method, it will be invoked every fifteen minutes.

logger.setStorage(new IStorage() {

  @Override
  public void upload(@NonNull Logger logger) {

// upload logs to remote server
  
}
 
}
)

There are two predefined IStorage implement, you can use them directly.

  • jlog-storage-qiniu, upload logs to qiniu automatically
  • jlog-storage-disk, set disk's capacity for logs, when over capacity, it will delete files according to the last modified time of files in log directory

Usage

logger.v(String)

Jlog will use caller's class name as default tag.

logger.v(TAG, String)

You can specify TAG as well.

logger.json(json)

Jlog formats json content in a pretty way

About me

Resources

Base and simple List, Recycler and Spinner adapters for the Android platform.

A customisable decimal and hexadecimal material picker view for Android.

A customizable adapter for RecyclerView.

DateTimeTemplate is date/time formatting library supporting formatting placeholders, i.e. Today is %DDD%, %k%:%ii% %a% once formatted would produce Today is Wednesday, 6:21a. Supports abbreviated day/month names, 12/24hrs clocks, leading-zero values and localization.

You can use like using just ImageView and you can get color from any images.

A bubble bicker library.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes