Commit 7f7077f5566e11ee5ac98818d190c4a119ea9a17
1 parent
f54c89ab
Exists in
master
and in
3 other branches
Adding option to use syslog (when available).
Showing
8 changed files
with
82 additions
and
0 deletions
Show diff stats
configure.ac
... | ... | @@ -463,6 +463,7 @@ dnl Check for headers |
463 | 463 | dnl --------------------------------------------------------------------------- |
464 | 464 | |
465 | 465 | AC_CHECK_HEADER(malloc.h, AC_DEFINE(HAVE_MALLOC_H,,[do we have malloc.h?])) |
466 | +AC_CHECK_HEADER(syslog.h, AC_DEFINE(HAVE_SYSLOG,,[do we have malloc.h?])) | |
466 | 467 | |
467 | 468 | AC_CHECK_FUNCS(getaddrinfo, AC_DEFINE(HAVE_GETADDRINFO) ) |
468 | 469 | AC_CHECK_FUNC(vasprintf, AC_DEFINE(HAVE_VASPRINTF) ) | ... | ... |
src/include/config.h.in
src/include/lib3270/log.h
... | ... | @@ -57,6 +57,16 @@ |
57 | 57 | LIB3270_EXPORT int lib3270_write_rc(H3270 *session, const char *module, int rc, const char *fmt, ...) LIB3270_GNUC_FORMAT(4,5); |
58 | 58 | LIB3270_EXPORT void lib3270_write_va_log(H3270 *session, const char *module, const char *fmt, va_list arg); |
59 | 59 | |
60 | + /** | |
61 | + * @brief Send logs to system log (if available) | |
62 | + * | |
63 | + * @param flag Non-zero to use syslog. | |
64 | + * | |
65 | + * @return 0 if ok, non zero if not. | |
66 | + * | |
67 | + */ | |
68 | + LIB3270_EXPORT int lib3270_set_syslog(int flag); | |
69 | + | |
60 | 70 | #ifdef DEBUG |
61 | 71 | #include <stdio.h> |
62 | 72 | #undef trace | ... | ... |
src/lib3270/init.c
... | ... | @@ -54,6 +54,10 @@ |
54 | 54 | #include <lib3270/log.h> |
55 | 55 | #include "private.h" |
56 | 56 | |
57 | +#ifdef HAVE_SYSLOG | |
58 | + #include <syslog.h> | |
59 | +#endif // HAVE_SYSLOG | |
60 | + | |
57 | 61 | #if defined WIN32 |
58 | 62 | BOOL WINAPI DllMain(HANDLE hinst, DWORD dwcallpurpose, LPVOID lpvResvd); |
59 | 63 | #else |
... | ... | @@ -118,6 +122,13 @@ int lib3270_unloaded(void) |
118 | 122 | curl_global_cleanup(); |
119 | 123 | #endif // HAVE_LIBCURL |
120 | 124 | |
125 | +#ifdef HAVE_SYSLOG | |
126 | + if(use_syslog) | |
127 | + { | |
128 | + closelog(); | |
129 | + } | |
130 | +#endif // HAVE_SYSLOG | |
131 | + | |
121 | 132 | return 0; |
122 | 133 | } |
123 | 134 | ... | ... |
src/lib3270/linux/log.c
... | ... | @@ -34,13 +34,59 @@ |
34 | 34 | #include <lib3270.h> |
35 | 35 | #include <lib3270/log.h> |
36 | 36 | |
37 | +#ifdef HAVE_SYSLOG | |
38 | + #include <syslog.h> | |
39 | +#endif // HAVE_SYSLOG | |
40 | + | |
37 | 41 | /*---[ Implementacao ]--------------------------------------------------------------------------------------*/ |
38 | 42 | |
43 | + int use_syslog = 0; | |
44 | + | |
39 | 45 | void default_log_writer(H3270 GNUC_UNUSED(*session), const char *module, int GNUC_UNUSED(rc), const char *fmt, va_list arg_ptr) |
40 | 46 | { |
47 | +#ifdef HAVE_SYSLOG | |
48 | + if(use_syslog) | |
49 | + { | |
50 | + vsyslog(LOG_USER, fmt, arg_ptr); | |
51 | + } | |
52 | + else | |
53 | + { | |
54 | + printf("%s:\t",module); | |
55 | + vprintf(fmt,arg_ptr); | |
56 | + printf("\n"); | |
57 | + fflush(stdout); | |
58 | + } | |
59 | +#else | |
41 | 60 | printf("%s:\t",module); |
42 | 61 | vprintf(fmt,arg_ptr); |
43 | 62 | printf("\n"); |
44 | 63 | fflush(stdout); |
64 | +#endif | |
45 | 65 | } |
46 | 66 | |
67 | + LIB3270_EXPORT int lib3270_set_syslog(int flag) | |
68 | + { | |
69 | +#ifdef HAVE_SYSLOG | |
70 | + if(flag) | |
71 | + { | |
72 | + if(!use_syslog) | |
73 | + { | |
74 | + openlog(LIB3270_STRINGIZE_VALUE_OF(LIB3270_NAME), LOG_NDELAY, LOG_USER); | |
75 | + use_syslog = 1; | |
76 | + } | |
77 | + } | |
78 | + else | |
79 | + { | |
80 | + if(use_syslog) | |
81 | + { | |
82 | + closelog(); | |
83 | + use_syslog = 0; | |
84 | + } | |
85 | + } | |
86 | + | |
87 | + return 0; | |
88 | + | |
89 | +#else | |
90 | + return errno = ENOENT; | |
91 | +#endif // HAVE_SYSLOG | |
92 | + } | ... | ... |
src/lib3270/log.c
... | ... | @@ -41,6 +41,7 @@ |
41 | 41 | #include <config.h> |
42 | 42 | #include <lib3270.h> |
43 | 43 | #include <lib3270/log.h> |
44 | +#include <errno.h> | |
44 | 45 | |
45 | 46 | /*---[ Constants ]------------------------------------------------------------------------------------------*/ |
46 | 47 | |
... | ... | @@ -75,3 +76,4 @@ |
75 | 76 | { |
76 | 77 | loghandler(session,module,0,fmt,arg); |
77 | 78 | } |
79 | + | ... | ... |
src/lib3270/private.h
... | ... | @@ -691,6 +691,12 @@ struct _h3270 |
691 | 691 | LIB3270_INTERNAL HANDLE hEventLog; |
692 | 692 | #endif // _WIN32 |
693 | 693 | |
694 | +#ifdef HAVE_SYSLOG | |
695 | +/// @brief Windows Event Log Handler. | |
696 | +LIB3270_INTERNAL int use_syslog; | |
697 | +#endif // HAVE_SYSLOG | |
698 | + | |
699 | + | |
694 | 700 | /* Library internal calls */ |
695 | 701 | LIB3270_INTERNAL int key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped); |
696 | 702 | LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr); | ... | ... |