From 216ab4260fa05795564766ab3ea0f3020d036fd3 Mon Sep 17 00:00:00 2001 From: Alexander Wenzel Date: Mon, 2 Dec 2013 13:35:30 +0100 Subject: Environement variables added to configure internal logging in library. Signed-off-by: Alexander Wenzel --- include/dlt/dlt_common.h | 12 ++++++++++++ src/lib/dlt_user.c | 3 +++ src/shared/dlt_common.c | 49 ++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h index 7f205c9..0740c9e 100755 --- a/include/dlt/dlt_common.h +++ b/include/dlt/dlt_common.h @@ -174,6 +174,13 @@ #define LOG_DAEMON (3<<3) #endif +enum { + DLT_LOG_TO_CONSOLE=0, + DLT_LOG_TO_SYSLOG=1, + DLT_LOG_TO_FILE=2, + DLT_LOG_DROPPED=3 +}; + /** * The standard TCP Port used for DLT daemon */ @@ -1232,6 +1239,11 @@ extern "C" */ int dlt_message_argument_print(DltMessage *msg,uint32_t type_info,uint8_t **ptr,int32_t *datalength,char *text,int textlength,int byteLength,int verbose); + /** + * Check environment variables. + */ + void dlt_check_envvar(); + #ifdef __cplusplus } #endif diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index 56e8417..40e7cf9 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -180,6 +180,9 @@ int dlt_init(void) return -1; } + /* check environment variables */ + dlt_check_envvar(); + dlt_user.dlt_is_file = 0; dlt_user.overflow = 0; dlt_user.overflow_counter = 0; diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index 52eabed..9739266 100755 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -101,7 +101,7 @@ const char dltSerialHeader[DLT_ID_SIZE] = { 'D','L','S',1 }; char dltSerialHeaderChar[DLT_ID_SIZE] = { 'D','L','S',1 }; /* internal logging parameters */ -static int logging_mode = 0; +static int logging_mode = DLT_LOG_TO_CONSOLE; static int logging_level = 6; static char logging_filename[NAME_MAX + 1] = ""; static FILE *logging_handle = 0; @@ -2024,7 +2024,7 @@ void dlt_log_init(int mode) { logging_mode = mode; - if(logging_mode == 2) + if(logging_mode == DLT_LOG_TO_FILE) { /* internal logging to file */ logging_handle = fopen(logging_filename,"w"); @@ -2038,7 +2038,7 @@ void dlt_log_init(int mode) void dlt_log_free(void) { - if(logging_mode == 2) { + if(logging_mode == DLT_LOG_TO_FILE) { fclose(logging_handle); } } @@ -2107,11 +2107,11 @@ int dlt_log(int prio, char *s) switch(logging_mode) { - case 0: + case DLT_LOG_TO_CONSOLE: /* log to stdout */ printf(logfmtstring, s); break; - case 1: + case DLT_LOG_TO_SYSLOG: /* log to syslog */ #if !defined (__WIN32__) && !defined(_MSC_VER) openlog("DLT",LOG_PID,LOG_DAEMON); @@ -2119,13 +2119,16 @@ int dlt_log(int prio, char *s) closelog(); #endif break; - case 2: + case DLT_LOG_TO_FILE: /* log to file */ if(logging_handle) { fprintf(logging_handle,logfmtstring, s); fflush(logging_handle); } break; + case DLT_LOG_DROPPED: + default: + break; } return 0; @@ -3637,3 +3640,37 @@ int dlt_message_argument_print(DltMessage *msg,uint32_t type_info,uint8_t **ptr, return 0; } + +void dlt_check_envvar() +{ + char* env_log_filename = getenv("DLT_LOG_FILENAME"); + + if( env_log_filename != NULL ) + { + dlt_log_set_filename(env_log_filename); + } + + char* env_log_level_str = getenv("DLT_LOG_LEVEL"); + + if( env_log_level_str != NULL ) + { + int level = 0; + if( sscanf(env_log_level_str, "%d", &level) ) + { + dlt_log_set_level(level); + } + } + + char* env_log_mode = getenv("DLT_LOG_MODE"); + + if( env_log_mode != NULL ) + { + int mode = 0; + if( sscanf(env_log_mode, "%d", &mode) ) + { + dlt_log_init(mode); + } + } + + +} -- cgit v1.2.1