# HG changeset patch # User Diggory Hardy # Date 1253003797 -7200 # Node ID 62aa8845edd2000971735723b63f89835b8d7723 # Parent af40e96794360b5b695377980f3f3e09b9664a99 Coloured log output to the console. diff -r af40e9679436 -r 62aa8845edd2 data/L10n/en-GB.mtt --- a/data/L10n/en-GB.mtt Sat Sep 12 09:50:33 2009 +0200 +++ b/data/L10n/en-GB.mtt Tue Sep 15 10:36:37 2009 +0200 @@ -42,6 +42,7 @@ + diff -r af40e9679436 -r 62aa8845edd2 mde/setup/Init.d --- a/mde/setup/Init.d Sat Sep 12 09:50:33 2009 +0200 +++ b/mde/setup/Init.d Tue Sep 15 10:36:37 2009 +0200 @@ -43,6 +43,7 @@ import mde.setup.InitStage; // Controls external delegates run by init import mde.setup.exception; import mde.setup.logger; +import mde.setup.LogLayout; import mde.content.AStringContent; import mde.content.ContentLoader; @@ -89,6 +90,7 @@ ["Trace", "Info", "Warn", "Error", "Fatal", "None"]); logOutput = new EnumContent ("MiscOptions.logOutput", ["both", "file", "console", "none"]); + logColour = new BoolContent ("MiscOptions.logColour"); // Callback to set the logging level on change: logLevel.addCallback (&setLogLevel); @@ -160,6 +162,9 @@ // Where logging is done to is determined at compile-time, currently just via static ifs. root = Log.root; root.clear; // we may no longer want to log to the console + Appender.Layout layout = null; + if (logColour()) + layout = new LayoutTimerColour(); // logOutput == 0 enables both outputs, in case options aren't read if (!(logOutput() & 2)) { // first appender so root seperator messages don't show on console @@ -169,7 +174,7 @@ root.append (Level.None, ""); } if (!(logOutput() & 1)) - root.add(new AppendConsole); + root.add(new AppendConsole (layout)); } catch (Exception e) { // Presumably it was only adding a file appender which failed; set up a new console // logger and if that fails let the exception kill the program. @@ -399,7 +404,7 @@ private static { Logger logger; - BoolContent exitImmediately; + BoolContent exitImmediately, logColour; IntContent maxThreads; EnumContent logLevel, logOutput; diff -r af40e9679436 -r 62aa8845edd2 mde/setup/LogLayout.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mde/setup/LogLayout.d Tue Sep 15 10:36:37 2009 +0200 @@ -0,0 +1,54 @@ +/* LICENSE BLOCK +Part of mde: a Modular D game-oriented Engine +Copyright © 2007-2008 Diggory Hardy + +This program is free software: you can redistribute it and/or modify it under the terms +of the GNU General Public License as published by the Free Software Foundation, either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . */ + +/************************************************************************************************** + * Provides coloured log output. + *************************************************************************************************/ +module mde.setup.LogLayout; + +import tango.util.log.Log; + +public class LayoutTimerColour : Appender.Layout +{ + this () { + colour = ["\033[0;37m", "\033[0;0m", "\033[0;33m", "\033[0;31m", "\033[0;35m"]; + bold = ["\033[1;30m", "\033[1;1m", "\033[1;33m", "\033[1;31m", "\033[1;35m"]; + } + + void format (LogEvent event, size_t delegate(void[]) dg) + { + char[20] tmp = void; + size_t i = cast(size_t)event.level; + if (i >= 5) i = 1; + + dg ("\033[1;97m"); + dg (event.toMilli (tmp, event.span)); + dg ("\t"); +// dg (Thread.getThis.name); +// dg (" "); + dg (bold[i]); + dg (event.levelName); + dg (colour[i]); + dg (event.name); + dg (event.host.context.label); + dg (bold[i]); + dg (" - "); + dg (colour[i]); + dg (event.toString); + dg ("\033[0;00m"); + } + + char[][] colour, bold; +} diff -r af40e9679436 -r 62aa8845edd2 mde/setup/logger.d --- a/mde/setup/logger.d Sat Sep 12 09:50:33 2009 +0200 +++ b/mde/setup/logger.d Tue Sep 15 10:36:37 2009 +0200 @@ -21,6 +21,7 @@ *****************************************************************************/ module mde.setup.logger; +import mde.setup.LogLayout; import tango.util.log.Log; import tango.util.log.AppendConsole; @@ -29,5 +30,5 @@ Logger root = Log.root; debug root.level(Logger.Trace); else root.level(Logger.Info); - root.add(new AppendConsole); + root.add(new AppendConsole (new LayoutTimerColour())); }