#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
*/
*/
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
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;
{
logging_mode = mode;
- if(logging_mode == 2)
+ if(logging_mode == DLT_LOG_TO_FILE)
{
/* internal logging to file */
logging_handle = fopen(logging_filename,"w");
void dlt_log_free(void)
{
- if(logging_mode == 2) {
+ if(logging_mode == DLT_LOG_TO_FILE) {
fclose(logging_handle);
}
}
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);
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;
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);
+ }
+ }
+
+
+}