Mercurial > projects > mde
comparison mde/setup/Init.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 | a1ba9157510e |
children |
comparison
equal
deleted
inserted
replaced
177:af40e9679436 | 178:62aa8845edd2 |
---|---|
41 module mde.setup.Init; | 41 module mde.setup.Init; |
42 | 42 |
43 import mde.setup.InitStage; // Controls external delegates run by init | 43 import mde.setup.InitStage; // Controls external delegates run by init |
44 import mde.setup.exception; | 44 import mde.setup.exception; |
45 import mde.setup.logger; | 45 import mde.setup.logger; |
46 import mde.setup.LogLayout; | |
46 | 47 |
47 import mde.content.AStringContent; | 48 import mde.content.AStringContent; |
48 import mde.content.ContentLoader; | 49 import mde.content.ContentLoader; |
49 import paths = mde.file.paths; | 50 import paths = mde.file.paths; |
50 import mde.exception; // optionsLoadException | 51 import mde.exception; // optionsLoadException |
87 maxThreads = new IntContent ("MiscOptions.maxThreads"); | 88 maxThreads = new IntContent ("MiscOptions.maxThreads"); |
88 logLevel = new EnumContent ("MiscOptions.logLevel", | 89 logLevel = new EnumContent ("MiscOptions.logLevel", |
89 ["Trace", "Info", "Warn", "Error", "Fatal", "None"]); | 90 ["Trace", "Info", "Warn", "Error", "Fatal", "None"]); |
90 logOutput = new EnumContent ("MiscOptions.logOutput", | 91 logOutput = new EnumContent ("MiscOptions.logOutput", |
91 ["both", "file", "console", "none"]); | 92 ["both", "file", "console", "none"]); |
93 logColour = new BoolContent ("MiscOptions.logColour"); | |
92 | 94 |
93 // Callback to set the logging level on change: | 95 // Callback to set the logging level on change: |
94 logLevel.addCallback (&setLogLevel); | 96 logLevel.addCallback (&setLogLevel); |
95 } | 97 } |
96 | 98 |
158 Logger root; | 160 Logger root; |
159 try { | 161 try { |
160 // Where logging is done to is determined at compile-time, currently just via static ifs. | 162 // Where logging is done to is determined at compile-time, currently just via static ifs. |
161 root = Log.root; | 163 root = Log.root; |
162 root.clear; // we may no longer want to log to the console | 164 root.clear; // we may no longer want to log to the console |
165 Appender.Layout layout = null; | |
166 if (logColour()) | |
167 layout = new LayoutTimerColour(); | |
163 | 168 |
164 // logOutput == 0 enables both outputs, in case options aren't read | 169 // logOutput == 0 enables both outputs, in case options aren't read |
165 if (!(logOutput() & 2)) { // first appender so root seperator messages don't show on console | 170 if (!(logOutput() & 2)) { // first appender so root seperator messages don't show on console |
166 // Use 2 log files with a maximum size of 16kiB: | 171 // Use 2 log files with a maximum size of 16kiB: |
167 root.add (new AppendFiles (paths.logDir~"/log-.txt", 2, 16*1024)); | 172 root.add (new AppendFiles (paths.logDir~"/log-.txt", 2, 16*1024)); |
168 root.append (Level.None, ""); // some kind of separation between runs | 173 root.append (Level.None, ""); // some kind of separation between runs |
169 root.append (Level.None, ""); | 174 root.append (Level.None, ""); |
170 } | 175 } |
171 if (!(logOutput() & 1)) | 176 if (!(logOutput() & 1)) |
172 root.add(new AppendConsole); | 177 root.add(new AppendConsole (layout)); |
173 } catch (Exception e) { | 178 } catch (Exception e) { |
174 // Presumably it was only adding a file appender which failed; set up a new console | 179 // Presumably it was only adding a file appender which failed; set up a new console |
175 // logger and if that fails let the exception kill the program. | 180 // logger and if that fails let the exception kill the program. |
176 root.clear; | 181 root.clear; |
177 root.add (new AppendConsole); | 182 root.add (new AppendConsole); |
397 logger.warn ("InitStage {}: was not run due to unmet dependencies", stage.name); | 402 logger.warn ("InitStage {}: was not run due to unmet dependencies", stage.name); |
398 } | 403 } |
399 | 404 |
400 private static { | 405 private static { |
401 Logger logger; | 406 Logger logger; |
402 BoolContent exitImmediately; | 407 BoolContent exitImmediately, logColour; |
403 IntContent maxThreads; | 408 IntContent maxThreads; |
404 EnumContent logLevel, logOutput; | 409 EnumContent logLevel, logOutput; |
405 | 410 |
406 // Callback on logLevel | 411 // Callback on logLevel |
407 void setLogLevel (IContent = null) { | 412 void setLogLevel (IContent = null) { |