Skip to content

Commit

Permalink
Release 1.5.1
Browse files Browse the repository at this point in the history
- add asynchronous implementation of handle and writer
- add parameters for %trait placeholder
- add %color placeholder
- add reusing handles from previous config file read
- add possibility to backup and restore NDC and MDC values
- add out-buffer parameter to std and file handle in configuration file
- improve internal exceptions behaviour
  • Loading branch information
atroxaper committed Apr 24, 2019
2 parents 7e036cf + 30b9488 commit a4f6158
Show file tree
Hide file tree
Showing 39 changed files with 1,152 additions and 370 deletions.
20 changes: 20 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Version history:

1.5.1 2019-04-24 'the new small features'
- add asynchronous implementation of handle and writer
- add parameters for %trait placeholder
- add %color placeholder
- add reusing handles from previous config file read
- add possibility to backup and restore NDC and MDC values
- add out-buffer parameter to std and file handle in configuration file
- improve internal exceptions behaviour

1.4.2 2019-04-10 'better config file and zero length'
- add length=0 support in %level placeholder
- add support of using 'custom' arguments in custom's args in configuration file

1.4.1 2019-04-08 'callframe in writer pattern'
- add callframe support in writer pattern

1.3.1 2019-04-07 'The first public release'
- Production ready log library
4 changes: 2 additions & 2 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
],
"description": "Full customisable logging library inspired by idea of separate logging and its configuration.",
"resources": [],
"version": "1.4.2",
"version": "1.5.1",
"tags": [
"LOG",
"LOGGING",
"LOGGER"
],
"license": "Artistic-2.0",
"source-url": "https://github.com/atroxaper/p6-LogP6",
"source-url": "git://github.com/atroxaper/p6-LogP6.git",
"provides": {
"LogP6::Wrapper::SyncAbstract": "lib/LogP6/Wrapper/SyncAbstract.pm6",
"LogP6::LoggerPure": "lib/LogP6/LoggerPure.pm6",
Expand Down
63 changes: 52 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ even in your own libraries.
- [WriterConf](#writerconf)
- [Standard WriterConf](#standard-writerconf)
- [Pattern](#pattern)
- [Async writing](#async-writing)
- [Writer factory subroutines](#writer-factory-subroutines)
- [Writer configuration file](#writer-configuration-file)
- [Filter configuration](#filter-configuration)
Expand Down Expand Up @@ -210,8 +211,11 @@ current date-time and so from the context.
Logger has the following methods:

- `trait()` - returns logger trait;
- `ndc-push($obj)`, `ndc-pop()`, `ndc-clean()` - work with NDC;
- `mdc-put($key, $obj)`, `mdc-remove($key)`, `mdc-clean()` - work with MDC;
- `ndc-push($obj)`, `ndc-pop()`, `ndc-clean()` - work with `NDC`;
- `mdc-put($key, $obj)`, `mdc-remove($key)`, `mdc-clean()` - work with `MDC`;
- `dc-copy()`, `dc-restore($dc-copy)` - make copy of `NDC` and `MDC` and restore
them from copy. The methods are useful when you want to share NDC and MDC values
across multiple threads.
- `trace(*@args, :$x)`, `debug(*@args, :$x)`, `info(*@args, :$x)`,
`warn(*@args, :$x)`, `error(*@args, :$x)` - logging the arguments with specified
importance log level. `:$x` is an optional exception argument. `@args` - data
Expand Down Expand Up @@ -364,7 +368,19 @@ placeholder name.

Pattern can has the following placeholders:

- `%trait` - for name of logger trait;
- `%trait`, `%trait{short=[package-delimeter]number}`, `%trait{sprintf=pattern}` -
for name of logger trait. Additionally you can specify one of two options of
trait representation. `sprintf` option is useful for traits like `database`,
`audit` or so, when you want to represent all traits with the same length. For
example, `[%trait{sprintf=%s7}]` can be converted into `[ audit]`. `short`
option is useful for traits like `Module::Packge1::Package2::Class`. You can
specify package delimiter (instead of `::`) and how many packages will be
displayed. For example, `%trait{short=[.]1` can be converted into
`Class`, `%trait{short=[.]-1` - into `Packge1.Package2.Class` and
`%trait{short=[.]2.4` - into `Modu.Pack.Package2.Class`. If `number` is a
positive integer then only `number` right elements will be displayed. If
`number` is a negative integer then `|number|` left elements will be deleted. If
`number` is real then left elements will be cut to fractional symbols;
- `%tid` - for current `Thread` id;
- `%tname` - for current `Thread` name;
- `%msg` - for log message;
Expand All @@ -378,10 +394,21 @@ name, `$trace` - optional exception stacktrace. For example,
- `%level{WARN=W DEBUG=D ERROR=E TRACE=T INFO=I length=2}` - log importance
level. By default logger will use level name in upper case but you can
specify synonyms for all or part of them in curly brackets in format
`<LEVEL_NAME>=<sysnonym>`. Also you can specify a fixed length of log level
name. Default length is 0 - write level as is. For example
`<LEVEL_NAME>=<sysnonym>`. You can specify a fixed length of log level name.
Default length is 0 - write level as is. For example
`'[%level{WARN=hmm ERROR=alarm length=5}]'` can be converted into
`'[hmm ]'`, `'[alarm]'`, `'[INFO ]'`, `'[DEBUG]'`;
- `%color{TRACE=yellow DEBUG=green INFO=blue WARN=magenta ERROR=red}` - colorize
log string after that placeholder. You can specify color for any log level.
Level you not specified color will be use its default color (as in example
above). For example, `%color{ERROR=green}` means
`%color{TRACE=yellow DEBUG=green INFO=blue WARN=magenta ERROR=green}`. You can
use `yellow`, `green`, `blue`, `magenta`, `green` color names or color code
(more [information](https://misc.flogisoft.com/bash/tip_colors_and_formatting).
For example `%color{TRACE=35 DEBUG=30;48;5;82 INFO=green}`. You can use `%color`
placeholder several times;
- `%color{reset}` or `%creset` - reset log string colorizing after that
placeholder;
- `%date{$yyyy-$yy-$MM-$MMM-$dd $hh:$mm:$ss:$mss $z}` - current date and time.
String in curly brackets is used as
subpattern.
Expand All @@ -398,9 +425,25 @@ at the same log call line;
`callframe().code.name` in log call block;

Note that using `%framefile`, `%frameline` or `%framename` in the pattern will
slow your program because it requires several `callframe` calls on each
slow your logging because it requires several `callframe()` calls on each
resultative log call;

### Async writing

`LogP6` provides writer and handle implementation for asynchronous writing.

You can use `LogP6::Handle::Async.new(IO::Handle :$delegate!, Scheduler :$scheduler = $*SCHEDULER)`
as handle which will schedule `WRITE` method call of `delegate` handle.

If is it not enough to wrap a handle then you can wrap whole writer. Use
`LogP6::WriterConf::Async.new(LogP6::WriterConf :$delegate!, Scheduler :$scheduler = $*SCHEDULER), :$name, Bool :$need-callframe)`
as writer configuration of another configuration. Final writer will schedule
`write` method call of `delegate` created writer with copy of current
`logger context`. If you miss a `:name` parameter then `delegate`'s name will
be used. Pass boolean parameter `need-callframe` if you plan to use callframe
information in wrapped writer. Note that using callframe will slow your logging
because it requires several `callframe()` calls on each resultative log call.

### Writer factory subroutines

`LogP6` module has the following subs for manage writers configurations:
Expand Down Expand Up @@ -430,8 +473,8 @@ array. Only `std` (for standard configuration) and `custom` types are supported.
In case of standard configuration all field are optional excepts `name`. Handle
can be:

- `file` type for output into file. You can specify `path` and `append`
arguments;
- `file` type for output into file. You can specify `path`,`append` (`True`
by default) and `out-buffer` arguments;
- `std` type for output into `$*OUT` or `$*ERR`. You can specify `path` as `out`
or `err`.
- `custom` type.
Expand Down Expand Up @@ -1030,17 +1073,15 @@ subroutines logic then make a special sub for retrieve logger like

# ROADMAP

- Make IO::Handle for write log in databases;
- Make IO::Handle rollover support - change log file after some period of time
or after file size limit are reached;
- Add Writer for asynchronous writing;
- Add a `Cro::Transform` for using `LogP6` in `cro` applications.

# AUTHOR

Mikhail Khorkov <atroxaper@cpan.org>

Source can be located at: https://github.com/atroxaper/p6-LogP6. Comments and Pull Requests
Source can be located at: [github](https://github.com/atroxaper/p6-LogP6). Comments and Pull Requests
are welcome.

# COPYRIGHT AND LICENSE
Expand Down
8 changes: 4 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ High priority:
1. ~~add `length=0` in `%level` for exact length. make it default~~

Medium priority:
1. use a better exceptions instead of 'die'
1. add params for %trait in pattern (short, long variant)
1. try make entities be really immutable (filters, writes, loggers)
1. ~~use a better exceptions instead of 'die'~~
1. ~~add params for %trait in pattern (short, long variant)~~
1. ~~add database writer~~

Low priority:

1. add 'turn off/on cliche' factory method
1. add trace-some methods in logger (like 'returns value', 'enter method with')
1. add backup/restore ndc and mdc
1. try make entities be really immutable (filters, writes, loggers)
1. ~~add backup/restore ndc and mdc~~

Archive:

Expand Down
Loading

0 comments on commit a4f6158

Please sign in to comment.