EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LogNew.h
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Captnoord
24 */
25 
26 #ifndef __LOG__LOG_NEW_H__INCL__
27 #define __LOG__LOG_NEW_H__INCL__
28 
29 #include "utils/Singleton.h"
30 #include "threading/Mutex.h"
31 
41 class NewLog
42 : public Singleton< NewLog >
43 {
44 public:
46  NewLog();
47  NewLog(std::string logPath);
49  ~NewLog();
50 
51  void Initialize();
52 
58  void InitializeLogging( std::string logPath );
65  void Log( const char* source, const char* fmt, ... );
72  void Error( const char* source, const char* fmt, ... );
79  void Warning( const char* source, const char* fmt, ... );
86  void White( const char* source, const char* fmt, ... );
93  void Green( const char* source, const char* fmt, ... );
100  void Blue( const char* source, const char* fmt, ... );
107  void Magenta( const char* source, const char* fmt, ... );
114  void Yellow( const char* source, const char* fmt, ... );
121  void Cyan( const char* source, const char* fmt, ... );
130  void Debug( const char* source, const char* fmt, ... );
131 
140  bool SetLogfile( const char* filename );
151  bool SetLogfile( FILE* file );
152 
158  void SetTime( time_t time ) { mTime = time; }
159 
160 protected:
162  enum Color
163  {
173 
175  };
176 
188  void PrintMsg( Color color, char pfx, const char* source, const char* fmt, va_list ap );
192  void PrintTime();
193 
203  void Print( const char* fmt, ... );
213  void PrintVa( const char* fmt, va_list ap );
214 
220  void SetColor( Color color );
224  void SetLogfileDefault(std::string logPath);
225 
227  FILE* mLogfile;
229  time_t mTime; // crap there should be 1 generic easy to understand time manager.
232 
234 
235 #ifdef HAVE_WINDOWS_H
236  const HANDLE mStdOutHandle;
239  const HANDLE mStdErrHandle;
240 
242  static const WORD COLOR_TABLE[ COLOR_COUNT ];
243 #else /* !HAVE_WINDOWS_H */
244  static const char* const COLOR_TABLE[ COLOR_COUNT ];
246 #endif /* !HAVE_WINDOWS_H */
247 };
248 
250 #define sLog \
251  ( NewLog::get() )
252 
253 #endif /* !__LOG__LOG_NEW_H__INCL__ */
void PrintTime()
Prints current time.
Definition: LogNew.cpp:256
void SetColor(Color color)
Sets the color of the output text.
Definition: LogNew.cpp:302
Magenta color.
Definition: LogNew.h:170
Red color.
Definition: LogNew.h:166
void Cyan(const char *source, const char *fmt,...)
Logs a message to console in cyan.
Definition: LogNew.cpp:141
A default color.
Definition: LogNew.h:164
void Blue(const char *source, const char *fmt,...)
Logs a message to console in blue.
Definition: LogNew.cpp:161
void Debug(const char *source, const char *fmt,...)
Logs a debug message to file and console.
Definition: LogNew.cpp:191
void Yellow(const char *source, const char *fmt,...)
Logs a message to console in yellow.
Definition: LogNew.cpp:181
Mutex mMutex
Protection against concurrent log messages.
Definition: LogNew.h:231
FILE * mLogfile
The active logfile.
Definition: LogNew.h:227
Common wrapper for platform-specific mutexes.
Definition: Mutex.h:36
Green color.
Definition: LogNew.h:167
void Magenta(const char *source, const char *fmt,...)
Logs a message to console in magenta.
Definition: LogNew.cpp:171
void SetLogfileDefault(std::string logPath)
Sets the default logfile.
Definition: LogNew.cpp:315
Yellow color.
Definition: LogNew.h:168
void Log(const char *source, const char *fmt,...)
Logs a message to file.
Definition: LogNew.cpp:99
static const char *const COLOR_TABLE[COLOR_COUNT]
Color translation table.
Definition: LogNew.h:245
Cyan color.
Definition: LogNew.h:171
Number of colors.
Definition: LogNew.h:174
time_t mTime
Current timestamp.
Definition: LogNew.h:229
Black color.
Definition: LogNew.h:165
bool m_initialized
Definition: LogNew.h:233
bool SetLogfile(const char *filename)
Sets the logfile to be used.
Definition: LogNew.cpp:203
void SetTime(time_t time)
Sets the log system time every main loop.
Definition: LogNew.h:158
void Warning(const char *source, const char *fmt,...)
Logs a warning message to file.
Definition: LogNew.cpp:131
Color
A convenience color enum.
Definition: LogNew.h:162
Blue color.
Definition: LogNew.h:169
void InitializeLogging(std::string logPath)
Initializes and sets the Log file path.
Definition: LogNew.cpp:88
NewLog()
Primary constructor, initializes logging.
Definition: LogNew.cpp:48
a small and simple logging system.
Definition: LogNew.h:41
~NewLog()
Destructor, closes the logfile.
Definition: LogNew.cpp:74
White color.
Definition: LogNew.h:172
void Green(const char *source, const char *fmt,...)
Logs a message to console in green.
Definition: LogNew.cpp:151
void PrintVa(const char *fmt, va_list ap)
Prints a raw message.
Definition: LogNew.cpp:279
void White(const char *source, const char *fmt,...)
Logs a message to console in white.
Definition: LogNew.cpp:109
void PrintMsg(Color color, char pfx, const char *source, const char *fmt, va_list ap)
Prints a message.
Definition: LogNew.cpp:230
void Error(const char *source, const char *fmt,...)
Logs error message to console and file.
Definition: LogNew.cpp:121
Template used for singleton classes.
Definition: Singleton.h:43
void Initialize()
Definition: LogNew.cpp:82
void Print(const char *fmt,...)
Prints a raw message.
Definition: LogNew.cpp:269