Environement variables added to configure internal logging in library.
authorAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Mon, 2 Dec 2013 12:35:30 +0000 (13:35 +0100)
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Fri, 10 Jan 2014 06:15:55 +0000 (07:15 +0100)
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
include/dlt/dlt_common.h
src/lib/dlt_user.c
src/shared/dlt_common.c

index 7f205c9..0740c9e 100755 (executable)
 #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
index 56e8417..40e7cf9 100644 (file)
@@ -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;
index 52eabed..9739266 100755 (executable)
@@ -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);
+               }
+       }
+
+
+}