Browse Source

Added logger spec parser for CLI args

Yann Weber 4 years ago
parent
commit
686e6ecf2e
3 changed files with 38 additions and 8 deletions
  1. 3
    2
      include/conf.h
  2. 31
    0
      src/conf.c
  3. 4
    6
      src/pyutils.c

+ 3
- 2
include/conf.h View File

@@ -46,7 +46,7 @@
46 46
 
47 47
 #define PYFCGI_NAME "spawn-fcgi [OPTIONS] -- pyfcgi"
48 48
 
49
-#define PYFCGI_SHORT_OPT "Ce:E:w:W:m:l:Svh"
49
+#define PYFCGI_SHORT_OPT "Ce:E:w:W:m:L:Svh"
50 50
 
51 51
 #define PYFCGI_LONG_OPT { \
52 52
 	{"config", required_argument, 0, 'C'},\
@@ -77,7 +77,8 @@
77 77
 	{"Display this help and exit", NULL},\
78 78
 }
79 79
 
80
-#define PYFCGI_HELP_TEXT "Logger specification format 'LOGFILE[;FILT][;FMT]' with :\n\
80
+#define PYFCGI_HELP_TEXT "\n\
81
+Logger specification format 'LOGFILE[;FILT][;FMT]' with :\n\
81 82
 \t- LOGFILE the log file name\n\
82 83
 \t- FILT a number (in decimal or hexadicimal 0xXX) indicating wich\n\
83 84
 \t  facility/level to log\n\

+ 31
- 0
src/conf.c View File

@@ -156,6 +156,37 @@ int check_entrypoint_import()
156 156
 
157 157
 int parse_optlog(const char* logspec)
158 158
 {
159
+	char *filename, *filter, *fmt;
160
+	int filt;
161
+
162
+	filename = strdup(logspec); /**@todo check error */
163
+	filter = filename;
164
+	while(*filter && *filter != ';') { filter++; }
165
+	if(*filter)
166
+	{
167
+		*filter = '\0';
168
+		filter++;
169
+	}
170
+	fmt = filter;
171
+	while(*fmt && *fmt != ';') { fmt++; }
172
+	if(*fmt)
173
+	{
174
+		*fmt = '\0';
175
+		fmt++;
176
+	}
177
+	if(!strlen(filter))
178
+	{
179
+		filt = 0xFF;
180
+	}
181
+	else
182
+	{
183
+		filt = strtol(filter, NULL, !strncmp(filter, "0x", 2)?16:10);
184
+	}
185
+	fmt = strlen(fmt)?fmt:NULL;
186
+	if(pyfcgi_logger_add(filename, filt, filt, fmt))
187
+	{
188
+		return 1;
189
+	}
159 190
 	return 0;
160 191
 }
161 192
 

+ 4
- 6
src/pyutils.c View File

@@ -122,13 +122,10 @@ PyObject* import_entrypoint()
122 122
 	if(!entry_module)
123 123
 	{
124 124
 		//TODO syslog python error / traceback
125
-		pyfcgi_log(	LOG_CRIT,
126
-			"Unable to import python file '%s'",
125
+		pyfcgi_log(LOG_CRIT, "Unable to import python file '%s'",
127 126
 			PyFCGI_conf.py_entrymod);
128
-		pyfcgi_log( LOG_INFO,
129
-			"%s", getcwd(NULL, 256));
127
+		//pyfcgi_log( LOG_INFO, "%s", getcwd(NULL, 256));
130 128
 		log_expt(LOG_ERR);
131
-		sleep(1);
132 129
 		return NULL;
133 130
 	}
134 131
 
@@ -139,9 +136,10 @@ PyObject* import_entrypoint()
139 136
 	if(!entry_fun)
140 137
 	{
141 138
 		//TODO syslog python error / traceback
142
-		pyfcgi_log(	LOG_CRIT,
139
+		pyfcgi_log(LOG_CRIT,
143 140
 			"Unable to import object '%s' from '%s'",
144 141
 			PyFCGI_conf.py_entryfun, PyFCGI_conf.py_entrymod);
142
+		log_expt(LOG_ERR);
145 143
 		return NULL;
146 144
 	}
147 145
 	if(!PyCallable_Check(entry_fun))

Loading…
Cancel
Save