Lightweight Android and Java logging library—xLog

Lightweight Android and Java logging library—xLog

2022-08-30 0 1,535
Resource Number 36581 Last Updated 2025-02-24
¥ 0 USD Upgrade VIP
Download Notice Demo
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

Product Details 商品属性

  • Language: Java
  • Database:
  • License: License-Free
  • Source Code: Fully Open Source
  • Specification: Full Website Source
  • Delivery: Automatic (instant download after payment)

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

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:

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.

TopTinker E-Commerce Lightweight Android and Java logging library—xLog https://toptinker.com/36581.html

商家类型:个人(声明)

Share free open-source source code

Q&A
  • 1. Automatic: After making an online payment, click the (Download) link to download the source code; 2. Manual: Contact the seller or the official to check if the template is consistent. Then, place an order and make payment online. The seller ships the goods, and both parties inspect and confirm that there are no issues. TopTinker will then settle the payment for the seller. Note: Please ensure to place your order and make payment through TopTinker. If you do not place your order and make payment through TopTinker, and the seller sends fake source code or encounters any issues, TopTinker will not assist in resolving them, nor can we guarantee your funds!
View details
  • 1. Default transaction cycle for source code: The seller manually ships the goods within 1-3 days. The amount paid by the user will be held in escrow by TopTinker until 7 days after the transaction is completed and both parties confirm that there are no issues. TopTinker will then settle with the seller. In case of any disputes, TopTinker will have staff to assist in handling until the dispute is resolved or a refund is made! If the buyer places an order and makes payment not through TopTinker, any issues and disputes have nothing to do with TopTinker, and TopTinker will not be responsible for any liabilities!
View details
  • 1. TopTinker will permanently archive the transaction process between both parties and snapshots of the traded goods to ensure the authenticity, validity, and security of the transaction! 2. TopTinker cannot guarantee services such as "permanent package updates" and "permanent technical support" after the merchant's commitment. Buyers are advised to identify these services on their own. If necessary, they can contact TopTinker for assistance; 3. When both website demonstration and image demonstration exist in the source code, and the text descriptions of the website and images are inconsistent, the text description of the image shall prevail as the basis for dispute resolution (excluding special statements or agreements); 4. If there is no statement such as "no legal basis for refund" or similar content, any indication on the product that "once sold, no refunds will be supported" or other similar declarations shall be deemed invalid; 5. Before the buyer places an order and makes payment, the transaction details agreed upon by both parties via WhatsApp or email can also serve as the basis for dispute resolution (in case of any inconsistency between the agreement and the description of the conflict, the agreement shall prevail); 6. Since chat records and email records can serve as the basis for dispute resolution, both parties should only communicate with each other through the contact information left on the system when contacting each other, in order to prevent the other party from denying their own commitments. 7. Although the probability of disputes is low, it is essential to retain important information such as chat records, text messages, and email records, in case a dispute arises, so that TopTinker can intervene quickly.
View details
  • 1. As a third-party intermediary platform, TopTinker solely protects transaction security and the rights and interests of both buyers and sellers based on the transaction contract (product description, agreed content before the transaction); 2. For online trading projects not on the TopTinker platform, any consequences are unrelated to this platform; regardless of the reason why the seller requests an offline transaction, please contact the administrator to report.
View details

Related Source code

TopTinker Customer Service

24-hour online professional services