Bugfix on logger with ident field etc
This commit is contained in:
parent
1d4a84b8c7
commit
d2e7517348
3 changed files with 36 additions and 12 deletions
|
|
@ -63,8 +63,8 @@
|
|||
#define PYFCGI_LOG_DTM_LEN 25
|
||||
#define PYFCGI_LOG_LVL_LEN 7
|
||||
#define PYFCGI_LOG_TYP_LEN 7
|
||||
#define PYFCGI_LOG_PID_LEN 4
|
||||
#define PYFCGI_LOG_PID_FMT "%04d"
|
||||
#define PYFCGI_LOG_PID_LEN 6
|
||||
#define PYFCGI_LOG_PID_FMT "%6d"
|
||||
|
||||
#define SYSLOG_syslog syslog
|
||||
#define SYSLOG_vsyslog vsyslog
|
||||
|
|
@ -98,7 +98,7 @@
|
|||
#define LOG_DEBUG (8 << 4)
|
||||
|
||||
/**@brief Convert a PyFCGI loglevel in a syslog one */
|
||||
#define PYFCGI_SYSLOG_LVL(lvl) (SYSLOG_LVLS[(lvl & 0xF0) >> 4])
|
||||
#define PYFCGI_SYSLOG_LVL(lvl) (((lvl & 0xF0) >> 4)-1)
|
||||
|
||||
/**@brief Macro checking if syslog is activated and log a message
|
||||
* @params int lvl the PyFCGI log level
|
||||
|
|
@ -125,13 +125,15 @@
|
|||
/**@ingroup cong_logger_flags */
|
||||
#define PYFCGI_LOG_FSYSLOG 1
|
||||
/**@brief Indicate if the logger should try to reopen on failure
|
||||
* @warn not implemented
|
||||
* @ingroup cong_logger_flags */
|
||||
#define PYFCGI_LOG_FRETRY 2
|
||||
/**@brief Exit if failure
|
||||
* @warn not implemented
|
||||
* @ingroup cong_logger_flags */
|
||||
#define PYFCGI_LOG_FEXIT_ONFAIL 4
|
||||
|
||||
#define PYFCGI_LOGGER_FMT_DEFAULT "{datetime} {ident} {level}({pid}) {msg}"
|
||||
#define PYFCGI_LOGGER_FMT_DEFAULT "{datetime} {ident}[{pid}] {level} {msg}"
|
||||
#define PYFCGI_LOGGER_TIME_FMT_DEFAULT "%F %T%z"
|
||||
|
||||
|
||||
|
|
@ -151,9 +153,7 @@ typedef struct ident_args_s ident_args_t;
|
|||
typedef union pyfcgi_logger_field_args pyfcgi_logger_field_args_u;
|
||||
|
||||
|
||||
static const short SYSLOG_LVLS[8] = {LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,
|
||||
LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG};
|
||||
static const char* PYFCGI_LOGGER_LVLNAME[] = {
|
||||
static const char* PYFCGI_LOGGER_LVLNAME[] __attribute__((unused)) = {
|
||||
" Emerge",
|
||||
" Alert",
|
||||
" Critic",
|
||||
|
|
@ -163,8 +163,8 @@ static const char* PYFCGI_LOGGER_LVLNAME[] = {
|
|||
" Info",
|
||||
" Debug"};
|
||||
|
||||
static const char* PYFCGI_LOGGER_TYPNAME[] = {"Global", "Access", "Internal",
|
||||
"Worker", "Master"};
|
||||
static const char* PYFCGI_LOGGER_TYPNAME[] __attribute__((unused)) =
|
||||
{"Global", "Access", "Internal", "Worker", "Master"} ;
|
||||
|
||||
|
||||
/**@defgroup conf_logger_format Logline format
|
||||
|
|
@ -321,6 +321,11 @@ int pyfcgi_logger_init();
|
|||
*/
|
||||
int pyfcgi_logger_stop();
|
||||
|
||||
/**@brief Enable syslog logging with given ident
|
||||
* @param char* ident if NULL use current ident
|
||||
*/
|
||||
void pyfcgi_logger_enable_syslog(char*);
|
||||
|
||||
/**@brief Stop & free an individual logger */
|
||||
void _pyfcgi_logger_free(pyfcgi_logger_t*);
|
||||
|
||||
|
|
|
|||
23
src/logger.c
23
src/logger.c
|
|
@ -32,6 +32,22 @@ int pyfcgi_logger_stop()
|
|||
return 0;
|
||||
}
|
||||
|
||||
void pyfcgi_logger_enable_syslog(char* nident)
|
||||
{
|
||||
pyfcgi_conf_logger_t *conf;
|
||||
conf = &PyFCGI_conf.logs;
|
||||
if(conf->flags & PYFCGI_LOG_FSYSLOG)
|
||||
{
|
||||
closelog();
|
||||
}
|
||||
conf->flags |= PYFCGI_LOG_FSYSLOG;
|
||||
if(!nident)
|
||||
{
|
||||
nident = conf->ident;
|
||||
}
|
||||
openlog(nident, LOG_CONS | LOG_PERROR, LOG_DAEMON | LOG_USER);
|
||||
}
|
||||
|
||||
void _pyfcgi_logger_free(pyfcgi_logger_t *logger)
|
||||
{
|
||||
free(logger->filename);
|
||||
|
|
@ -264,10 +280,13 @@ int pyfcgi_logger_format_bufinit(pyfcgi_logger_format_t* fmt)
|
|||
{
|
||||
|
||||
case pyfcgi_logger_field_const:
|
||||
case pyfcgi_logger_field_ident:
|
||||
memcpy(cur, fmt->fields[i].val,
|
||||
fmt->fields[i].len);
|
||||
break;
|
||||
case pyfcgi_logger_field_ident:
|
||||
memcpy(cur, *((char**)fmt->fields[i].val),
|
||||
fmt->fields[i].len);
|
||||
break;
|
||||
case pyfcgi_logger_field_pid:
|
||||
snprintf(pid, PYFCGI_LOG_PID_LEN+1,
|
||||
PYFCGI_LOG_PID_FMT,
|
||||
|
|
@ -540,7 +559,7 @@ int pyfcgi_logger_set_ident(const char* new_ident)
|
|||
if(field->type == pyfcgi_logger_field_ident)
|
||||
{
|
||||
field->len = len;
|
||||
upd = 0;
|
||||
upd = 1;
|
||||
}
|
||||
}
|
||||
if(upd)
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ START_TEST(test_logger_add)
|
|||
{
|
||||
char tmplog[128];
|
||||
char logfmt[] = "{level} {ident} {pid} {msg}";
|
||||
char expected[] = " Alert 0000 Hello world ! foobar 04\n";
|
||||
char expected[] = " Alert 0 Hello world ! foobar 04\n";
|
||||
int ret;
|
||||
pyfcgi_conf_logger_t *conf;
|
||||
pyfcgi_logger_t *logger;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue