Code transformation tool and viewer for ProtoLog.
ProtoLogTool incorporates three different modes of operation:
Command: process <protolog class path> <protolog implementation class path> <protolog groups class path> <config.jar> [<input.java>] <output.srcjar>
In this mode ProtoLogTool transforms every ProtoLog logging call in form of:
ProtoLog.x(ProtoLogGroup.GROUP_NAME, "Format string %d %s", value1, value2);
into:
if (GROUP_NAME.isLogToAny()) { ProtoLogImpl.x(ProtoLogGroup.GROUP_NAME, 123456, "Format string %d %s or null", value1, value2); }
where ProtoLog
, ProtoLogImpl
and ProtoLogGroup
are the classes provided as arguments (can be imported, static imported or full path, wildcard imports are not allowed) and, x
is the logging method. The transformation is done on the source level. A hash is generated from the format string and log level and inserted after the ProtoLogGroup
argument. The format string is replaced by null
if ProtoLogGroup.GROUP_NAME.isLogToLogcat()
returns false. If ProtoLogGroup.GROUP_NAME.isEnabled()
returns false the log statement is removed entirely from the resultant code.
Input is provided as a list of java source file names. Transformed source is saved to a single source jar file. The ProtoLogGroup class with all dependencies should be provided as a compiled jar file (config.jar).
Command: viewerconf <protolog class path> <protolog implementation class path <protolog groups class path> <config.jar> [<input.java>] <output.json>
This command is similar in it's syntax to the previous one, only instead of creating a processed source jar it writes a viewer configuration file with following schema:
{ "version": "1.0.0", "messages": { "123456": { "message": "Format string %d %s", "level": "ERROR", "group": "GROUP_NAME" }, }, "groups": { "GROUP_NAME": { "tag": "TestLog" } } }
Command: read <viewer.json> <wm_log.pb>
Reads the binary ProtoLog log file and outputs a human-readable LogCat-like text log.
ProtoLog is a logging system created for the WindowManager project. It allows both binary and text logging and is tunable in runtime. It consists of 3 different submodules:
ProtoLog is designed to reduce both application size (and by that memory usage) and amount of resources needed for logging. This is achieved by replacing log message strings with their hashes and only loading to memory/writing full log messages when necessary.
For text-based logs Android LogCat is used as a backend. Message strings are loaded from a viewer config located on the device when needed.
Binary logs are saved as Protocol Buffers file. They can be read using the ProtoLog tool or specialised viewer like Winscope.
To add a new ProtoLogGroup simple create a new enum ProtoLogGroup member with desired parameters.
To add a new logging statement just add a new call to ProtoLog.x where x is a log level.
After doing any changes to logging groups or statements you should run make update-protolog
to update viewer configuration saved in the code repository.
Use the adb shell su root cmd window logging
command. To get help just type adb shell su root cmd window logging help
.