EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
logsys.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: Zhur
24 */
25 
26 
27 #ifndef LOGSYS_H_
28 #define LOGSYS_H_
29 
30 /*
31  *
32  * Usage:
33  *
34  * These are the main functions provided by logsys:
35  * - _log(TYPE, fmt, ...) - Log a message in any context
36  * - _hex(TYPE, data, length) - Log hex dump in any context.
37  * Types are defined in logtypes.h
38  *
39  *
40  *
41  *
42  * this is very C-ish, not C++ish, but thats how I felt like writting it
43  *
44  *
45  *
46  */
47 
48 #include <execinfo.h>
49 
50 
51 #define LOG_CATEGORY(category) LOG_ ##category ,
53 {
54  #include "logtypes.h"
56 };
57 
58 #define LOG_TYPE(category, type, enabled, str) category##__##type ,
59 enum LogType
60 {
61  #include "logtypes.h"
63 };
64 
66 
68 {
69  bool enabled;
71  const char *name;
72  const char *display_name;
73 };
74 
75 //expose a read-only pointer
76 extern const LogTypeStatus* log_type_info;
77 
78 #define is_log_enabled( type ) \
79  ( log_type_info[ ( type ) ].enabled )
80 
81 extern void log_enable( LogType t );
82 extern void log_disable( LogType t );
83 extern void log_toggle( LogType t );
84 
85 extern bool log_open_logfile( const char* filename );
86 extern bool log_close_logfile();
87 
88 extern bool load_log_settings( const char* filename );
89 
90 extern void log_message(LogType type, const char *fmt, ...);
91 extern void log_messageVA(LogType type, const char *fmt, va_list args);
92 extern void log_messageVA(LogType type, uint32 iden, const char *fmt, va_list args);
93 extern void log_hex(LogType type, const void *data, unsigned long length, unsigned char padding=4);
94 extern void log_phex(LogType type, const void *data, unsigned long length, unsigned char padding=4);
95 
96 #if defined ( DISABLE_LOGSYS )
97 //completely disabled, this is the best I can come up with since we have no variadic macros
98 # define _log( type, fmt, ... )
99 # define codelog( type, fmt, ... )
100 #elif defined ( NO_VARIADIC_MACROS )
101 inline void _log( LogType type, const char* fmt, ... )
102 {
103  va_list args;
104  va_start( args, fmt );
105 
106  if( is_log_enabled( type ) )
107  log_messageVA( type, fmt, args );
108 
109  va_end( args );
110 }
111 //we cannot actually implement this one without variadic
112 inline void codelog( LogType type, const char* fmt, ... )
113 {
114  va_list args;
115  va_start( args, fmt );
116 
117  if( is_log_enabled( type ) )
118  log_messageVA( type, fmt, args );
119 
120  va_end(args);
121 }
122 #else
123 //we have variadic macros, hooray!
124 # define _log( type, fmt, ... ) \
125  if ( is_log_enabled( type ) ) \
126  log_message( type, fmt, ##__VA_ARGS__ )
127 
128 # define codelog( type, fmt, ... ) \
129  if ( is_log_enabled( type ) ) \
130  log_message( type, "%s(%s:%d): " fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__ )
131 #endif
132 
133 #define _hex( type, data, len) \
134  if ( is_log_enabled( type ) ) \
135  log_hex( type, (const char*)data, len )
136 
137 #define phex( type, data, len) \
138  if ( is_log_enabled( type ) ) \
139  log_phex( type, (const char*)data, len )
140 
141 
142 #endif /*LOGSYS_H_*/
143 
144 
145 
146 
147 
148 
LogCategory
Definition: logsys.h:52
#define _log(type, fmt,...)
Definition: logsys.h:124
void log_messageVA(LogType type, const char *fmt, va_list args)
Definition: logsys.cpp:79
const char * name
Definition: logsys.h:71
bool log_close_logfile()
Definition: logsys.cpp:160
bool log_open_logfile(const char *filename)
Definition: logsys.cpp:149
void log_toggle(LogType t)
Definition: logsys.cpp:144
LogCategory category
Definition: logsys.h:70
* args
#define is_log_enabled(type)
Definition: logsys.h:78
void log_enable(LogType t)
Definition: logsys.cpp:134
#define codelog(type, fmt,...)
Definition: logsys.h:128
const char * display_name
Definition: logsys.h:72
void log_phex(LogType type, const void *data, unsigned long length, unsigned char padding=4)
Definition: logsys.cpp:60
bool enabled
Definition: logsys.h:69
unsigned __int32 uint32
Definition: eve-compat.h:50
bool load_log_settings(const char *filename)
Definition: logsys.cpp:168
LogType
Definition: logsys.h:59
const char * log_category_names[NUMBER_OF_LOG_CATEGORIES]
Definition: logsys.cpp:37
void log_message(LogType type, const char *fmt,...)
Definition: logsys.cpp:72
const LogTypeStatus * log_type_info
Definition: logsys.cpp:49
void log_disable(LogType t)
Definition: logsys.cpp:139
void log_hex(LogType type, const void *data, unsigned long length, unsigned char padding=4)
Definition: logsys.cpp:51