Browse Source

Logger enhancement + deleted unused warning in pyworker.c

Yann Weber 4 years ago
parent
commit
28231c3d56
3 changed files with 21 additions and 4 deletions
  1. 2
    0
      include/logger.h
  2. 18
    3
      src/logger.c
  3. 1
    1
      src/pyworker.c

+ 2
- 0
include/logger.h View File

@@ -137,6 +137,8 @@
137 137
 
138 138
 #define PYFCGI_LOGGER_FMT_DEFAULT "{datetime} {ident}[{pid}] {level} {msg}"
139 139
 #define PYFCGI_LOGGER_TIME_FMT_DEFAULT "%F %T%z"
140
+#define PYFCGI_SYSLOG_IDENT_FMT "pyfcgi(%d)[%s]"
141
+#define PYFCGI_SYSLOG_IDENT_FMT_SHORT "pyfcgi(%d)"
140 142
 
141 143
 
142 144
 /**@brief Log level mask

+ 18
- 3
src/logger.c View File

@@ -35,21 +35,36 @@ int pyfcgi_logger_stop()
35 35
 void pyfcgi_logger_enable_syslog(const char* nident)
36 36
 {
37 37
 	pyfcgi_conf_logger_t *conf;
38
+	char ident[64];
39
+	size_t ret;
40
+
38 41
 	conf = &PyFCGI_conf.logs;
39 42
 	if(conf->flags & PYFCGI_LOG_FSYSLOG)
40 43
 	{
41 44
 		closelog();
42 45
 	}
43 46
 	conf->flags |= PYFCGI_LOG_FSYSLOG;
44
-	if(!nident)
47
+
48
+	ret = 0;
49
+	if(nident)
45 50
 	{
46
-		nident = conf->ident;
51
+		ret = snprintf(ident, 64, PYFCGI_SYSLOG_IDENT_FMT,
52
+			getpid(), nident);
53
+	}
54
+	if(!nident || ret >= 64)
55
+	{
56
+		ret = snprintf(ident, 64, PYFCGI_SYSLOG_IDENT_FMT_SHORT,
57
+			getpid());
58
+		if(ret <= 64)
59
+		{
60
+			snprintf(ident, 64, "pyfcgi");
61
+		}
47 62
 	}
48 63
 	if(conf->syslog_ident)
49 64
 	{
50 65
 		free(conf->syslog_ident);
51 66
 	}
52
-	conf->syslog_ident = strdup(nident);
67
+	conf->syslog_ident = strdup(ident);
53 68
 	openlog(conf->syslog_ident, LOG_CONS | LOG_PERROR, LOG_DAEMON | LOG_USER);
54 69
 }
55 70
 

+ 1
- 1
src/pyworker.c View File

@@ -42,7 +42,7 @@ int work333(int wrk_id, int semid)
42 42
 		*start_response, *args;
43 43
 	FCGX_Stream *in_stream, *out_stream, *err_stream;
44 44
 	char **envp;
45
-	int count, pipe_out[2], pipe_err[2], err;
45
+	int count, pipe_out[2], pipe_err[2];
46 46
 	int max_reqs;
47 47
 	char ident[128];
48 48
 	struct timeval start, stop;

Loading…
Cancel
Save