OregonCore  revision fb2a440-git
Your Favourite TBC server
Log Class Reference

Main logging class. More...

#include <Log.h>

+ Inheritance diagram for Log:

Public Member Functions

void Initialize ()
 
void InitColors (const std::string &init_str)
 
void SetColor (ColorTypes color)
 Sets color for upcoming output. More...
 
void ResetColor ()
 Resets output color to normal. More...
 
void outString (const char *fmt,...) ATTR_PRINTF(2
 
void void outBasic (const char *fmt,...) ATTR_PRINTF(2
 
void void void outDetail (const char *fmt,...) ATTR_PRINTF(2
 
void void void void outDebug (const char *fmt,...) ATTR_PRINTF(2
 
void void void void void outError (const char *fmt,...) ATTR_PRINTF(2
 
void void void void void void outErrorDb (const char *fmt,...) ATTR_PRINTF(2
 
void void void void void void void outSQL (const char *fmt,...) ATTR_PRINTF(2
 
void void void void void void void void outArena (const char *fmt,...) ATTR_PRINTF(2
 
void void void void void void void void void outWarden (const char *fmt,...) ATTR_PRINTF(2
 
void void void void void void void void void void outChat (const char *fmt,...) ATTR_PRINTF(2
 
void void void void void void void void void void void outCommand (const char *fmt,...) ATTR_PRINTF(2
 
void void void void void void void void void void void void outChar (const char *fmt,...) ATTR_PRINTF(2
 
void void void void void void void void void void void void void outRemote (const char *fmt,...) ATTR_PRINTF(2
 
void void void void void void void void void void void void void void outMap (const char *fmt,...) ATTR_PRINTF(2
 
void void void void void void void void void void void void void void void outVMap (const char *fmt,...) ATTR_PRINTF(2
 
void void void void void void void void void void void void void void void void outMMap (const char *fmt,...) ATTR_PRINTF(2
 
void void void void void void void void void void void void void void void void void outNetwork (const char *fmt,...) ATTR_PRINTF(2
 
void void void void void void void void void void void void void void void void void void outDB (LogTypes type, const char *str)
 
void outString ()
 
void outDebugInLine (const char *fmt,...) ATTR_PRINTF(2
 
void void outFatal (const char *err,...) ATTR_PRINTF(2
 
void outCharDump (const char *str, uint32 account_id, uint32 guid, const char *name)
 
void outCommand (uint64 account, const char *fmt,...) ATTR_PRINTF(3
 
void SetLogMask (unsigned long mask)
 
void SetDBLogMask (unsigned long mask)
 
unsigned long GetLogMask () const
 
unsigned long GetDBLogMask () const
 
bool IsOutDebug () const
 Checks whether outDebug works. More...
 
bool IsLogTypeEnabled (LogTypes type) const
 

Static Public Member Functions

void static void outTimestamp (FILE *file)
 
static std::string GetTimestampStr ()
 
- Static Public Member Functions inherited from Oregon::Singleton< Log, Oregon::ClassLevelLockable< Log, ACE_Thread_Mutex > >
static LogInstance ()
 

Public Attributes

void void ATTR_NORETURN
 

Private Member Functions

 Log ()
 
 ~Log ()
 
void DoLog (LogTypes type, bool newline, const char *prefix, const char *fmt, va_list ap, FILE *file=NULL)
 Performs logging. More...
 
FILE * openLogFile (char const *configFileName, char const *configTimeStampFlag, char const *mode)
 
FILE * openGmlogPerAccount (uint64 account)
 opens specific file for account More...
 

Private Attributes

FILE * m_logFiles [MAX_LOG_TYPES]
 files for each message type More...
 
std::string m_logsDir
 directory to put log files in More...
 
std::string m_logsTimestamp
 
bool m_gmlog_per_account
 flag: create separate log for every GM account? More...
 
std::string m_gmlog_filename_format
 format for GM log filename More...
 
ColorTypes m_colors [MAX_LOG_TYPES]
 colors assigned to individual message types More...
 
unsigned long m_logMask
 mask to filter messages sent to console and files More...
 
unsigned long m_logMaskDatabase
 mask to filter messages sent to db More...
 

Friends

class Oregon::OperatorNew< Log >
 

Additional Inherited Members

- Protected Member Functions inherited from Oregon::Singleton< Log, Oregon::ClassLevelLockable< Log, ACE_Thread_Mutex > >
 Singleton ()
 

Detailed Description

Main logging class.

Definition at line 90 of file Log.h.

Constructor & Destructor Documentation

Log::Log ( )
private

Definition at line 53 of file Log.cpp.

References Initialize(), m_colors, and m_logFiles.

54 {
55  memset(m_logFiles, 0, sizeof(m_logFiles));
56  memset(m_colors, 0, sizeof(m_colors));
57 
58  Initialize();
59 }
bool m_gmlog_per_account
flag: create separate log for every GM account?
Definition: Log.h:177
unsigned long m_logMask
mask to filter messages sent to console and files
Definition: Log.h:182
void Initialize()
Definition: Log.cpp:86
FILE * m_logFiles[MAX_LOG_TYPES]
files for each message type
Definition: Log.h:172
ColorTypes m_colors[MAX_LOG_TYPES]
colors assigned to individual message types
Definition: Log.h:180
unsigned long m_logMaskDatabase
mask to filter messages sent to db
Definition: Log.h:183
Log::~Log ( )
private

Definition at line 61 of file Log.cpp.

References m_logFiles, and MAX_LOG_TYPES.

62 {
63  std::set<FILE*> openfiles;
64 
65  for (size_t i = 0; i < MAX_LOG_TYPES; ++i)
66  if (m_logFiles[i])
67  openfiles.insert(m_logFiles[i]);
68 
69  for (std::set<FILE*>::iterator i = openfiles.begin(); i != openfiles.end(); ++i)
70  {
71  fflush(*i);
72  fclose(*i);
73  }
74 }
FILE * m_logFiles[MAX_LOG_TYPES]
files for each message type
Definition: Log.h:172

Member Function Documentation

void Log::DoLog ( LogTypes  type,
bool  newline,
const char *  prefix,
const char *  fmt,
va_list  ap,
FILE *  file = NULL 
)
private

Performs logging.

Performs logging.

Parameters
typeone value of the LogTypes
newlineset if newline should be put after the message
prefixprefix, usually the LogTypes as string
fmtprintf-like formatting message
aplist of arguments
fileif set, use this file instead of m_logFiles[type]

Definition at line 401 of file Log.cpp.

References m_colors, m_logFiles, m_logMask, m_logMaskDatabase, outDB(), outTimestamp(), ResetColor(), SetColor(), Utf8toWStr(), and vsnprintf.

Referenced by IsLogTypeEnabled(), and outCommand().

402 {
403  va_list ap2;
404  va_copy(ap2, ap);
405 
406  size_t len = vsnprintf(NULL, 0, fmt, ap2) + 1;
407  char* buffer = (char*) ((len > 1024) ? malloc(len * sizeof(char)) : alloca(len * sizeof(char)));
408 
409  va_end(ap2);
410  vsprintf(buffer, fmt, ap);
411 
412  if (m_logMaskDatabase & (1 << type))
413  {
414  // we don't want empty strings in the DB
415  if (*buffer && *buffer != ' ' && *buffer != '\n')
416  outDB(type, buffer);
417  }
418 
419  if (m_logMask & (1 << type))
420  {
421  if (FILE* logFile = (file ? file : m_logFiles[type]))
422  {
423  outTimestamp(logFile);
424  fwrite(buffer, len-1, 1, logFile);
425  if (newline)
426  fputc('\n', logFile);
427  fflush(logFile);
428  }
429 
430  if (prefix)
431  {
432  if (colorPrefixTable[m_colors[type]])
433  SetColor(colorPrefixTable[m_colors[type]]);
434 
435  fprintf(stderr, "[%s] ", prefix);
436  }
437 
438  if (m_colors[type])
439  SetColor(m_colors[type]);
440 
441  #if PLATFORM == PLATFORM_WINDOWS
442  wchar_t* wtemp_buf = (wchar_t*) _malloca(len * sizeof(wchar_t));
443  size_t siz = len - 1;
444  if (Utf8toWStr(buffer, len-1, wtemp_buf, siz))
445  {
446  CharToOemBuffW(wtemp_buf, buffer, siz);
447  fwrite(buffer, siz, 1, stderr);
448  }
449  _freea(wtemp_buf);
450  #else
451  fwrite(buffer, len-1, 1, stderr);
452  #endif
453 
454  if (m_colors[type])
455  ResetColor();
456 
457  if (newline)
458  fputc('\n', stderr);
459 
460  // just to be sure, stderr should be unbuffered anyway
461  fflush(stderr);
462  }
463 
464  if (len > 1024)
465  free(buffer);
466 }
void SetColor(ColorTypes color)
Sets color for upcoming output.
Definition: Log.cpp:274
unsigned long m_logMask
mask to filter messages sent to console and files
Definition: Log.h:182
void static void outTimestamp(FILE *file)
Definition: Log.cpp:241
bool Utf8toWStr(char const *utf8str, size_t csize, wchar_t *wstr, size_t &wsize)
Definition: Util.cpp:255
FILE * m_logFiles[MAX_LOG_TYPES]
files for each message type
Definition: Log.h:172
ColorTypes m_colors[MAX_LOG_TYPES]
colors assigned to individual message types
Definition: Log.h:180
void ResetColor()
Resets output color to normal.
Definition: Log.cpp:354
void void void void void void void void void void void void void void void void void void outDB(LogTypes type, const char *str)
Definition: Log.cpp:381
unsigned long m_logMaskDatabase
mask to filter messages sent to db
Definition: Log.h:183
#define vsnprintf
Definition: Common.h:131
unsigned long Log::GetDBLogMask ( ) const
inline

Definition at line 147 of file Log.h.

References m_logMaskDatabase.

148  {
149  return m_logMaskDatabase;
150  }
unsigned long m_logMaskDatabase
mask to filter messages sent to db
Definition: Log.h:183
unsigned long Log::GetLogMask ( ) const
inline

Definition at line 142 of file Log.h.

References m_logMask.

143  {
144  return m_logMask;
145  }
unsigned long m_logMask
mask to filter messages sent to console and files
Definition: Log.h:182
std::string Log::GetTimestampStr ( )
static

Definition at line 369 of file Log.cpp.

References snprintf.

Referenced by Initialize().

370 {
371  time_t t = time(NULL);
372  tm* aTm = localtime(&t);
373  // YYYY year
374  // MM month (2 digits 01-12)
375  // DD day (2 digits 01-31)
376  char buf[20];
377  snprintf(buf, 20, "%04d-%02d-%02d", aTm->tm_year + 1900, aTm->tm_mon + 1, aTm->tm_mday);
378  return std::string(buf);
379 }
#define snprintf
Definition: Common.h:129
void Log::InitColors ( const std::string &  init_str)

Definition at line 254 of file Log.cpp.

References m_colors, MAX_COLORS, and MAX_LOG_TYPES.

Referenced by Initialize().

255 {
256  std::stringstream ss(str);
257 
258  for (uint8 i = 0; i < MAX_LOG_TYPES; ++i)
259  {
260  int color;
261  ss >> color;
262 
263  if (ss.eof() || ss.fail() || ss.bad())
264  break;
265 
266  if (color < 0 || color >= MAX_COLORS)
267  break;
268 
269  m_colors[i] = ColorTypes (color);
270  }
271  }
Definition: Log.h:86
ACE_UINT8 uint8
Definition: Define.h:73
ColorTypes
Definition: Log.h:67
ColorTypes m_colors[MAX_LOG_TYPES]
colors assigned to individual message types
Definition: Log.h:180
void Log::Initialize ( void  )

Definition at line 86 of file Log.cpp.

References GetTimestampStr(), InitColors(), LOG_TYPE_ARENA, LOG_TYPE_BASIC, LOG_TYPE_CHAR, LOG_TYPE_CHAT, LOG_TYPE_COMMAND, LOG_TYPE_DEBUG, LOG_TYPE_DETAIL, LOG_TYPE_ERROR, LOG_TYPE_ERROR_DB, LOG_TYPE_MAP, LOG_TYPE_MMAP, LOG_TYPE_NETWORK, LOG_TYPE_REMOTE, LOG_TYPE_SQL, LOG_TYPE_STRING, LOG_TYPE_VMAP, LOG_TYPE_WARDEN, LOGL_BASIC, LOGL_DEBUG, LOGL_DETAIL, LOGL_MINIMAL, m_gmlog_filename_format, m_gmlog_per_account, m_logFiles, m_logMask, m_logMaskDatabase, m_logsDir, m_logsTimestamp, MAX_LOG_TYPES, openLogFile(), and sConfig.

Referenced by Log().

87 {
88  // Common log files data
89  m_logsDir = sConfig.GetStringDefault("LogsDir", "0 6 4 3 1 1 2 7 5 0 4 0 1 3 2 4 0");
90  if (!m_logsDir.empty())
91  if ((m_logsDir.at(m_logsDir.length() - 1) != '/') && (m_logsDir.at(m_logsDir.length() - 1) != '\\'))
92  m_logsDir.append("/");
93 
95 
96  // Open specific log files
97  FILE* logfile = openLogFile("LogFile", "LogTimestamp", "wb");
98 
99  for (int i = 0; i < MAX_LOG_TYPES; ++i)
100  if (!m_logFiles[i])
101  m_logFiles[i] = logfile;
102 
103  InitColors(sConfig.GetStringDefault("LogColors", "0 6 4 3 1 1 2 7 5 0 4 0 1 3 2 4 0"));
104 
105  m_gmlog_per_account = sConfig.GetBoolDefault("GmLogPerAccount", false);
106  if (!m_gmlog_per_account)
107  m_logFiles[LOG_TYPE_COMMAND] = openLogFile("GMLogFile", "GmLogTimestamp", "ab");
108  else
109  {
110  // GM log settings for per account case
111  m_gmlog_filename_format = sConfig.GetStringDefault("GMLogFile", "");
112  if (!m_gmlog_filename_format.empty())
113  {
114  bool m_gmlog_timestamp = sConfig.GetBoolDefault("GmLogTimestamp", false);
115 
116  size_t dot_pos = m_gmlog_filename_format.find_last_of(".");
117  if (dot_pos != m_gmlog_filename_format.npos)
118  {
119  if (m_gmlog_timestamp)
120  m_gmlog_filename_format.insert(dot_pos, m_logsTimestamp);
121 
122  m_gmlog_filename_format.insert(dot_pos, "_#%u");
123  }
124  else
125  {
126  m_gmlog_filename_format += "_#%u";
127 
128  if (m_gmlog_timestamp)
130  }
131 
133  }
134  }
135 
136  m_logFiles[LOG_TYPE_CHAR] = openLogFile("CharLogFile", "CharLogTimestamp", "ab");
137  m_logFiles[LOG_TYPE_ERROR_DB] = openLogFile("DBErrorLogFile", NULL, "ab");
138  m_logFiles[LOG_TYPE_REMOTE] = openLogFile("RaLogFile", NULL, "ab");
139  m_logFiles[LOG_TYPE_CHAT] = openLogFile("ChatLogFile", "ChatLogTimestamp", "ab");
140  m_logFiles[LOG_TYPE_ARENA] = openLogFile("ArenaLogFile", NULL, "ab");
141  m_logFiles[LOG_TYPE_WARDEN] = openLogFile("Warden.LogFile", NULL, "ab");
142  m_logFiles[LOG_TYPE_NETWORK] = openLogFile("WorldLogFile", NULL, "ab");
143  m_logFiles[LOG_TYPE_SQL] = openLogFile("LogSQLFilename", "LogSQLTimestamp", "ab");
144 
145  m_logMask = sConfig.GetIntDefault("LogMask", 51);
146  m_logMaskDatabase = sConfig.GetIntDefault("DBLogMask", 0);
147 
148  // -------------------------------------------------------------------
149  // Deprecated, kept for backward compatibilty - @todo remove in future
150  // -------------------------------------------------------------------
151 
152  // Main log file settings
153  switch (sConfig.GetIntDefault("LogLevel", -1))
154  {
155  case LOGL_MINIMAL:
157  break;
158  case LOGL_BASIC:
161  break;
162  case LOGL_DETAIL:
166  break;
167  case LOGL_DEBUG:
172  break;
173  case -1:
174  break;
175  }
176 
177  switch (sConfig.GetIntDefault("DBLogLevel", -1))
178  {
179  case LOGL_MINIMAL:
181  break;
182  case LOGL_BASIC:
185  break;
186  case LOGL_DETAIL:
190  break;
191  case LOGL_DEBUG:
196  break;
197  case -1:
198  break;
199  }
200 
201  // Check whether we'll log GM commands/RA events/character outputs/chat stuffs
202  m_logMaskDatabase |= static_cast<unsigned char>(sConfig.GetBoolDefault("LogDB.Char", false)) << LOG_TYPE_CHAR;
203  m_logMaskDatabase |= static_cast<unsigned char>(sConfig.GetBoolDefault("LogDB.RA", false)) << LOG_TYPE_REMOTE;
204  m_logMaskDatabase |= static_cast<unsigned char>(sConfig.GetBoolDefault("LogDB.GM", false)) << LOG_TYPE_COMMAND;
205  m_logMaskDatabase |= static_cast<unsigned char>(sConfig.GetBoolDefault("LogDB.Chat", false)) << LOG_TYPE_CHAT;
206 }
#define sConfig
Definition: Config.h:52
bool m_gmlog_per_account
flag: create separate log for every GM account?
Definition: Log.h:177
std::string m_logsDir
directory to put log files in
Definition: Log.h:174
Definition: Log.h:62
NULL Dbg ErrDB Arena Chat LOG_TYPE_CHAR
Definition: Log.cpp:547
unsigned long m_logMask
mask to filter messages sent to console and files
Definition: Log.h:182
std::string m_gmlog_filename_format
format for GM log filename
Definition: Log.h:178
static std::string GetTimestampStr()
Definition: Log.cpp:369
NULL Dbg ErrDB Arena Chat Char LOG_TYPE_MAP
Definition: Log.cpp:550
std::string m_logsTimestamp
Definition: Log.h:175
FILE * m_logFiles[MAX_LOG_TYPES]
files for each message type
Definition: Log.h:172
NULL Dbg ErrDB Arena LOG_TYPE_CHAT
Definition: Log.cpp:544
Definition: Log.h:60
NULL Dbg ErrDB Arena Chat Char Map LOG_TYPE_MMAP
Definition: Log.cpp:552
void InitColors(const std::string &init_str)
Definition: Log.cpp:254
NULL LOG_TYPE_DEBUG
Definition: Log.cpp:536
unsigned long m_logMaskDatabase
mask to filter messages sent to db
Definition: Log.h:183
NULL Dbg LOG_TYPE_ERROR_DB
Definition: Log.cpp:539
NULL Dbg ErrDB LOG_TYPE_ARENA
Definition: Log.cpp:542
FILE * openLogFile(char const *configFileName, char const *configTimeStampFlag, char const *mode)
Definition: Log.cpp:208
LOG_TYPE_BASIC
Definition: Log.cpp:534
bool Log::IsLogTypeEnabled ( LogTypes  type) const
inline

Definition at line 158 of file Log.h.

References DoLog(), m_logMask, m_logMaskDatabase, openGmlogPerAccount(), and openLogFile().

159  {
160  return (m_logMask | m_logMaskDatabase) & (1 << type);
161  }
unsigned long m_logMask
mask to filter messages sent to console and files
Definition: Log.h:182
unsigned long m_logMaskDatabase
mask to filter messages sent to db
Definition: Log.h:183
bool Log::IsOutDebug ( ) const
inline

Checks whether outDebug works.

Definition at line 153 of file Log.h.

References LOG_TYPE_DEBUG, m_logMask, and m_logMaskDatabase.

154  {
156  }
unsigned long m_logMask
mask to filter messages sent to console and files
Definition: Log.h:182
unsigned long m_logMaskDatabase
mask to filter messages sent to db
Definition: Log.h:183
FILE * Log::openGmlogPerAccount ( uint64  account)
private

opens specific file for account

Opens appropriate log for GM account

Parameters
accountaccount id
Returns
the open file

Definition at line 231 of file Log.cpp.

References m_gmlog_filename_format, OREGON_PATH_MAX, and snprintf.

Referenced by IsLogTypeEnabled(), and outCommand().

232 {
233  if (m_gmlog_filename_format.empty())
234  return NULL;
235 
236  char namebuf[OREGON_PATH_MAX];
237  snprintf(namebuf, OREGON_PATH_MAX, m_gmlog_filename_format.c_str(), account);
238  return fopen(namebuf, "ab");
239 }
#define snprintf
Definition: Common.h:129
std::string m_gmlog_filename_format
format for GM log filename
Definition: Log.h:178
#define OREGON_PATH_MAX
Definition: Define.h:40
FILE * Log::openLogFile ( char const *  configFileName,
char const *  configTimeStampFlag,
char const *  mode 
)
private

Definition at line 208 of file Log.cpp.

References m_logsDir, m_logsTimestamp, and sConfig.

Referenced by Initialize(), and IsLogTypeEnabled().

209 {
210  std::string logfn = sConfig.GetStringDefault(configFileName, "");
211  if (logfn.empty())
212  return NULL;
213 
214  if (configTimeStampFlag && sConfig.GetBoolDefault(configTimeStampFlag, false))
215  {
216  size_t dot_pos = logfn.find_last_of(".");
217  if (dot_pos != logfn.npos)
218  logfn.insert(dot_pos, m_logsTimestamp);
219  else
220  logfn += m_logsTimestamp;
221  }
222 
223  return fopen((m_logsDir + logfn).c_str(), mode);
224 }
#define sConfig
Definition: Config.h:52
std::string m_logsDir
directory to put log files in
Definition: Log.h:174
std::string m_logsTimestamp
Definition: Log.h:175
void void void void void void void void Log::outArena ( const char *  fmt,
  ... 
)
void void Log::outBasic ( const char *  fmt,
  ... 
)
void void void void void void void void void void void void Log::outChar ( const char *  fmt,
  ... 
)
void Log::outCharDump ( const char *  str,
uint32  account_id,
uint32  guid,
const char *  name 
)

Definition at line 512 of file Log.cpp.

References LOG_TYPE_CHAR, and m_logFiles.

513 {
515  {
516  fprintf(m_logFiles[LOG_TYPE_CHAR], "== START DUMP == (account: %u guid: %u name: %s)\n%s\n== END DUMP ==\n", account_id, guid, name, str);
517  fflush(m_logFiles[LOG_TYPE_CHAR]);
518  }
519 }
NULL Dbg ErrDB Arena Chat LOG_TYPE_CHAR
Definition: Log.cpp:547
FILE * m_logFiles[MAX_LOG_TYPES]
files for each message type
Definition: Log.h:172
void void void void void void void void void void Log::outChat ( const char *  fmt,
  ... 
)
void void void void void void void void void void void Log::outCommand ( const char *  fmt,
  ... 
)
void Log::outCommand ( uint64  account,
const char *  fmt,
  ... 
)

Definition at line 489 of file Log.cpp.

References DoLog(), LOG_TYPE_COMMAND, m_gmlog_per_account, m_logFiles, m_logMask, m_logMaskDatabase, and openGmlogPerAccount().

490 {
491  if (!((m_logMask | m_logMaskDatabase) & (1 << LOG_TYPE_COMMAND)))
492  return;
493 
494  FILE* file;
496  file = openGmlogPerAccount(account);
497  else
499 
500  va_list ap;
501  va_start(ap, str);
502  DoLog(LOG_TYPE_COMMAND, true, "CMD", str, ap, file);
503  va_end(ap);
504 
506  {
507  fflush(file);
508  fclose(file);
509  }
510 }
bool m_gmlog_per_account
flag: create separate log for every GM account?
Definition: Log.h:177
void DoLog(LogTypes type, bool newline, const char *prefix, const char *fmt, va_list ap, FILE *file=NULL)
Performs logging.
Definition: Log.cpp:401
unsigned long m_logMask
mask to filter messages sent to console and files
Definition: Log.h:182
FILE * m_logFiles[MAX_LOG_TYPES]
files for each message type
Definition: Log.h:172
FILE * openGmlogPerAccount(uint64 account)
opens specific file for account
Definition: Log.cpp:231
unsigned long m_logMaskDatabase
mask to filter messages sent to db
Definition: Log.h:183
void Log::outDB ( LogTypes  type,
const char *  str 
)

Definition at line 381 of file Log.cpp.

References Database::escape_string(), Database::IsConnected(), LoginDatabase, Database::PExecute(), realmID, and UI64FMTD.

Referenced by DoLog().

382 {
383  if (!LoginDatabase.IsConnected())
384  return;
385 
386  std::string new_str(str);
387  LoginDatabase.escape_string(new_str);
388  LoginDatabase.PExecute("INSERT INTO logs (time, realm, type, string) "
389  "VALUES (" UI64FMTD ", %u, %u, '%s');", uint64(time(0)), realmID, type, new_str.c_str());
390 }
uint32 realmID
Id of the realm.
Definition: Main.cpp:57
bool IsConnected() const
Definition: Database.h:62
unsigned long escape_string(char *to, const char *from, unsigned long length)
Definition: Database.cpp:212
#define UI64FMTD
Definition: Common.h:149
DatabaseType LoginDatabase
Accessor to the realm/login database.
Definition: Main.cpp:55
bool PExecute(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:441
ACE_UINT64 uint64
Definition: Define.h:70
void void void void Log::outDebug ( const char *  fmt,
  ... 
)
void Log::outDebugInLine ( const char *  fmt,
  ... 
)

Referenced by outString().

void void void Log::outDetail ( const char *  fmt,
  ... 
)
void void void void void Log::outError ( const char *  fmt,
  ... 
)

Referenced by outFatal().

void void void void void void Log::outErrorDb ( const char *  fmt,
  ... 
)
void Log::outFatal ( const char *  err,
  ... 
)

Definition at line 468 of file Log.cpp.

References LOG_TYPE_ERROR, m_logMask, outError(), sConsole, and vsnprintf.

469 {
470  va_list ap;
471  va_start(ap, err);
472  size_t len = vsnprintf(NULL, 0, err, ap) + 1;
473  char* buffer = (char*) alloca(len);
474  buffer[len - 1] = '\0';
475  va_end(ap);
476  va_start(ap, err);
477  vsprintf(buffer, err, ap);
478  va_end(ap);
479 
481  outError("%s", buffer);
482 
483  if (sConsole.IsEnabled())
484  sConsole.FatalError(buffer);
485 
486  exit (EXIT_FAILURE);
487 }
#define sConsole
Definition: Console.h:99
unsigned long m_logMask
mask to filter messages sent to console and files
Definition: Log.h:182
void void void void void outError(const char *fmt,...) ATTR_PRINTF(2
#define vsnprintf
Definition: Common.h:131
void void void void void void void void void void void void void void Log::outMap ( const char *  fmt,
  ... 
)
void void void void void void void void void void void void void void void void Log::outMMap ( const char *  fmt,
  ... 
)
void void void void void void void void void void void void void void void void void Log::outNetwork ( const char *  fmt,
  ... 
)
void void void void void void void void void void void void void Log::outRemote ( const char *  fmt,
  ... 
)
void void void void void void void Log::outSQL ( const char *  fmt,
  ... 
)
void Log::outString ( const char *  fmt,
  ... 
)
void Log::outString ( )
inline

Definition at line 127 of file Log.h.

References ATTR_PRINTF, and outDebugInLine().

128  {
129  outString("");
130  }
void outString()
Definition: Log.h:127
void Log::outTimestamp ( FILE *  file)
static

Definition at line 241 of file Log.cpp.

Referenced by DoLog().

242 {
243  time_t t = time(NULL);
244  tm* aTm = localtime(&t);
245  // YYYY year
246  // MM month (2 digits 01-12)
247  // DD day (2 digits 01-31)
248  // HH hour (2 digits 00-23)
249  // MM minutes (2 digits 00-59)
250  // SS seconds (2 digits 00-59)
251  fprintf(file, "%-4d-%02d-%02d %02d:%02d:%02d ", aTm->tm_year + 1900, aTm->tm_mon + 1, aTm->tm_mday, aTm->tm_hour, aTm->tm_min, aTm->tm_sec);
252 }
void void void void void void void void void void void void void void void Log::outVMap ( const char *  fmt,
  ... 
)
void void void void void void void void void Log::outWarden ( const char *  fmt,
  ... 
)
void Log::ResetColor ( )

Resets output color to normal.

Definition at line 354 of file Log.cpp.

References sConsole.

Referenced by DoLog().

355 {
356  if (sConsole.IsEnabled())
357  {
358  fputc(0xFE, stderr);
359  return;
360  }
361 
362  #if PLATFORM == PLATFORM_WINDOWS
363  SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
364  #else
365  fprintf(stderr, "\x1b[0m");
366  #endif
367 }
#define sConsole
Definition: Console.h:99
void Log::SetColor ( ColorTypes  color)

Sets color for upcoming output.

Definition at line 274 of file Log.cpp.

References MAX_COLORS, and sConsole.

Referenced by DoLog().

275 {
276  if (sConsole.IsEnabled())
277  {
278  fputc(0xFF, stderr);
279  #if defined(__PDCURSES__) && !defined(PDC_RGB)
280  // BGR mode, convert from RGB then
281  int clr = int(color);
282  int rgb = (clr & 0x07);
283  clr &= ~0x07;
284  clr |= (rgb & 0x1) << 2; // red
285  clr |= (rgb & 0x2); // green
286  clr |= (rgb & 0x4) >> 2; // blue
287  color = ColorTypes(clr);
288  #endif
289  fputc((char) color, stderr);
290  return;
291  }
292 
293  #if PLATFORM == PLATFORM_WINDOWS
294  static WORD WinColorFG[MAX_COLORS] =
295  {
296  0, // BLACK
297  FOREGROUND_RED, // RED
298  FOREGROUND_GREEN, // GREEN
299  FOREGROUND_RED | FOREGROUND_GREEN, // BROWN
300  FOREGROUND_BLUE, // BLUE
301  FOREGROUND_RED | FOREGROUND_BLUE,// MAGENTA
302  FOREGROUND_GREEN | FOREGROUND_BLUE, // CYAN
303  FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,// WHITE
304  FOREGROUND_INTENSITY, // BLACK, BOLD (GREY?)
305  FOREGROUND_RED | FOREGROUND_INTENSITY, // RED, BOLD
306  FOREGROUND_GREEN | FOREGROUND_INTENSITY, // GREEN, BOLD
307  FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY, // YELLOW
308  FOREGROUND_BLUE | FOREGROUND_INTENSITY, // BLUE, BOLD
309  FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY, // MAGENTA, BOLD
310  FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY, // CYAN, BOLD
311  FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY // WHITE, BOLD
312  };
313 
314  SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), WinColorFG[color]);
315  #else
316 
317  enum ANSIFgTextAttr
318  {
319  FG_BLACK = 30,
320  FG_RED,
321  FG_GREEN,
322  FG_YELLOW,
323  FG_BLUE,
324  FG_MAGENTA,
325  FG_CYAN,
326  FG_WHITE
327  };
328 
329  static uint8 UnixColorFG[MAX_COLORS] =
330  {
331  FG_BLACK, // BLACK
332  FG_RED, // RED
333  FG_GREEN, // GREEN
334  FG_YELLOW, // BROWN
335  FG_BLUE, // BLUE
336  FG_MAGENTA, // MAGENTA
337  FG_CYAN, // CYAN
338  FG_WHITE, // LGREY
339  FG_BLACK, // GREY
340  FG_RED, // LRED
341  FG_GREEN, // LGREEN
342  FG_YELLOW, // YELLOW
343  FG_BLUE, // LBLUE
344  FG_MAGENTA, // LMAGENTA
345  FG_CYAN, // LCYAN
346  FG_WHITE // LWHITE
347  };
348 
349  fprintf(stderr, "\x1b[%s%dm", ((color > 7) ? "01;" : "00;"), UnixColorFG[color]);
350  #endif
351 }
Definition: Log.h:86
#define sConsole
Definition: Console.h:99
ACE_UINT8 uint8
Definition: Define.h:73
ColorTypes
Definition: Log.h:67
void Log::SetDBLogMask ( unsigned long  mask)

Definition at line 81 of file Log.cpp.

References m_logMaskDatabase.

82 {
83  m_logMaskDatabase = mask;
84 }
unsigned long m_logMaskDatabase
mask to filter messages sent to db
Definition: Log.h:183
void Log::SetLogMask ( unsigned long  mask)

Definition at line 76 of file Log.cpp.

References m_logMask.

77 {
78  m_logMask = mask;
79 }
unsigned long m_logMask
mask to filter messages sent to console and files
Definition: Log.h:182

Friends And Related Function Documentation

friend class Oregon::OperatorNew< Log >
friend

Definition at line 92 of file Log.h.

Member Data Documentation

void void Log::ATTR_NORETURN

Definition at line 132 of file Log.h.

ColorTypes Log::m_colors[MAX_LOG_TYPES]
private

colors assigned to individual message types

Definition at line 180 of file Log.h.

Referenced by DoLog(), InitColors(), and Log().

std::string Log::m_gmlog_filename_format
private

format for GM log filename

Definition at line 178 of file Log.h.

Referenced by Initialize(), and openGmlogPerAccount().

bool Log::m_gmlog_per_account
private

flag: create separate log for every GM account?

Definition at line 177 of file Log.h.

Referenced by Initialize(), and outCommand().

FILE* Log::m_logFiles[MAX_LOG_TYPES]
private

files for each message type

Definition at line 172 of file Log.h.

Referenced by DoLog(), Initialize(), Log(), outCharDump(), outCommand(), and ~Log().

unsigned long Log::m_logMask
private

mask to filter messages sent to console and files

Definition at line 182 of file Log.h.

Referenced by DoLog(), GetLogMask(), Initialize(), IsLogTypeEnabled(), IsOutDebug(), outCommand(), outFatal(), and SetLogMask().

unsigned long Log::m_logMaskDatabase
private

mask to filter messages sent to db

Definition at line 183 of file Log.h.

Referenced by DoLog(), GetDBLogMask(), Initialize(), IsLogTypeEnabled(), IsOutDebug(), outCommand(), and SetDBLogMask().

std::string Log::m_logsDir
private

directory to put log files in

Definition at line 174 of file Log.h.

Referenced by Initialize(), and openLogFile().

std::string Log::m_logsTimestamp
private

Definition at line 175 of file Log.h.

Referenced by Initialize(), and openLogFile().


The documentation for this class was generated from the following files: