Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/Tools/3dsmaxExport/LEXIExporter/SharedUtilities/Sources/ConsoleLogger.cpp @ 11

Last change on this file since 11 was 6, checked in by anonymous, 18 years ago

=…

File size: 2.4 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of LEXIExporter
4
5Copyright 2006 NDS Limited
6
7Author(s):
8Lasse Tassing
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25
26#include "stdafx.h"
27
28CConsoleLogger::CConsoleLogger(bool bLogTimes, ELogLevel eMinLevel)
29{
30        m_bLogTimes=bLogTimes;
31
32        // Setup colors
33        memset(m_wColors,0xFF,sizeof(WORD)*255);
34        m_wColors[LOG_INFO]             =FOREGROUND_GREEN|FOREGROUND_INTENSITY;
35        m_wColors[LOG_DEBUG]    =FOREGROUND_BLUE|FOREGROUND_INTENSITY;
36        m_wColors[LOG_WARNING]  =FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY;
37        m_wColors[LOG_ERROR]    =FOREGROUND_RED|FOREGROUND_INTENSITY;
38       
39        m_eMinLevel=eMinLevel;
40        AllocConsole();
41        m_hConsoleHandle=GetStdHandle(STD_OUTPUT_HANDLE);
42}
43CConsoleLogger::~CConsoleLogger(void)
44{
45        FreeConsole();
46}
47
48// Set level color. Mostly used for custom logging levels.
49void CConsoleLogger::SetLevelColor(int iMessageLevel, WORD wColor)
50{
51        if(iMessageLevel<255 && iMessageLevel>=0) m_wColors[iMessageLevel]=wColor;
52}
53
54// Called from the logsystem
55void CConsoleLogger::ReceiveLogMessage(SYSTEMTIME &LogTime, const char *pszTimeStr, int iMessageLevel, const char *pszMessage)
56{
57        // Do we want to write the message?
58        if(iMessageLevel<m_eMinLevel) return;
59
60        // Setup color
61        if(iMessageLevel<255 && m_wColors[iMessageLevel]!=0xFFFF)
62                SetConsoleTextAttribute(m_hConsoleHandle, m_wColors[iMessageLevel]);
63
64        // Write to console
65        DWORD dwWritten;
66        if(m_bLogTimes)
67                WriteConsole(m_hConsoleHandle, pszTimeStr, (DWORD)strlen(pszTimeStr), &dwWritten, NULL);
68        WriteConsole(m_hConsoleHandle, pszMessage, (DWORD)strlen(pszMessage), &dwWritten, NULL);
69}
Note: See TracBrowser for help on using the repository browser.