1 /**
2 Copyright: Copyright (c) 2015-2018 Andrey Penechko.
3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0).
4 Authors: Andrey Penechko.
5 */
6 module voxelman.log.utils;
7 
8 import std.experimental.logger;
9 import std.stdio : stdout, File;
10 
11 class ConciseLogger : FileLogger
12 {
13 	import std.datetime : SysTime;
14 	import std.concurrency : Tid;
15 	this(File file, const LogLevel lv = LogLevel.info) @safe
16 	{
17 		super(file, lv);
18 	}
19 
20 	this(in string fn, const LogLevel lv = LogLevel.info) @safe
21 	{
22 		super(fn, lv);
23 	}
24 
25 	override protected void beginLogMsg(string file, int line, string funcName,
26 		string prettyFuncName, string moduleName, LogLevel logLevel,
27 		Tid threadId, SysTime timestamp, Logger logger)
28 		@safe
29 	{
30 		// empty
31 	}
32 }
33 
34 MultiLogger setupMultiLogger()
35 {
36 	globalLogLevel = LogLevel.all;
37 	auto logger = new MultiLogger;
38 	sharedLog = logger;
39 	return logger;
40 }
41 
42 void setupFileLogger(MultiLogger parentLogger, string filename)
43 {
44 	auto file = File(filename, "w");
45 	auto fileLogger = new ConciseLogger(file);
46 	fileLogger.logLevel = LogLevel.all;
47 	parentLogger.insertLogger("fileLogger", fileLogger);
48 }
49 
50 void setupStdoutLogger(MultiLogger parentLogger)
51 {
52 	auto conciseLogger = new ConciseLogger(stdout);
53 	conciseLogger.logLevel = LogLevel.info;
54 	parentLogger.insertLogger("stdoutLogger", conciseLogger);
55 }