-
Notifications
You must be signed in to change notification settings - Fork 2
/
logger.d
802 lines (634 loc) · 24.2 KB
/
logger.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
module sidero.base.logger;
import sidero.base.text;
import sidero.base.attributes;
import sidero.base.allocators;
import sidero.base.errors;
import sidero.base.console;
import sidero.base.path.file;
export @safe nothrow @nogc:
///
enum LoggingTargets : uint {
/// Default
None = 0,
///
Console = 1,
///
File = 1 << 1,
/// Posix, requires some sort of syslog
Syslog = 1 << 2,
/// Windows events
Windows = 1 << 3,
///
Custom = 1 << 4,
///
All = Console | File | Syslog | Windows | Custom,
}
///
enum LogLevel {
/**
The trace log level, will only output if trace.
Tracing debug events should only be included in library code for the purposes of understanding failures either in production or during debugging.
It may take the place of console writing during the debugging process but it should never reach consumers once debugging in complete.
*/
Trace,
/**
The debug log level, will only output for trace to debug inclusive.
This should be used by library authors to log any action that could fail.
It may contain any information required to identify the actions being performed as well as any reason a code path may be failing.
*/
Debug,
/**
A information log level, will only output for trace to info inclusive.
Use this to inform about commonly desired information.
This includes information such as a system handle has been created with its given value, but only if that system handle is commonly accessed externally.
You should not be using this to output information that will be exclusively be needed during debugging.
*/
Info,
/**
A notice log level, will only output for trace to notice inclusive.
It is the default.
Use this to inform about standard logic within a program.
This is stuff like a socket connection has been made to a given network address.
It should not include the system handle for the socket.
*/
Notice,
/**
The warning log level, will only output for trace to warning inclusive.
Use this to document a potentially indicative behavior to a problem.
What it is indicative of may not be known at this stage.
It is used after the ending of a program to help diagnose a problem that has occured.
*/
Warning,
/**
The error log level, will only output for trace to error inclusive.
This will be printed to standard error not standard output.
For library authors the purpose of this is for recoverable situations but only if the API is be designed for error checking.
It allows documenting the cause of a recoverable situation that ends a given library logic.
*/
Error,
/**
A critical log level, will only output for trace to critical inclusive.
This will be printed to standard error not standard output.
For library authors the purpose of this is for unrecoverable situations and the API is designed for error checking.
It allows for documenting the cause of a unrecoverable situation that ends a given programs logic.
*/
Critical,
/**
Fatal log level, will always be printed.
This will be printed to standard error not standard output.
For use with any erroneous situation that will immediately ends a program life.
Use sparingly.
TODO: this should immediately exit the program
*/
Fatal,
}
///
enum LogRotateFrequency {
///
None,
///
OnStart,
///
Hourly,
///
Daily,
}
///
alias CustomTargetMessage = void delegate(LogLevel level, GDateTime dateTime, String_UTF8 moduleLineUTF8,
String_UTF16 moduleLineUTF16, String_UTF8 tags, String_UTF8 levelText, String_UTF8 composite) @safe nothrow @nogc;
///
alias CustomTargetOnRemove = void delegate() @safe nothrow @nogc;
///
alias LoggerReference = ResultReference!Logger;
///
struct Logger {
private @PrettyPrintIgnore {
import sidero.base.containers.dynamicarray;
import sidero.base.internal.meta;
RCAllocator allocator;
String_UTF8 name_;
SystemLock mutex;
LogLevel logLevel;
uint targets;
String_UTF8 dateTimeFormat;
String_UTF8 tags;
ConsoleTarget consoleTarget;
FileTarget fileTarget;
DynamicArray!CustomTarget customTargets;
static int opApplyImpl(Del)(scope Del del) @trusted {
int result;
auto getLoggers() @trusted nothrow @nogc {
return loggers;
}
static if(__traits(compiles, { LoggerReference lr; del(lr); })) {
result = getLoggers.opApply(del);
} else {
int handle()(ref ResultReference!String_UTF8 k, ref LoggerReference v) {
assert(k);
String_UTF8 tempKey = k;
return del(tempKey, v);
}
result = getLoggers.opApply(&handle!());
}
return result;
}
}
export:
static {
///
mixin OpApplyCombos!("LoggerReference", "String_UTF8", ["@safe", "nothrow", "@nogc"], "opApply", "opApplyImpl", true);
}
@safe nothrow @nogc:
this(return scope ref Logger other) scope {
this.tupleof = other.tupleof;
assert(this.name_.isNull, "Don't copy the Logger around directly, use it only by the LoggerReference");
}
///
bool isNull() scope const {
return name.isNull;
}
///
String_UTF8 name() scope const @trusted {
return (cast(Logger)this).name_;
}
///
void setLevel(LogLevel level) scope {
cast(void)mutex.lock;
logLevel = level;
mutex.unlock;
}
/// See_Also: LoggingTargets
void setTargets(uint targets = LoggingTargets.None) scope {
cast(void)mutex.lock;
this.targets = targets;
mutex.unlock;
}
///
void setTags(scope return String_UTF8 tags) scope {
cast(void)mutex.lock;
this.tags = tags;
mutex.unlock;
}
///
void setTags(scope return String_UTF16 tags) scope {
this.setTags(tags.byUTF8);
}
///
void setTags(scope return String_UTF32 tags) scope {
this.setTags(tags.byUTF8);
}
/// Set console stream back to the default
void setToDefaultConsoleStream() scope {
cast(void)mutex.lock;
foreach(i, ref v; this.consoleTarget.useErrorStream)
v = ConsoleTarget.DefaultErrorStream[i];
mutex.unlock;
}
/// Will console stream be stderr instead of stdout?
void setConsoleStream(bool useError) scope {
cast(void)mutex.lock;
foreach(ref v; this.consoleTarget.useErrorStream)
v = useError;
mutex.unlock;
}
///
void setToDefaultConsoleColors() scope {
cast(void)mutex.lock;
consoleTarget.colors = ConsoleTarget.DefaultConsoleColors;
mutex.unlock;
}
///
void setConsoleColor(LogLevel level, ConsoleColor foreground = ConsoleColor.Unknown, ConsoleColor background = ConsoleColor.Unknown) {
cast(void)mutex.lock;
consoleTarget.colors[level] = [foreground, background];
mutex.unlock;
}
/// Prefix (Separator DateTime)? . Extension
ErrorResult setLogFile(FilePath rootLogDirectory, String_UTF8 filePrefix, String_UTF8 filePrefixSeparator,
String_UTF8 fileExtension, LogRotateFrequency rotateFrequency = LogRotateFrequency.OnStart) {
if(rootLogDirectory.couldPointToEntry) {
if(!rootLogDirectory.asAbsolute())
rootLogDirectory = rootLogDirectory.asAbsolute();
} else
return ErrorResult(MalformedInputException("Expected a log directory path that could be made absolute"));
cast(void)mutex.lock;
fileTarget.rootLogDirectory = rootLogDirectory;
fileTarget.filePrefix = filePrefix;
fileTarget.filePrefixSeparator = filePrefixSeparator;
fileTarget.fileExtension = fileExtension;
fileTarget.logRotateFrequency = rotateFrequency;
mutex.unlock;
return ErrorResult.init;
}
///
void addCustomTarget(CustomTargetMessage messageDel, CustomTargetOnRemove onRemoveDel = null) @trusted {
if(messageDel is null && onRemoveDel is null)
return;
cast(void)mutex.lock;
customTargets ~= CustomTarget();
customTargets.unsafeGetLiteral[$ - 1] = CustomTarget(messageDel, onRemoveDel);
mutex.unlock;
}
///
void clearCustomTargets() {
cast(void)mutex.lock;
customTargets = typeof(customTargets)();
mutex.unlock;
}
///
String_UTF8 toString() scope const {
return this.name;
}
///
static LoggerReference forName(return scope String_UTF8 name, return scope RCAllocator allocator = RCAllocator.init) @trusted {
if(name.length == 0)
return typeof(return)(MalformedInputException("Name must not be empty"));
mutexForCreation.pureLock;
LoggerReference ret = loggers[name];
if(ret && !ret.isNull) {
mutexForCreation.unlock;
return ret;
}
if(allocator.isNull)
allocator = globalAllocator();
if(loggers.isNull) {
loggers = ConcurrentHashMap!(String_UTF8, Logger)(globalAllocator());
loggers.cleanupUnreferencedNodes;
}
loggers[name] = Logger();
ret = loggers[name];
assert(ret);
ret.allocator = allocator;
ret.name_ = name;
ret.dateTimeFormat = GDateTime.ISO8601Format;
ret.targets = LoggingTargets.Console;
ret.fileTarget.filePrefix = String_UTF8("log");
ret.fileTarget.filePrefixSeparator = String_UTF8("_");
ret.fileTarget.fileExtension = String_UTF8("log");
ret.fileTarget.logRotateFrequency = LogRotateFrequency.OnStart;
if(name == "global") {
globalLogger = ret;
}
ret.logLevel = LogLevel.Notice;
mutexForCreation.unlock;
return ret;
}
/// Global logger "global"
static LoggerReference global() {
return Logger.forName(String_UTF8("global"));
}
///
void trace(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) scope {
if(logLevel > LogLevel.Trace)
return;
cast(void)mutex.lock;
message!(moduleName, line)(LogLevel.Trace, args);
mutex.unlock;
}
///
void debug_(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) scope {
if(logLevel > LogLevel.Debug)
return;
cast(void)mutex.lock;
message!(moduleName, line)(LogLevel.Debug, args);
mutex.unlock;
}
///
alias info = information;
///
void information(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) scope {
if(logLevel > LogLevel.Info)
return;
cast(void)mutex.lock;
message!(moduleName, line)(LogLevel.Info, args);
mutex.unlock;
}
///
void notice(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) scope {
if(logLevel > LogLevel.Notice)
return;
cast(void)mutex.lock;
message!(moduleName, line)(LogLevel.Notice, args);
mutex.unlock;
}
///
alias warn = warning;
///
void warning(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) scope {
if(logLevel > LogLevel.Warning)
return;
cast(void)mutex.lock;
message!(moduleName, line)(LogLevel.Warning, args);
mutex.unlock;
}
///
void error(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) scope {
if(logLevel > LogLevel.Error)
return;
cast(void)mutex.lock;
message!(moduleName, line)(LogLevel.Error, args);
mutex.unlock;
}
///
void critical(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) scope {
if(logLevel > LogLevel.Critical)
return;
cast(void)mutex.lock;
message!(moduleName, line)(LogLevel.Critical, args);
mutex.unlock;
}
///
void fatal(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) scope {
cast(void)mutex.lock;
message!(moduleName, line)(LogLevel.Fatal, args);
mutex.unlock;
}
///
bool opEquals(Logger other) const {
return this.name_ == other.name_;
}
///
int opCmp(Logger other) const {
return this.name_.opCmp(other.name_);
}
///
ulong toHash() const {
return this.name_.toHash();
}
/*private:*/
void message(string moduleName, int line, Args...)(LogLevel level, Args args) scope {
import sidero.base.datetime.time.clock;
import sidero.base.internal.conv;
enum ModuleLine2 = stringToWstring!moduleName ~ ":"w ~ intToWString!line;
enum ModuleLine = " `" ~ moduleName ~ ":" ~ intToString!line ~ "` ";
GDateTime currentDateTime = accurateDateTime();
StringBuilder_UTF8 dateTimeText = currentDateTime.format(this.dateTimeFormat);
StringBuilder_UTF8 contentBuilder;
String_UTF8 contentUTF8;
static immutable LevelTag = [
"TRACE", "DEBUG", "INFO", "NOTICE", "WARNING", "ERROR", "CRITICAL", "FATAL", " TRACE", " DEBUG", " INFO",
" NOTICE", " WARNING", " ERROR", " CRITICAL", " FATAL"
];
void syslog() {
version(Posix) {
import core.sys.posix.syslog : syslog, openlog, closelog, LOG_PID, LOG_CONS, LOG_USER;
guardForCreation(() @trusted {
if(!haveSysLog) {
openlog("ProjectSidero dependent program".ptr, LOG_PID | LOG_CONS, LOG_USER);
haveSysLog = true;
}
syslog(PrioritySyslogForLevels[level], contentUTF8.ptr);
});
}
}
void windowsEvents() @trusted {
version(Windows) {
import core.sys.windows.windows : ReportEventW, WORD, DWORD, EVENTLOG_INFORMATION_TYPE,
EVENTLOG_WARNING_TYPE, EVENTLOG_ERROR_TYPE;
guardForCreation(() @trusted {
static WORD[] WTypes = [
EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE, EVENTLOG_WARNING_TYPE,
EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE
];
String_UTF16 text = contentBuilder[dateTimeText.length + ModuleLine.length .. $].byUTF16.asReadOnly;
static WORD[] dwEventID = [0, 1, 2, 3, 4, 5];
const(wchar)*[2] messages = [ModuleLine2.ptr, text.ptr];
ReportEventW(needWindowsEventHandle(), WTypes[level], dwEventID[level], 0, cast(void*)null, 2,
0, &messages[0], cast(void*)null);
});
}
}
void file() @trusted {
bool triggered = fileTarget.logStream.isNull;
if(!triggered) {
// check based upon last date/time
final switch(fileTarget.logRotateFrequency) {
case LogRotateFrequency.None:
case LogRotateFrequency.OnStart:
break;
case LogRotateFrequency.Hourly:
triggered = currentDateTime.hour != fileTarget.logRotateLastDateTime.hour;
break;
case LogRotateFrequency.Daily:
triggered = currentDateTime.day != fileTarget.logRotateLastDateTime.day;
break;
}
}
if(triggered) {
// recreate!
FilePath fp = fileTarget.rootLogDirectory.dup;
StringBuilder_UTF8 filename;
filename ~= fileTarget.filePrefix;
if(fileTarget.logRotateFrequency == LogRotateFrequency.None) {
// does not include date/time
} else {
filename ~= fileTarget.filePrefixSeparator;
filename ~= currentDateTime.format(GDateTime.LogFileName);
}
if(fileTarget.fileExtension.length > 0 && !fileTarget.fileExtension.startsWith("."))
filename ~= "."c;
filename ~= fileTarget.fileExtension;
cast(void)(fp ~= filename);
auto filePath = FilePath.from(filename);
if(filePath)
fileTarget.logStream = FileAppender(filePath.get);
}
fileTarget.logStream.append(contentBuilder);
fileTarget.logStream.append(String_UTF8("\n"));
}
void custom() @trusted {
foreach(ref ct; customTargets.unsafeGetLiteral()) {
ct.messageDel(level, currentDateTime, String_UTF8(ModuleLine), String_UTF16(ModuleLine2), tags,
String_UTF8(LevelTag[level + (tags.isNull ? 0 : 6)]), contentUTF8);
}
}
if(targets & LoggingTargets.Console) {
import sidero.base.console;
auto fg = consoleTarget.colors[level][0], bg = consoleTarget.colors[level][1];
auto formatArg = resetDefaultBeforeApplying().deliminateArgs(false).prettyPrintingActive(true)
.foreground(fg).background(bg).useErrorStream(consoleTarget.useErrorStream[level]);
writeln(formatArg, dateTimeText, ModuleLine, tags, LevelTag[level + (tags.isNull ? 0 : 6)],
resetDefaultBeforeApplying(), ": ", args, resetDefaultBeforeApplying());
}
if(targets & LoggingTargets.File || targets & LoggingTargets.Syslog || targets & LoggingTargets.Windows ||
targets & LoggingTargets.Custom) {
{
contentBuilder ~= dateTimeText;
contentBuilder ~= ModuleLine;
contentBuilder ~= tags;
contentBuilder ~= LevelTag[level + (tags.isNull ? 0 : 6)];
contentBuilder ~= ": ";
PrettyPrint prettyPrinter = PrettyPrint.defaults;
prettyPrinter(contentBuilder, args);
}
if(targets & LoggingTargets.Windows)
windowsEvents;
if(targets & LoggingTargets.Syslog || targets & LoggingTargets.Custom)
contentUTF8 = contentBuilder.asReadOnly;
if(targets & LoggingTargets.File)
file;
if(targets & LoggingTargets.Syslog)
syslog;
if(targets & LoggingTargets.Custom)
custom;
}
}
}
///
void setLogProcessName(String_UTF8 name) @trusted {
if(name.length == 0) {
mutexForCreation.pureLock;
processName = String_UTF8.init;
mutexForCreation.unlock;
return;
}
if(name.isPtrNullTerminated && !name.isEncodingChanged)
processName = name;
else
processName = name.dup;
version(Posix) {
import core.sys.posix.syslog : openlog, closelog, LOG_PID, LOG_CONS, LOG_USER;
mutexForCreation.pureLock;
if(haveSysLog)
closelog();
haveSysLog = true;
openlog(processName.ptr, LOG_PID | LOG_CONS, LOG_USER);
mutexForCreation.unlock;
} else version(Windows) {
import core.sys.windows.windows : RegisterEventSourceW, DeregisterEventSource;
mutexForCreation.pureLock;
if(windowsEventHandle !is null) {
DeregisterEventSource(windowsEventHandle);
}
String_UTF16 processName16 = name.byUTF16.dup;
windowsEventHandle = RegisterEventSourceW(null, cast(wchar*)processName16.ptr);
mutexForCreation.unlock;
}
}
///
void trace(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) @trusted {
Logger.global.assumeOkay.trace!(moduleName, line)(args);
}
///
void debug_(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) @trusted {
Logger.global.assumeOkay.debug_!(moduleName, line)(args);
}
///
alias info = information;
///
void information(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) @trusted {
Logger.global.assumeOkay.info!(moduleName, line)(args);
}
///
void notice(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) @trusted {
Logger.global.assumeOkay.notice!(moduleName, line)(args);
}
///
alias warn = warning;
///
void warning(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) @trusted {
Logger.global.assumeOkay.warning!(moduleName, line)(args);
}
///
void error(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) @trusted {
Logger.global.assumeOkay.error!(moduleName, line)(args);
}
///
void critical(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) @trusted {
Logger.global.assumeOkay.critical!(moduleName, line)(args);
}
///
void fatal(string moduleName = __MODULE__, int line = __LINE__, Args...)(Args args) @trusted {
Logger.global.assumeOkay.fatal!(moduleName, line)(args);
}
pragma(crt_destructor) extern (C) void deinitializeLogging() @trusted {
version(Posix) {
import core.sys.posix.syslog : closelog;
if(haveSysLog) {
closelog;
haveSysLog = false;
}
} else version(Windows) {
import core.sys.windows.windows : DeregisterEventSource;
if(windowsEventHandle !is null) {
DeregisterEventSource(windowsEventHandle);
windowsEventHandle = null;
}
}
}
export void guardForCreation(scope void delegate() @safe nothrow @nogc del) @trusted {
mutexForCreation.pureLock;
del();
mutexForCreation.unlock;
}
version(Windows) {
export HANDLE needWindowsEventHandle() @trusted {
import core.sys.windows.windows : RegisterEventSourceW;
if(windowsEventHandle is null)
windowsEventHandle = RegisterEventSourceW(null, cast(wchar*)"ProjectSidero dependent program"w.ptr);
return windowsEventHandle;
}
}
private:
import sidero.base.containers.map.concurrenthashmap;
import sidero.base.synchronization.mutualexclusion : TestTestSetLockInline;
import sidero.base.synchronization.system.lock;
import sidero.base.internal.filesystem;
import sidero.base.datetime : GDateTime;
__gshared {
TestTestSetLockInline mutexForCreation;
ConcurrentHashMap!(String_UTF8, Logger) loggers;
LoggerReference globalLogger;
String_UTF8 processName;
bool haveSysLog;
}
struct ConsoleTarget {
static immutable DefaultErrorStream = [false, false, false, false, false, true, true, true];
static immutable ConsoleColor[2][8] DefaultConsoleColors = [
[ConsoleColor.Yellow, ConsoleColor.Unknown], [ConsoleColor.Blue, ConsoleColor.Unknown],
[ConsoleColor.Green, ConsoleColor.Unknown], [ConsoleColor.Unknown, ConsoleColor.Unknown],
[ConsoleColor.Magenta, ConsoleColor.Unknown], [ConsoleColor.Red, ConsoleColor.Yellow],
[ConsoleColor.Red, ConsoleColor.Cyan], [ConsoleColor.Red, ConsoleColor.Blue],
];
ConsoleColor[2][8] colors = DefaultConsoleColors;
bool[8] useErrorStream = DefaultErrorStream;
export @safe nothrow @nogc:
~this() {
}
}
struct FileTarget {
FilePath rootLogDirectory;
String_UTF8 filePrefix, filePrefixSeparator, fileExtension;
GDateTime logRotateLastDateTime;
LogRotateFrequency logRotateFrequency;
FileAppender logStream;
@safe nothrow @nogc:
this(return scope ref FileTarget other) scope {
}
auto toHash() scope const @trusted {
import sidero.base.hash.utils;
ulong ret = hashOf();
static foreach(I; 0 .. this.tupleof.length) {
ret = hashOf((*cast(FileTarget*)&this).tupleof[I], ret);
}
return ret;
}
}
struct CustomTarget {
CustomTargetMessage messageDel;
CustomTargetOnRemove onRemoveDel;
export @safe nothrow @nogc:
~this() scope {
if(onRemoveDel !is null)
onRemoveDel();
}
}
version(Windows) {
import core.sys.windows.windows : HANDLE;
__gshared HANDLE windowsEventHandle;
} else version(Posix) {
import core.sys.posix.syslog : LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR, LOG_CRIT;
static PrioritySyslogForLevels = [
LOG_DEBUG, LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR, LOG_ERR, LOG_CRIT
];
}