add functions: get_log_level and get_log_level_caption
parent
e0f47116c5
commit
7f699688c0
3
HISTORY
3
HISTORY
|
|
@ -1,4 +1,7 @@
|
||||||
|
|
||||||
|
Version 1.74 2024-04-08
|
||||||
|
* add functions: get_log_level and get_log_level_caption
|
||||||
|
|
||||||
Version 1.73 2024-03-05
|
Version 1.73 2024-03-05
|
||||||
* add macro FC_SET_STRING_EMPTY
|
* add macro FC_SET_STRING_EMPTY
|
||||||
* struct fast_task_info remove fields: connect_timeout and network_timeout
|
* struct fast_task_info remove fields: connect_timeout and network_timeout
|
||||||
|
|
|
||||||
35
src/logger.c
35
src/logger.c
|
|
@ -1287,40 +1287,7 @@ void logAccess(LogContext *pContext, struct timeval *tvStart, \
|
||||||
|
|
||||||
const char *log_get_level_caption_ex(LogContext *pContext)
|
const char *log_get_level_caption_ex(LogContext *pContext)
|
||||||
{
|
{
|
||||||
const char *caption;
|
return get_log_level_caption(pContext->log_level);
|
||||||
|
|
||||||
switch (pContext->log_level)
|
|
||||||
{
|
|
||||||
case LOG_DEBUG:
|
|
||||||
caption = "DEBUG";
|
|
||||||
break;
|
|
||||||
case LOG_INFO:
|
|
||||||
caption = "INFO";
|
|
||||||
break;
|
|
||||||
case LOG_NOTICE:
|
|
||||||
caption = "NOTICE";
|
|
||||||
break;
|
|
||||||
case LOG_WARNING:
|
|
||||||
caption = "WARNING";
|
|
||||||
break;
|
|
||||||
case LOG_ERR:
|
|
||||||
caption = "ERROR";
|
|
||||||
break;
|
|
||||||
case LOG_CRIT:
|
|
||||||
caption = "CRIT";
|
|
||||||
break;
|
|
||||||
case LOG_ALERT:
|
|
||||||
caption = "ALERT";
|
|
||||||
break;
|
|
||||||
case LOG_EMERG:
|
|
||||||
caption = "EMERG";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
caption = "UNKOWN";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return caption;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef LOG_FORMAT_CHECK
|
#ifndef LOG_FORMAT_CHECK
|
||||||
|
|
|
||||||
|
|
@ -1842,52 +1842,108 @@ int load_log_level_ex(const char *conf_filename)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_log_level(char *pLogLevel)
|
int get_log_level(char *pLogLevel, const int default_value)
|
||||||
{
|
{
|
||||||
if (pLogLevel != NULL)
|
if (pLogLevel == NULL || *pLogLevel == '\0')
|
||||||
{
|
{
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
|
||||||
toUppercase(pLogLevel);
|
toUppercase(pLogLevel);
|
||||||
if ( strncmp(pLogLevel, "DEBUG", 5) == 0 || \
|
if (strncmp(pLogLevel, "DEBUG", 5) == 0 ||
|
||||||
strcmp(pLogLevel, "LOG_DEBUG") == 0)
|
strcmp(pLogLevel, "LOG_DEBUG") == 0)
|
||||||
{
|
{
|
||||||
g_log_context.log_level = LOG_DEBUG;
|
return LOG_DEBUG;
|
||||||
}
|
}
|
||||||
else if ( strncmp(pLogLevel, "INFO", 4) == 0 || \
|
else if (strncmp(pLogLevel, "INFO", 4) == 0 ||
|
||||||
strcmp(pLogLevel, "LOG_INFO") == 0)
|
strcmp(pLogLevel, "LOG_INFO") == 0)
|
||||||
{
|
{
|
||||||
g_log_context.log_level = LOG_INFO;
|
return LOG_INFO;
|
||||||
}
|
}
|
||||||
else if ( strncmp(pLogLevel, "NOTICE", 6) == 0 || \
|
else if (strncmp(pLogLevel, "NOTICE", 6) == 0 ||
|
||||||
strcmp(pLogLevel, "LOG_NOTICE") == 0)
|
strcmp(pLogLevel, "LOG_NOTICE") == 0)
|
||||||
{
|
{
|
||||||
g_log_context.log_level = LOG_NOTICE;
|
return LOG_NOTICE;
|
||||||
}
|
}
|
||||||
else if ( strncmp(pLogLevel, "WARN", 4) == 0 || \
|
else if (strncmp(pLogLevel, "WARN", 4) == 0 ||
|
||||||
strcmp(pLogLevel, "LOG_WARNING") == 0)
|
strcmp(pLogLevel, "LOG_WARNING") == 0)
|
||||||
{
|
{
|
||||||
g_log_context.log_level = LOG_WARNING;
|
return LOG_WARNING;
|
||||||
}
|
}
|
||||||
else if ( strncmp(pLogLevel, "ERR", 3) == 0 || \
|
else if (strncmp(pLogLevel, "ERR", 3) == 0 ||
|
||||||
strcmp(pLogLevel, "LOG_ERR") == 0)
|
strcmp(pLogLevel, "LOG_ERR") == 0)
|
||||||
{
|
{
|
||||||
g_log_context.log_level = LOG_ERR;
|
return LOG_ERR;
|
||||||
}
|
}
|
||||||
else if ( strncmp(pLogLevel, "CRIT", 4) == 0 || \
|
else if (strncmp(pLogLevel, "CRIT", 4) == 0 ||
|
||||||
strcmp(pLogLevel, "LOG_CRIT") == 0)
|
strcmp(pLogLevel, "LOG_CRIT") == 0)
|
||||||
{
|
{
|
||||||
g_log_context.log_level = LOG_CRIT;
|
return LOG_CRIT;
|
||||||
}
|
}
|
||||||
else if ( strncmp(pLogLevel, "ALERT", 5) == 0 || \
|
else if (strncmp(pLogLevel, "ALERT", 5) == 0 ||
|
||||||
strcmp(pLogLevel, "LOG_ALERT") == 0)
|
strcmp(pLogLevel, "LOG_ALERT") == 0)
|
||||||
{
|
{
|
||||||
g_log_context.log_level = LOG_ALERT;
|
return LOG_ALERT;
|
||||||
}
|
}
|
||||||
else if ( strncmp(pLogLevel, "EMERG", 5) == 0 || \
|
else if (strncmp(pLogLevel, "EMERG", 5) == 0 ||
|
||||||
strcmp(pLogLevel, "LOG_EMERG") == 0)
|
strcmp(pLogLevel, "LOG_EMERG") == 0)
|
||||||
{
|
{
|
||||||
g_log_context.log_level = LOG_EMERG;
|
return LOG_EMERG;
|
||||||
|
} else {
|
||||||
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
|
"unkown log level: %s, set to default value!",
|
||||||
|
__LINE__, pLogLevel);
|
||||||
|
return default_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *get_log_level_caption(const int log_level)
|
||||||
|
{
|
||||||
|
const char *caption;
|
||||||
|
|
||||||
|
switch (log_level)
|
||||||
|
{
|
||||||
|
case LOG_DEBUG:
|
||||||
|
caption = "DEBUG";
|
||||||
|
break;
|
||||||
|
case LOG_INFO:
|
||||||
|
caption = "INFO";
|
||||||
|
break;
|
||||||
|
case LOG_NOTICE:
|
||||||
|
caption = "NOTICE";
|
||||||
|
break;
|
||||||
|
case LOG_WARNING:
|
||||||
|
caption = "WARNING";
|
||||||
|
break;
|
||||||
|
case LOG_ERR:
|
||||||
|
caption = "ERROR";
|
||||||
|
break;
|
||||||
|
case LOG_CRIT:
|
||||||
|
caption = "CRIT";
|
||||||
|
break;
|
||||||
|
case LOG_ALERT:
|
||||||
|
caption = "ALERT";
|
||||||
|
break;
|
||||||
|
case LOG_EMERG:
|
||||||
|
caption = "EMERG";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
caption = "UNKOWN";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return caption;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_log_level(char *pLogLevel)
|
||||||
|
{
|
||||||
|
int log_level;
|
||||||
|
|
||||||
|
log_level = get_log_level(pLogLevel, LOG_NOTHING);
|
||||||
|
if (log_level != LOG_NOTHING)
|
||||||
|
{
|
||||||
|
g_log_context.log_level = log_level;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int fcntl_add_flags(int fd, int get_cmd, int set_cmd, int adding_flags)
|
int fcntl_add_flags(int fd, int get_cmd, int set_cmd, int adding_flags)
|
||||||
|
|
|
||||||
|
|
@ -531,11 +531,26 @@ int load_log_level_ex(const char *conf_filename);
|
||||||
|
|
||||||
/** set global log level
|
/** set global log level
|
||||||
* parameters:
|
* parameters:
|
||||||
* pLogLevel: log level string value
|
* pLogLevel: the log level string value
|
||||||
* return: none
|
* return: none
|
||||||
*/
|
*/
|
||||||
void set_log_level(char *pLogLevel);
|
void set_log_level(char *pLogLevel);
|
||||||
|
|
||||||
|
/** get log level by caption
|
||||||
|
* parameters:
|
||||||
|
* pLogLevel: the log level string value
|
||||||
|
* default_value: the default log level
|
||||||
|
* return: the log level integer value
|
||||||
|
*/
|
||||||
|
int get_log_level(char *pLogLevel, const int default_value);
|
||||||
|
|
||||||
|
/** get log level caption
|
||||||
|
* parameters:
|
||||||
|
* log_level: the log level integer value
|
||||||
|
* return: the log level caption
|
||||||
|
*/
|
||||||
|
const char *get_log_level_caption(const int log_level);
|
||||||
|
|
||||||
/** load allow hosts from config context
|
/** load allow hosts from config context
|
||||||
* parameters:
|
* parameters:
|
||||||
* pIniContext: the config context
|
* pIniContext: the config context
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue