des.log

Simple example

1 import des.log;
2 
3 void func()
4 {
5    logger.fatal( "fatal" );
6    logger.error( "error" );
7    logger.warn( "warn" );
8    logger.info( "info" );
9    logger.Debug( "debug" );
10    logger.trace( "trace" );
11 }
12 
13 void main()
14 {
15    logger.fatal( "fatal message" );
16    logger.error( "error message" );
17    logger.warn( "warn message" );
18    logger.info( "info message" );
19    logger.Debug( "debug message" );
20    logger.trace( "trace message" );
21 
22    func();
23 }

can have output like this:

1 ./app
2 [000000.000122258][FATAL][app.main]: fatal message
3 [000000.000214030][ERROR][app.main]: error message
4 [000000.000261067][FATAL][app.func]: fatal
5 [000000.000285349][ERROR][app.func]: error
More...

Modules

base
module des.log.base
consolecolor
module des.log.consolecolor
logcls
module des.log.logcls
output
module des.log.output
rule
module des.log.rule

Members

Classes

LogGetOptException
class LogGetOptException

Mixin templates

ClassLogger
mixin template ClassLogger()

for simple adding logging to class

Variables

logger
Logger logger;

Detailed Description

Flag --log used for setting max level of logging output. Default level is error. If log function called with greater level it's skipped. Level has attitudes off < fatal < error < warn < info < debug < trace.

1 $ ./app --log app.func:debug
2 [log use min]: false
3 [log rules]:
4 ERROR
5 app : ERROR
6   func : DEBUG
7 [000000.000162889][FATAL][app.main]: fatal message
8 [000000.000207483][ERROR][app.main]: error message
9 [000000.000242506][FATAL][app.func]: fatal
10 [000000.000261887][ERROR][app.func]: error
11 [000000.000285754][ WARN][app.func]: warn
12 [000000.000304789][ INFO][app.func]: info
13 [000000.000323652][DEBUG][app.func]: debug
1 $ ./app --log info --log app.func:trace
2 [log use min]: false
3 [log rules]:
4 INFO
5 app : INFO
6   func : TRACE
7 [000000.000245525][FATAL][app.main]: fatal message
8 [000000.000308796][ERROR][app.main]: error message
9 [000000.000338714][ WARN][app.main]: warn message
10 [000000.000365555][ INFO][app.main]: info message
11 [000000.000406501][FATAL][app.func]: fatal
12 [000000.000434482][ERROR][app.func]: error
13 [000000.000461296][ WARN][app.func]: warn
14 [000000.000487242][ INFO][app.func]: info
15 [000000.000512884][DEBUG][app.func]: debug
16 [000000.000538288][TRACE][app.func]: trace

Flag --log can be used with module name ./program --log draw.point:debug. It will set debug level for module draw.point and default to other.

Flag --log-use-min is boolean flag. It forces logging system to skip output from all child modules if their level greater than parent. Default is false.

./program --log trace --log draw:info --log draw.point:trace --log-use-min=true skips all output from logger.trace and logger.Debug from whole draw.point, and doesn't skip from other modules.

./program --log trace --log draw:info --log draw.point:trace allow log_trace and log_debug only from draw.point from module draw. For other modules in draw sets level info

You can compile program with version=des_log_onlyerror for skip all trace, debug, info and warn outputs in logger. It can improve program release speed.

Class logging

Module provides some functional for useful logging classes.

Examples

1 module x;
2 import des.log;
3 class A
4 {
5    mixin ClassLogger;
6    void func() { logger.trace( "hello" ); }
7 }
module y;
import x;
class B : A { }
auto b = new B;
b.func();

outputs:

[000000.148628473][TRACE][x.A.func]: hello

If create instance logger

class B : A { this(){ logger = new InstanceLogger(this); } }

outputs:

[000000.148628473][TRACE][y.B.func]: hello

If create instance logger with instance name

class B : A { this(){ logger = new InstanceLogger(this,"my object"); } }

outputs:

[000000.148628473][TRACE][y.B.[my object].func]: hello

If create instance full logger

class B : A { this(){ logger = new InstanceFullLogger(this); } }

outputs:

[000000.148628473][TRACE][y.B.[x.A.func]]: hello

If create instance full logger with name

class B : A { this(){ logger = new InstanceFullLogger(this,"name"); } }

outputs:

[000000.148628473][TRACE][y.B.[name].[x.A.func]]: hello

Flag --log can get full emitter string y.B.[name].[x.A.func].

./program --log "y.B.[one]:trace" --log "y.B.[two]:debug"

Meta