1 // Written in the D programming language.
2 /**
3 Source: $(PHOBOSSRC std/experimental/logger/nulllogger.d)
4 */
5 module std.experimental.logger.nulllogger;
6 
7 import std.experimental.logger.core;
8 
9 /** The `NullLogger` will not process any log messages.
10 
11 In case of a log message with `LogLevel.fatal` nothing will happen.
12 */
13 class NullLogger : Logger
14 {
15     /** The default constructor for the `NullLogger`.
16 
17     Independent of the parameter this Logger will never log a message.
18 
19     Params:
20       lv = The `LogLevel` for the `NullLogger`. By default the `LogLevel`
21       for `NullLogger` is `LogLevel.all`.
22     */
23     this(const LogLevel lv = LogLevel.all) @safe
24     {
25         super(lv);
26         this.fatalHandler = delegate() {};
27     }
28 
29     override protected void writeLogMsg(ref LogEntry payload) @safe @nogc
30     {
31     }
32 }
33 
34 ///
35 @safe unittest
36 {
37     import std.experimental.logger.core : LogLevel;
38     auto nl1 = new NullLogger(LogLevel.all);
39     nl1.info("You will never read this.");
40     nl1.fatal("You will never read this, either and it will not throw");
41 }
Suggestion Box / Bug Report