The basic implementation of
Handler interface.
This log handler is configured with a logging level, a tag and
a message patterns.
The logging level parameter is the minimal level of log messages printed
by this handler instance. The logging level can be
null which
means no messages should be printed using this logger.
Attention: Android may set its own requirement for logging level
using
Log#isLoggable(String, int) method. This logger doesn't take
it into account in
isEnabled(Logger.Level) method.
The patterns are format strings written according to a special rules described
below. Log messages will be formatted and printed as it is specified in
the tag and the message pattern. The tag pattern configures log tag used
to print messages. The message pattern configures a head of the message but
not whole message printed to log.
| The tag pattern |
TAG |
| The message pattern |
%d{yyyy-MM-dd}: |
| Resulting tag |
TAG |
| Resulting message |
2013-07-12: <incoming message> |
The tag and the message patterns are wrote according to similar rules.
So we will show only one pattern in further examples.
The patterns is strings that contains a set of placeholders and other
special marks. Each special mark should start with '%' sign. To escape
this sign you can double it.
The list of special marks and placeholders:
Conversion marks
| Mark | Effect |
| %% |
Escapes special sign. Prints just one '%' instead. |
| %n |
Prints a new line character '\n'. |
| %d{date format} %date{date format} |
Prints date/time of a message. Date format
should be supported by SimpleDateFormat.
Default date format is "yyyy-MM-dd HH:mm:ss.SSS". |
| %p %level |
Prints logging level of a message. |
| %c{count.length} %logger{count.length} |
Prints a name of the logger. The algorithm will shorten some part of
full logger name to the specified length. You can find examples below.
| Conversion specifier |
Logger name |
Result |
| %logger |
com.example.android.MainActivity |
com.example.android.MainActivity |
| %logger{0} |
com.example.android.MainActivity |
com.example.android.MainActivity |
| %logger{3} |
com.example.android.MainActivity |
com.example.android |
| %logger{-1} |
com.example.android.MainActivity |
example.android.MainActivity |
| %logger{.0} |
com.example.android.MainActivity |
com.example.android.MainActivity |
%logger{.30} |
com.example.android.MainActivity |
com.example.android.* |
| %logger{.15} |
com.example.android.MainActivity |
com.example.* |
| %logger{.-25} |
com.example.android.MainActivity |
*.android.MainActivity |
| %logger{3.-18} |
com.example.android.MainActivity |
*.example.android |
| %logger{-3.-10} |
com.example.android.MainActivity$SubClass |
MainActivity$SubClass |
|
| %C{count.length} %caller{count.length} |
Prints information about a caller class which causes the logging event.
Additional parameters 'count' and 'length' means the same as
the parameters of %logger. Examples:
| Conversion specifier |
Caller |
Result |
| %caller |
Class com.example.android.MainActivity at line 154 |
com.example.android.MainActivity:154 |
| %caller{-3.-15} |
Class com.example.android.MainActivity at line 154 |
MainActivity:154 |
|
| %s{count.length} %source{count.length} |
Prints source of class which causes the logging event. Examples:
| Conversion specifier |
Caller |
Result |
| %source or %s |
Class com.example.android.MainActivity at line 154 |
(MainActivity.java:154) |
| %source or %s |
Native |
(native) |
| %source or %s |
Unknown |
(unknown) |
|
| %t{count.length} %thread{count.length} |
Prints a name of the thread which causes the logging event. |
| %(...) |
Special mark used to grouping parts of message. Format modifiers
(if specified) are applied on whole group. Examples:
| Example |
Result |
| [%50(%d %caller{-3.-15})] |
[ 2013-07-12 19:45:26.315 MainActivity:154] |
| [%-50(%d %caller{-3.-15})] |
[2013-07-12 19:45:26.315 MainActivity:154 ] |
|
After special sign '%' user can add format modifiers. The modifiers
is similar to standard modifiers of
Formatter conversions.
| Example |
Result |
| %6(text) | ' text' |
| %-6(text) | 'text ' |
| %.3(text) | 'tex' |
| %.-3(text) | 'ext' |