1 /**
2 Copyright: Copyright (c) 2016-2017, Joakim Brännström. All rights reserved.
3 License: MPL-2
4 Author: Joakim Brännström (joakim.brannstrom@gmx.com)
5 
6 This Source Code Form is subject to the terms of the Mozilla Public License,
7 v.2.0. If a copy of the MPL was not distributed with this file, You can obtain
8 one at http://mozilla.org/MPL/2.0/.
9 
10 Logging utilities used to avoid template bloat by only instansiating the logger
11 template one time by taking func and line as runtime parameters.
12 */
13 module dextool.logger;
14 
15 static import std.experimental.logger;
16 
17 /// Only use via the aliases
18 auto internalLog(alias level)(const(char)[] txt, const uint indent = 0,
19         string func = __FUNCTION__, uint line = __LINE__) nothrow {
20     import std.algorithm : min;
21     import std.array : array;
22     import std.range : repeat;
23 
24     immutable indent_prep = repeat(' ', 1024).array();
25 
26     try {
27         string indent_ = indent_prep[0 .. min(indent_prep.length, indent)];
28         std.experimental.logger.logf!(-1, "", "", "", "")(level,
29                 "%d%s %s [%s:%d]", indent, indent_, txt, func, line);
30     }
31     catch (Exception ex) {
32     }
33 }
34 
35 alias trace = internalLog!(std.experimental.logger.LogLevel.trace);
36 alias info = internalLog!(std.experimental.logger.LogLevel.info);
37 alias error = internalLog!(std.experimental.logger.LogLevel.error);
38 alias fatal = internalLog!(std.experimental.logger.LogLevel.fatal);