Elvishew/xlog
Introduction to Framework Features
Global Config (tag, formatters ...) or log-based config
Support printing any object and customizable object formatter
Support Printing Array
Support Printing long log (No 4K limitation)
XML and JSON formatted
Thread information (thread name etc. Can be customized)
Stack trace information (configurable call stack depth, with file name, method name, line number)
Support Log Interceptors
Save logs in file (configurable file naming and backup strategy)
Good looking in Android Studio
Powerful in customization
Xlog supports array, object, XML, JSON and other data format printing, support log save local, support log level control. and format the print configuration.
Code section
Integration into the project:
S1. Add dependent compile ' com.elvishew:xlog:1.4.0 ' or import library source library;
S2. Initializing log;
S3. Call log;
API :
Initialize logconfiguration config=NewLogconfiguration.builder (). LogLevel (Buildconfig.debug? Loglevel.all//Specify log level, logs below-won ' t be printed, Default:LogLevel.ALL: Loglevel.none). Tag ("My_tag")//Specify TAG, default: "X-log". T ()//Enable thread info, disabled by default. ST (2)//Enable stack trace info with depth 2, disabled by default. B ()//Enable border, disabled by default. Jsonformatter (NewMyjsonformatter ())//Default:defaultjsonformatter. Xmlformatter (NewMyxmlformatter ())//Default:defaultxmlformatter. Throwableformatter (NewMythrowableformatter ())//Default:defaultthrowableformatter. Threadformatter (NewMythreadformatter ())//Default:defaultthreadformatter. Stacktraceformatter (NewMystacktraceformatter ())//Default:defaultstacktraceformatter. Borderformatter (NewMyboardformatter ())//Default:defaultborderformatter. Addobjectformatter (Anyclass.class,//ADD Formatter for specific class of object NewAnyclassobjectformatter ())//Use object.tostring () by default. Addinterceptor (NewBlacklisttagsfilterinterceptor (//ADD blacklist tags filter"Blacklist1", "Blacklist2", "Blacklist3"). Addinterceptor (NewMyinterceptor ())//Add a log interceptor. Build (); Printer Androidprinter=NewAndroidprinter ();//Printer that print the log using Android.util.LogPrinter Consoleprinter =NewConsoleprinter ();//Printer. Print the log to console using System.outPrinter Fileprinter =NewFileprinter//Printer that print the log to the file system. Builder ("/sdcard/xlog/")//specify the path to save log file. Filenamegenerator (NewDatefilenamegenerator ())//default:changelessfilenamegenerator ("log"). Backupstrategy (NewNeverbackupstrategy ())//Default:filesizebackupstrategy (1024x768). Logflattener (NewMyflattener ())//Default:defaultflattener. Build (); Xlog.init (//Initialize XLogConfig//Specify the log configuration, if not specified, would use new Logconfiguration.builder (). Build ()Androidprinter,//Specify printers, if no printer is specified, Androidprinter (for Android)/consoleprinter (for Java) would be used.consoleprinter,fileprinter); Log print: Xlog.d ("Simple Message") XLOG.D ("My name is%s", "Elvis"); XLOG.D ("An exception caught", exception); XLOG.D (object); XLOG.D (array); Xlog.json (unformattedjsonstring); Xlog.xml (unformattedxmlstring);
Reference:
Https://github.com/elvishew/xLog
Orhanobut/logger
Introduction to Framework Features
Simple, pretty and powerful logger for Android
Support basic information printing, object printing, Xml/json printing, format printing, the latest version has removed the log level control.
Code section
Integration into the project:
S1. Add dependent compile ' com.orhanobut:logger:2.1.1 ' or import library source library;
S2. Initialization of logger;
S3. Call logger;
API :
Initialize Formatstrategy formatstrategy=Prettyformatstrategy.newbuilder (). Showthreadinfo (false)//(Optional) Whether to show thread info or not. Default true. Methodcount (0)//(Optional) How many method line to show. Default 2. Methodoffset (7)//(Optional) Hides internal method calls up to offset. Default 5. Logstrategy (Customlog)//(Optional) changes the log strategy to print out. Default LogCat. Tag ("My Custom Tag")//(Optional) Global tag for every log. Default Pretty_logger. Build (); Logger.addlogadapter (NewAndroidlogadapter (formatstrategy)); Logger.addlogadapter (NewAndroidlogadapter () {@Override Public BooleanIsloggable (intPriority , String tag) { returnBuildconfig.debug; }}); Formatstrategy Formatstrategy=Csvformatstrategy.newbuilder (). Tag ("Custom"). build (); Logger.addlogadapter (NewDisklogadapter (formatstrategy)); Log print: LOGGER.D ("Debug"); LOGGER.E ("Error"); LOGGER.W ("Warning"); LOGGER.V ("Verbose"); LOGGER.I ("Information"); LOGGER.WTF ("WTF!!!!"); LOGGER.D ("Hello%s", "World"); LOGGER.D (MAP); LOGGER.D (SET); LOGGER.D (LIST); LOGGER.D (ARRAY); Logger.json (json_content); Logger.xml (xml_content);
Reference:
Https://github.com/orhanobut/logger
Pengwei1024/logutils
Introduction to Framework Features
Supports direct printing of data sets such as List, Set, Map, array, etc.
Global Configuration Log Output
Personalization tag
Accurate display of the calling method, line, quickly locate the file location
Supports Android system object intent, bundle printing
Release-no-op version available
Support Log Write file
Code section
Integration into the project:
S1. import library source database;
Compile ' com.apkfuns.logutils:library:1.5.1.1 '
Compile files (' Libs/okio-1.13.0.jar ')
S2. Initialization of Logutils;
S3. Call the log method;
Api:
initializes the Logutils.getlogconfig (). Configallowlog (true). Configtagprefix ("Myappname"). Configshowborders (true). Configformattag ("%d{hh:mm:ss:sss}%t%c{-5}"# supports writing logs to file Logutils.getlog2fileconfig (). Configlog2fileenable (true) //Targetsdkversion >= 23 need to ensure write SDcard permissions. Configlog2filepath ("/sdcard/project folder/logs/"). Configlog2filenameformat ("%d{yyyymmdd}.txt"). Configlogfileengine (Newlogfileenginefactory ()); Log Print://Output StringLOGUTILS.D ("12345");//Output ParametersLOGUTILS.D ("12%s3%d45", "a", 0);//Output ExceptionLOGUTILS.D (NewNullPointerException ("12345"));//Output ObjectPerson person =NewPerson ();p erson.setage (11);p Erson.setname ("Pengwei");p Erson.setscore (37.5f); LOGUTILS.D (person);//object is emptyLOGUTILS.D (NULL);//output JSON (JSON default debug print)String json = "{' A ': ' B ', ' C ': {' AA ': 234, ' dd ': {' AZ ': 12}}}"; Logutils.json (JSON);//Print Data collectionList<person> List1 =NewArraylist<>(); for(inti = 0; I < 4; i++{list1.add (person);} LOGUTILS.D (list1);//Print ArrayDouble[] Doubles = {{1.2, 1.6, 1.7, 30, 33}, {1.2, 1.6, 1.7, 30, 33}, {1.2, 1.6, 1.7, 30, 33}, {1.2, 1.6, 1.7, 30, 33}}; LOGUTILS.D (doubles);//Custom TagLogutils.tag ("I am a custom tag"). D ("I'm printing content");//Other usageLOGUTILS.V ("12345"); LOGUTILS.I ("12345"); LOGUTILS.W ("12345"); LOGUTILS.E ("12345"); LOGUTILS.WTF ("12345");
Reference:
Https://github.com/pengwei1024/LogUtils
Android Log logging framework