view 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
line wrap: on
line source

/* 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 <http://www.gnu.org/licenses/>. */

/**************************************************************************************************
 * 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;
}