comparison doodle/core/logging.d @ 58:c63719604adb

Beginnings of creating a rectangle...
author "David Bryant <bagnose@gmail.com>"
date Mon, 09 Aug 2010 21:43:24 +0930
parents 0eaf39fda206
children 523269b36711 ab745d8b10e5
comparison
equal deleted inserted replaced
57:9960c4fbd0dd 58:c63719604adb
1 module doodle.core.logging; 1 module doodle.core.logging;
2 2
3 private { 3 private {
4 import std.stdio; 4 import std.stdio;
5 import std.typecons; 5 import std.typecons;
6 import std.traits;
6 } 7 }
7 8
8 public { 9 public {
9 void trace(string file = __FILE__, int line = __LINE__)(in string message) { 10 void trace(string file = __FILE__, int line = __LINE__, S...)(S args) {
10 log(Severity.TRACE, std.string.format("%s(%d): TRACE: %s", right(file, 20), line, message)); 11 static assert(S.length > 0);
12 static assert(isSomeString!(S[0]));
13 log(Severity.TRACE,
14 std.string.format("%s(%d): MESSAGE: %s", right(file, 20), line, std.string.format(args)));
11 } 15 }
12 void info(string file = __FILE__, int line = __LINE__)(in string message) { 16
13 log(Severity.INFO, std.string.format("%s(%d): INFO: %s", right(file, 20), line, message)); 17 void info(string file = __FILE__, int line = __LINE__, S...)(S args) {
18 static assert(S.length > 0);
19 static assert(isSomeString!(S[0]));
20 log(Severity.INFO,
21 std.string.format("%s(%d): MESSAGE: %s", right(file, 20), line, std.string.format(args)));
14 } 22 }
15 void message(string file = __FILE__, int line = __LINE__)(in string message) { 23
16 log(Severity.MESSAGE, std.string.format("%s(%d): MESSAGE: %s", right(file, 20), line, message)); 24 void message(string file = __FILE__, int line = __LINE__, S...)(S args) {
25 static assert(S.length > 0);
26 static assert(isSomeString!(S[0]));
27 log(Severity.MESSAGE,
28 std.string.format("%s(%d): MESSAGE: %s", right(file, 20), line, std.string.format(args)));
17 } 29 }
18 void warning(string file = __FILE__, int line = __LINE__)(in string message) { 30
19 log(Severity.WARNING, std.string.format("%s(%d): WARNING: %s", right(file, 20), line, message)); 31 void warning(string file = __FILE__, int line = __LINE__, S...)(S args) {
32 static assert(S.length > 0);
33 static assert(isSomeString!(S[0]));
34 log(Severity.WARNING,
35 std.string.format("%s(%d): MESSAGE: %s", right(file, 20), line, std.string.format(args)));
20 } 36 }
21 void error(string file = __FILE__, int line = __LINE__)(in string message) { 37
22 log(Severity.ERROR, std.string.format("%s(%d): ERROR: %s", right(file, 20), line, message)); 38 void error(string file = __FILE__, int line = __LINE__, S...)(S args) {
39 static assert(S.length > 0);
40 static assert(isSomeString!(S[0]));
41 log(Severity.ERROR,
42 std.string.format("%s(%d): MESSAGE: %s", right(file, 20), line, std.string.format(args)));
23 } 43 }
24 void fatal(string file = __FILE__, int line = __LINE__)(in string message) { 44
25 log(Severity.FATAL, std.string.format("%s(%d): FATAL: %s", right(file, 20), line, message)); 45 void fatal(string file = __FILE__, int line = __LINE__, S...)(S args) {
46 static assert(S.length > 0);
47 static assert(isSomeString!(S[0]));
48 log(Severity.FATAL,
49 std.string.format("%s(%d): MESSAGE: %s", right(file, 20), line, std.string.format(args)));
26 assert(0); 50 assert(0);
27 } 51 }
28 } 52 }
29 53
30 private { 54 private {
50 } 74 }
51 assert(0); 75 assert(0);
52 } 76 }
53 77
54 void log(in Severity severity, in string message) { 78 void log(in Severity severity, in string message) {
55 write(severityString(severity)); 79 writeln(severityString(severity), message, modifierString(Modifier.RESET));
56 write(message);
57 writeln(modifierString(Modifier.RESET));
58 } 80 }
59 81
60 enum Modifier { 82 enum Modifier {
61 RESET = 0, 83 RESET = 0,
62 BRIGHT = 1, 84 BRIGHT = 1,