KamelosoLogger

Logger class, used to print timestamped and coloured logging messages.

It is thread-local so instantiate more if you're threading.

Constructors

this
this(Flag!"monochrome" monochrome, Flag!"brightTerminal" brightTerminal, Flag!"headless" headless, Flag!"flush" flush)

Creates a new KamelosoLogger with the passed settings.

this
this(CoreSettings settings)

Creates a new KamelosoLogger with settings divined from the passed CoreSettings struct.

Members

Aliases

log
alias log = all

Synonymous alias to KamelosoLogger.all, as a workaround for LogLevel.all not being named LogLevel.log.

logf
alias logf = allf

Synonymous alias to KamelosoLogger.allf, as a workaround for LogLevel.all not being named LogLevel.log.

logtint
alias logtint = alltint

Synonymous alias to alltint, as a workaround for LogLevel.all not being named LogLevel.log.

logtint
alias logtint = alltint

Synonymous alias to alltint, as a workaround for LogLevel.all not being named LogLevel.log.

Static functions

offtint
auto offtint()

Dummy function returning an empty string, since there can be no tints on non-version Colours builds.

tint
uint tint(LogLevel level, Flag!"brightTerminal" bright)

Returns the corresponding TerminalForeground for the LogLevel, taking into account whether the terminal is said to be bright or not.

Examples

1 struct S1
2 {
3     void toString(Sink)(auto ref Sink sink) const
4     {
5         sink.put("sink toString");
6     }
7 }
8 
9 struct S2
10 {
11     void toString(scope void delegate(const(char)[]) dg) const
12     {
13         dg("delegate toString");
14     }
15 
16     @disable this(this);
17 }
18 
19 struct S3
20 {
21     string s = "no toString";
22 }
23 
24 struct S4
25 {
26     string toString = "toString literal";
27 }
28 
29 struct S5
30 {
31     string toString()() const
32     {
33         return "template toString";
34     }
35 }
36 
37 class C
38 {
39     override string toString() const
40     {
41         return "plain toString";
42     }
43 }
44 
45 auto log_ = new KamelosoLogger(Yes.monochrome, No.brightTerminal, No.headless, Yes.flush);
46 
47 log_.logf!"log: %s"("log");
48 log_.infof!"log: %s"("info");
49 log_.warningf!"log: %s"("warning");
50 log_.errorf!"log: %s"("error");
51 log_.criticalf!"log: %s"("critical");
52 // log_.fatalf!"log: %s"("FATAL");
53 log_.tracef!"log: %s"("trace");
54 log_.offf!"log: %s"("off");
55 
56 version(Colours)
57 {
58     log_ = new KamelosoLogger(No.monochrome, Yes.brightTerminal, No.headless, Yes.flush);
59 
60     log_.log("log: log");
61     log_.info("log: info");
62     log_.warning("log: warning");
63     log_.error("log: error");
64     log_.critical("log: critical");
65     // log_.fatal("log: FATAL");
66     log_.trace("log: trace");
67     log_.off("log: off");
68 
69     log_ = new KamelosoLogger(No.monochrome, No.brightTerminal, No.headless, Yes.flush);
70 
71     log_.log("log: log");
72     log_.info("log: info");
73     log_.warning("log: warning");
74     log_.error("log: error");
75     // log_.fatal("log: FATAL");
76     log_.trace("log: trace");
77     log_.off("log: off");
78 }
79 
80 log_.log("log <i>info</> log <w>warning</> log <e>error</> log <t>trace</> log <o>off</> log");
81 
82 S1 s1;
83 S2 s2;
84 S3 s3;
85 S4 s4;
86 S5 s5;
87 C c = new C;
88 
89 log_.trace();
90 
91 log_.log(s1);
92 log_.info(s2);
93 log_.warning(s3);
94 log_.critical(s4);
95 log_.error(s5);
96 log_.trace(c);
97 
98 log_.headless = true;
99 log_.error("THIS SHOULD NEVER BE SEEN");

Meta