Helper class for log4ahk (Implementing layout)
Creates a pattern layout according to log4j-layout and a couple of log4ahk-specific extensions.
The following placeholders can be used within the layout string:
| %d | Current date in yyyy/MM/dd hh:mm:ss format |
| %F | File where the logging event occurred |
| %i | Indentationstring according calldepth of calling method |
| %H | Hostname |
| %l | Fully qualified name of the calling method followed by the callers source the file name and line number between parentheses. |
| %L | Line number within the file where the log statement was issued |
| %m | The message to be logged |
| %M | Method or function where the logging request was issued |
| %P | pid of the current process |
| %r | Number of milliseconds elapsed from logging start to current logging event |
| %R | Number of milliseconds elapsed from last logging event to current logging event |
| %s | Name of the current script |
| %S | Fullpath of the current script |
| %T | Stack trace of the function called |
| %V | Log level |
Most placeholders can be extended with formatting instructions, just similar to format:
| %20M | Reserve 20 chars for the method, right-justify and fill with blanks if it is shorter |
| %-20M | Same as %20c, but left-justify and fill the right side with blanks |
| %09r | Zero-pad the number of milliseconds to 9 digits |
| %.8M | Specify the maximum field with and have the formatter cut off the rest of the value |
Fine tuning with curlies:
Some placeholders have special functions defined if you add curlies with content after them:
| %T | complete Stack Trace of the function called |
| %T{3:} | Stack Trace starting at depth 3, ending at maximum depth (maximum depth is the function called) |
| %T{3:4} | Stack Trace starting at depth 3, ending at depth 4 |
| %T{-3:} | Stack Trace starting 3 from maximum depth, ending at maximum depth |
| %T{:-4} | Stack Trace starting at mimumum depth, ending 4 from maximum depth |
| %T{:} | complete Stack Trace (equivalent to %T) |
To set a layout use
logger.layout.required := "[%-5.5V] {%-15.15M}{%H} %m"| _expand( |
| ) |
Expands the placeholders with the values from the given array
| ph | associative Array containing mapping placeholder to its replacement |
Splits the layout into its tokens
The layout string is separated into its separate layout elements (tokens). For example "%8V %M" consists of two tokens: "%8V" and "%M". Each token starts with "%" and ends at the next space.
The tokens are split up into its separate parts: each token consists of three parts:
| Quantifier | All placeholders can be extended with formatting instructions, just similar to format |
| Placeholder | Placeholders are replaced with the corresponding information |
| Curlies | Curlies allow further manipulation of the placeholders |
As a result of the function, the property tokens is filled with objects, which contain the complete token as well as its single parts.
For more information, which values are allowed for quantifiers, placeholders and curlies have a look at documentation of class layout
Get/set the required layout. This layout will be used to format the logged message.
Get the tokens of the current layout
For more information see _split