Mercurial > projects > mde
annotate mde/setup/LogLayout.d @ 178:62aa8845edd2
Coloured log output to the console.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Tue, 15 Sep 2009 10:36:37 +0200 |
parents | |
children |
rev | line source |
---|---|
178
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it under the terms |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
16 /************************************************************************************************** |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
17 * Provides coloured log output. |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
18 *************************************************************************************************/ |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
19 module mde.setup.LogLayout; |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
20 |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
21 import tango.util.log.Log; |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
22 |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
23 public class LayoutTimerColour : Appender.Layout |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
24 { |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
25 this () { |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
26 colour = ["\033[0;37m", "\033[0;0m", "\033[0;33m", "\033[0;31m", "\033[0;35m"]; |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
27 bold = ["\033[1;30m", "\033[1;1m", "\033[1;33m", "\033[1;31m", "\033[1;35m"]; |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
28 } |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
29 |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
30 void format (LogEvent event, size_t delegate(void[]) dg) |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
31 { |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
32 char[20] tmp = void; |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
33 size_t i = cast(size_t)event.level; |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
34 if (i >= 5) i = 1; |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
35 |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
36 dg ("\033[1;97m"); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
37 dg (event.toMilli (tmp, event.span)); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
38 dg ("\t"); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
39 // dg (Thread.getThis.name); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
40 // dg (" "); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
41 dg (bold[i]); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
42 dg (event.levelName); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
43 dg (colour[i]); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
44 dg (event.name); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
45 dg (event.host.context.label); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
46 dg (bold[i]); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
47 dg (" - "); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
48 dg (colour[i]); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
49 dg (event.toString); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
50 dg ("\033[0;00m"); |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
51 } |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
52 |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
53 char[][] colour, bold; |
62aa8845edd2
Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
54 } |