Lightweight Android and Java logging library—xLog

Lightweight Android and Java logging library—xLog

2022-08-30 0 790
Resource Number 36581 Last Updated 2025-02-24
¥ 0USD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

Log directory full path

xLog is a lightweight, beautiful, and extensible logging library for Android and Java that can simultaneously print logs in files such as Logcat, Console, and files.

Peculiarity:

Global configuration (TAG, various formatters…) or a single-log based configuration
Support for printing arbitrary objects as well as customizable object formatters
Support for printing unlimited logs (no 4K character limit)
XML and JSON formatted output

Lightweight Android and Java logging library—xLog插图

How to Use:

1. Add dependencies

implementation ‘com.elvishew:xlog:1.10.1’

2. Initialize the configuration

When initialized, it can be done in the simplest way

XLog.init(LogLevel.ALL);

It is also possible to use advanced methods

LogConfiguration config = new LogConfiguration.Builder().logLevel(BuildConfig.DEBUG ? LogLevel.ALL // Specify the log level, logs below this level will not be printed, default is LogLevel.ALL: LogLevel.NONE).tag(“MY_TAG”) // Specify TAG, default is “X-LOG”.enableThreadInfo() // Allow thread information to be printed, disable .enableStackTrace(2) by default, // Allow print depth to be 2 .enableBorder() is allowed to be printed by default, .jsonFormatter(new MyJsonFormatter()) is disabled by default, and the default is DefaultJsonFormatter.xmlFormatter(new MyXmlFormatter()) // Specify the XML formatter by default DefaultXmlFormatter.throwableFormatter(new MyThrowableFormatter()) // Specify a throwable exception formatter, default is DefaultThrowableFormatter.threadFormatter(new MyThreadFormatter()) // Specify the thread information formatter, default DefaultThreadFormatter.stackTraceFormatter(new MyStackTraceFormatter()) // Specifies the call stack information formatter and defaults to DefaultStackTraceFormatter.borderFormatter(new MyBoardFormatter()) // Specifies the border formatter and defaults to DefaultBorderFormatter.addObjectFormatter(AnyClass.class, // Add an object formatter for the specified typenew AnyClassObjectFormatter()) // Object.toString().addInterceptor(new) is used by default BlacklistTagsFilterInterceptor( // Add a blacklist TAG filter “blacklist1”, “blacklist2”, “blacklist3”)).addInterceptor(new MyInterceptor()) // Add a log interceptor.build(); Printer androidPrinter = new AndroidPrinter(true); Printer that prints logs via android.util.Log consolePrinter = new ConsolePrinter(); Print the log to the printer in the console via System.out Printer filePrinter = new FilePrinter // Print the log to the printer of the file. Builder(“<Log directory full path>”) // Specify the path where the log file is saved.fileNameGenerator(new DateFileNameGenerator()) // Specify the log file name generator, defaults to ChangelessFileNameGenerator(“log”).backupStrategy(new NeverBackupStrategy()) // Specify the log file backup policy, default is FileSizeBackupStrategy(1024 * 1024).cleanStrategy(new FileLastModifiedCleanStrategy(MAX_TIME)) // Specify the log file cleanup policy, default is NeverCleanStrategy(). flattener(new MyFlattener()) // Specify the log tiler, default is DefaultFlattener.writer(new MyWriter()) // Specify the log writer, default is SimpleWriter.build(); XLog.init( // Initialize XLogconfig, // Specify the log configuration, if not, use new LogConfiguration.Builder().build()androidPrinter by default, // Add as many printers as you want. If no printer is added, AndroidPrinter(Android)/ConsolePrinter(java)consolePrinter,filePrinter will be used by default);

3. Print the log

Print a simple message
XLog.d(“Hello World”);
Prints a throwable message, usually when an exception is thrown
XLog.e(message, throwable);
String formatting is supported
XLog.d(“Hello%s, I’m %d years old”, “Elvis”, 20);
Unformatted JSON and XML strings are automatically formatted
XLog.json(JSON_CONTENT); XLog.xml(XML_CONTENT);
All Collection and Map types of data are supported
XLog.d(array); XLog.d(list); XLog.d(map);
Intents and bundle objects can be printed directly
XLog.d(intent); XLog.d(bundle);
Save the log to a file

To save logs to a file, you need to create a FilePrinter

Printer filePrinter = new FilePrinter // Print the log to the printer of the file. Builder(“< full path to the log directory>”) // Specify the path where the log file is saved.fileNameGenerator(new DateFileNameGenerator()) // Specify the log file name generator, defaults to ChangelessFileNameGenerator(“log”).backupStrategy(new NeverBackupStrategy()) // Specify the log file backup policy, default is FileSizeBackupStrategy(1024 * 1024).cleanStrategy(new FileLastModifiedCleanStrategy(MAX_TIME)) // Specify the log file cleanup policy, default is NeverCleanStrategy(). flattener(new MyFlattener()) // Specifies the log tiler, defaults to DefaultFlattener.build();

And add it on initialization

XLog.init(config, filePrinter);

Architecture:

Lightweight Android and Java logging library—xLog插图1

In addition, xLog also supports functions such as saving logs printed by third-party libraries to files, customizing log file names, intercepting and overthinking logs, customizing log formats, and formatting any type of object.

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free source code Lightweight Android and Java logging library—xLog https://ictcoder.com/kyym/lightweight-android-and-java-logging-library-xlog.html

Share free open-source source code

Q&A
  • 1, automatic: after taking the photo, click the (download) link to download; 2. Manual: After taking the photo, contact the seller to issue it or contact the official to find the developer to ship.
View details
  • 1, the default transaction cycle of the source code: manual delivery of goods for 1-3 days, and the user payment amount will enter the platform guarantee until the completion of the transaction or 3-7 days can be issued, in case of disputes indefinitely extend the collection amount until the dispute is resolved or refunded!
View details
  • 1. Heptalon will permanently archive the process of trading between the two parties and the snapshots of the traded goods to ensure that the transaction is true, effective and safe! 2, Seven PAWS can not guarantee such as "permanent package update", "permanent technical support" and other similar transactions after the merchant commitment, please identify the buyer; 3, in the source code at the same time there is a website demonstration and picture demonstration, and the site is inconsistent with the diagram, the default according to the diagram as the dispute evaluation basis (except for special statements or agreement); 4, in the absence of "no legitimate basis for refund", the commodity written "once sold, no support for refund" and other similar statements, shall be deemed invalid; 5, before the shooting, the transaction content agreed by the two parties on QQ can also be the basis for dispute judgment (agreement and description of the conflict, the agreement shall prevail); 6, because the chat record can be used as the basis for dispute judgment, so when the two sides contact, only communicate with the other party on the QQ and mobile phone number left on the systemhere, in case the other party does not recognize self-commitment. 7, although the probability of disputes is very small, but be sure to retain such important information as chat records, mobile phone messages, etc., in case of disputes, it is convenient for seven PAWS to intervene in rapid processing.
View details
  • 1. As a third-party intermediary platform, Qichou protects the security of the transaction and the rights and interests of both buyers and sellers according to the transaction contract (commodity description, content agreed before the transaction); 2, non-platform online trading projects, any consequences have nothing to do with mutual site; No matter the seller for any reason to require offline transactions, please contact the management report.
View details

Related Article

make a comment
No comments available at the moment
Official customer service team

To solve your worries - 24 hours online professional service