Commit 3e599ae12deafee2d51d9af84bd851c1c5a5b184
1 parent
b7cc91ca
Exists in
master
and in
5 other branches
Incluindo opção que permite o envio de logs para o serviço do sistema quando disponível
Showing
3 changed files
with
70 additions
and
1 deletions
Show diff stats
configure.ac
... | ... | @@ -165,6 +165,7 @@ AC_PATH_TOOL([RPMBUILD], [rpmbuild], [no]) |
165 | 165 | AC_PATH_TOOL([DPKGBUILD], [dpkg-buildpackage], [no]) |
166 | 166 | |
167 | 167 | AC_CHECK_HEADER(libintl.h, AC_DEFINE(HAVE_LIBINTL)) |
168 | +AC_CHECK_HEADER(syslog.h, AC_DEFINE(HAVE_SYSLOG)) | |
168 | 169 | AC_CHECK_LIB(intl, gettext,[INTL_LIBS="-lintl"]) |
169 | 170 | |
170 | 171 | AC_SUBST(INTL_LIBS) | ... | ... |
src/include/lib3270/config.h.in
src/pw3270/main.c
... | ... | @@ -42,6 +42,10 @@ |
42 | 42 | #include "v3270/accessible.h" |
43 | 43 | #include <stdlib.h> |
44 | 44 | |
45 | +#if defined( HAVE_SYSLOG ) | |
46 | + #include <syslog.h> | |
47 | +#endif // HAVE_SYSLOG | |
48 | + | |
45 | 49 | #define ERROR_DOMAIN g_quark_from_static_string(PACKAGE_NAME) |
46 | 50 | |
47 | 51 | /*--[ Statics ]--------------------------------------------------------------------------------------*/ |
... | ... | @@ -55,9 +59,15 @@ |
55 | 59 | #endif // HAVE_GTKMAC |
56 | 60 | |
57 | 61 | #if defined( WIN32 ) |
58 | - static const gchar * appname = PACKAGE_NAME; | |
62 | + static const gchar * appname = PACKAGE_NAME; | |
59 | 63 | #endif // WIN32 |
60 | 64 | |
65 | +#if defined( HAVE_SYSLOG ) | |
66 | + static gboolean log_to_syslog = FALSE; | |
67 | +#endif // HAVE_SYSLOG | |
68 | + | |
69 | + | |
70 | + | |
61 | 71 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
62 | 72 | |
63 | 73 | static int initialize(void) |
... | ... | @@ -182,6 +192,52 @@ static gboolean optcolors(const gchar *option_name, const gchar *value, gpointer |
182 | 192 | return FALSE; |
183 | 193 | } |
184 | 194 | |
195 | +#if defined( HAVE_SYSLOG ) | |
196 | +static void g_syslog(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data) | |
197 | +{ | |
198 | + static const struct _logtype | |
199 | + { | |
200 | + GLogLevelFlags log_level; | |
201 | + int priority; | |
202 | + const gchar * msg; | |
203 | + } logtype[] = | |
204 | + { | |
205 | + { G_LOG_FLAG_RECURSION, LOG_INFO, "recursion" }, | |
206 | + { G_LOG_FLAG_FATAL, LOG_ERR, "fatal error" }, | |
207 | + | |
208 | + /* GLib log levels */ | |
209 | + { G_LOG_LEVEL_ERROR, LOG_ERR, "error" }, | |
210 | + { G_LOG_LEVEL_CRITICAL, LOG_ERR, "critical error" }, | |
211 | + { G_LOG_LEVEL_WARNING, LOG_ERR, "warning" }, | |
212 | + { G_LOG_LEVEL_MESSAGE, LOG_ERR, "message" }, | |
213 | + { G_LOG_LEVEL_INFO, LOG_INFO, "info" }, | |
214 | + { G_LOG_LEVEL_DEBUG, LOG_DEBUG, "debug" }, | |
215 | + }; | |
216 | + | |
217 | + int f; | |
218 | + | |
219 | + for(f=0;f<G_N_ELEMENTS(logtype);f++) | |
220 | + { | |
221 | + if(logtype[f].log_level == log_level) | |
222 | + { | |
223 | + gchar *ptr; | |
224 | + gchar *text = g_strdup_printf("%s: %s %s",logtype[f].msg,log_domain ? log_domain : "",message); | |
225 | + for(ptr = text;*ptr;ptr++) | |
226 | + { | |
227 | + if(*ptr < ' ') | |
228 | + *ptr = ' '; | |
229 | + } | |
230 | + | |
231 | + syslog(logtype[f].priority,"%s",text); | |
232 | + g_free(text); | |
233 | + return; | |
234 | + } | |
235 | + } | |
236 | + | |
237 | + syslog(LOG_INFO,"%s %s",log_domain ? log_domain : "", message); | |
238 | +} | |
239 | +#endif // HAVE_SYSLOG | |
240 | + | |
185 | 241 | int main(int argc, char *argv[]) |
186 | 242 | { |
187 | 243 | static const gchar * session_name = PACKAGE_NAME; |
... | ... | @@ -252,6 +308,9 @@ int main(int argc, char *argv[]) |
252 | 308 | { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL }, |
253 | 309 | { "colors", 'c', 0, G_OPTION_ARG_CALLBACK, optcolors, N_( "Set reported colors (8/16)" ), "16" }, |
254 | 310 | { "systype", 't', 0, G_OPTION_ARG_STRING, &system, N_( "Host system type" ), "S390" }, |
311 | +#if defined( HAVE_SYSLOG ) | |
312 | + { "syslog", 'l', 0, G_OPTION_ARG_NONE, &log_to_syslog, N_( "Send messages to syslog" ), NULL }, | |
313 | +#endif | |
255 | 314 | |
256 | 315 | { NULL } |
257 | 316 | }; |
... | ... | @@ -292,6 +351,14 @@ int main(int argc, char *argv[]) |
292 | 351 | return -1; |
293 | 352 | } |
294 | 353 | |
354 | +#if defined( HAVE_SYSLOG ) | |
355 | + if(log_to_syslog) | |
356 | + { | |
357 | + openlog(g_get_prgname(), LOG_NDELAY|LOG_NDELAY, LOG_USER); | |
358 | + g_log_set_default_handler(g_syslog,NULL); | |
359 | + } | |
360 | +#endif // HAVE_SYSLOG | |
361 | + | |
295 | 362 | } |
296 | 363 | |
297 | 364 | { | ... | ... |