summaryrefslogtreecommitdiffstats
path: root/src/server/globals.c
diff options
context:
space:
mode:
authorSimon Rettberg2015-02-22 22:03:39 +0100
committerSimon Rettberg2015-02-22 22:03:39 +0100
commitea8f4961c6e4f94bf82e4c4cadbab4ec08824ae4 (patch)
tree4371eacef27e477523d6e05ef29c741540a77e32 /src/server/globals.c
parentGet rid of unneccessary volatile (diff)
downloaddnbd3-ea8f4961c6e4f94bf82e4c4cadbab4ec08824ae4.tar.gz
dnbd3-ea8f4961c6e4f94bf82e4c4cadbab4ec08824ae4.tar.xz
dnbd3-ea8f4961c6e4f94bf82e4c4cadbab4ec08824ae4.zip
[SERVER] Overhauled logging
- Added message type parameter - Log to file and stdout, no more logging in memory - Added options to server.conf to filter which messages show up where
Diffstat (limited to 'src/server/globals.c')
-rw-r--r--src/server/globals.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/server/globals.c b/src/server/globals.c
index 441b2d1..a0d6ea9 100644
--- a/src/server/globals.c
+++ b/src/server/globals.c
@@ -1,6 +1,6 @@
#include "globals.h"
#include "ini.h"
-#include "memlog.h"
+#include "log.h"
#include "../types.h"
#include <stddef.h>
#include <string.h>
@@ -22,6 +22,8 @@ int _clientTimeout = 15000;
#define SAVE_TO_VAR_BOOL(ss, kk) do { if (strcmp(section, #ss) == 0 && strcmp(key, #kk) == 0) _ ## kk = atoi(value) != 0 || strcmp(value, "true") == 0 || strcmp(value, "True") == 0 || strcmp(value, "TRUE") == 0; } while (0)
#define SAVE_TO_VAR_INT(ss, kk) do { if (strcmp(section, #ss) == 0 && strcmp(key, #kk) == 0) _ ## kk = atoi(value); } while (0)
+static void handleMaskString( const char *value, void(*func)(logmask_t) );
+
static int ini_handler(void *custom UNUSED, const char* section, const char* key, const char* value)
{
if ( _basePath == NULL ) SAVE_TO_VAR_STR( dnbd3, basePath );
@@ -33,6 +35,16 @@ static int ini_handler(void *custom UNUSED, const char* section, const char* key
SAVE_TO_VAR_INT( dnbd3, clientPenalty );
SAVE_TO_VAR_INT( dnbd3, uplinkTimeout );
SAVE_TO_VAR_INT( dnbd3, clientTimeout );
+ if ( strcmp( section, "logging" ) == 0 && strcmp( key, "fileMask" ) == 0 ) handleMaskString( value, &log_setFileMask );
+ if ( strcmp( section, "logging" ) == 0 && strcmp( key, "consoleMask" ) == 0 ) handleMaskString( value, &log_setConsoleMask );
+ if ( strcmp( section, "logging" ) == 0 && strcmp( key, "file" ) == 0 ) {
+ if ( log_openLogFile( value ) ) {
+ logadd( LOG_INFO, "Opened log file %s", value );
+ } else {
+ logadd( LOG_ERROR, "Could not open log file %s", value );
+ exit( EXIT_FAILURE );
+ }
+ }
return 1;
}
@@ -44,11 +56,11 @@ void globals_loadConfig()
ini_parse( name, &ini_handler, NULL );
free( name );
if ( _basePath == NULL || _basePath[0] == '\0' ) {
- memlogf( "[ERROR] Need to specify basePath in " CONFIG_FILENAME );
+ logadd( LOG_ERROR, "Need to specify basePath in " CONFIG_FILENAME );
exit( EXIT_FAILURE );
}
if ( _basePath[0] != '/' ) {
- memlogf( "[ERROR] _basePath must be absolute!" );
+ logadd( LOG_ERROR, "_basePath must be absolute!" );
exit( EXIT_FAILURE );
}
char *end = _basePath + strlen( _basePath ) - 1;
@@ -57,3 +69,17 @@ void globals_loadConfig()
if ( _serverPenalty < 0 ) _serverPenalty = 0;
if ( _clientPenalty < 0 ) _clientPenalty = 0;
}
+
+#define SETLOGBIT(name) do { if ( strstr( value, #name ) != NULL ) mask |= LOG_ ## name; } while (0)
+static void handleMaskString( const char *value, void(*func)(logmask_t) )
+{
+ logmask_t mask = 0;
+ SETLOGBIT( ERROR );
+ SETLOGBIT( WARNING );
+ SETLOGBIT( MINOR );
+ SETLOGBIT( INFO );
+ SETLOGBIT( DEBUG1 );
+ SETLOGBIT( DEBUG2 );
+ (*func)( mask );
+}
+