Commit 8c9ef674 authored by Maciej Lipinski's avatar Maciej Lipinski

[issue #194] add facility to wrs_msg and <facility*8+priority> to output msgs

Logger can interpret get log facility & level (error, info, etc) from
log message if such info is provided properly. I.e. it needs to be
enclosed in <> and the first thing in the message. The wrs-msg.c file
in the libwr was changed such that the log facility & level ares properly
printed in log messages, and thus later properly interpreted by the syslog
elastic search on the server. For this, wrs_msg lib needs to know the
faciltiy of the application that uses it. Thus, the wrs_msg_init()
function was updated (in the library and all its calls in applications)
parent 24ea4b97
...@@ -28,7 +28,7 @@ extern void wrs_msg_filename(char *name); ...@@ -28,7 +28,7 @@ extern void wrs_msg_filename(char *name);
extern int wrs_msg_level; /* user can set it in main() or whatever */ extern int wrs_msg_level; /* user can set it in main() or whatever */
/* Optional: prepare all defaults. Like argv[0] to be prefixed, signals... */ /* Optional: prepare all defaults. Like argv[0] to be prefixed, signals... */
extern void wrs_msg_init(int argc, char **argv); extern void wrs_msg_init(int argc, char **argv, int facility);
#ifdef DEBUG /* We had it, so let's keep this build-time thing */ #ifdef DEBUG /* We had it, so let's keep this build-time thing */
# define WRS_MSG_DEFAULT_LEVEL LOG_DEBUG # define WRS_MSG_DEFAULT_LEVEL LOG_DEBUG
...@@ -36,6 +36,8 @@ extern void wrs_msg_init(int argc, char **argv); ...@@ -36,6 +36,8 @@ extern void wrs_msg_init(int argc, char **argv);
# define WRS_MSG_DEFAULT_LEVEL LOG_INFO # define WRS_MSG_DEFAULT_LEVEL LOG_INFO
#endif #endif
#define WRS_MSG_DEFAULT_FACILITY LOG_USER /* User facility by default */
#define WRS_MSG_DETAILS_AT LOG_DEBUG /* >= for debug use __LINE__ */ #define WRS_MSG_DETAILS_AT LOG_DEBUG /* >= for debug use __LINE__ */
/* This is the external function for it all */ /* This is the external function for it all */
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#endif #endif
int wrs_msg_level = WRS_MSG_DEFAULT_LEVEL; int wrs_msg_level = WRS_MSG_DEFAULT_LEVEL;
int wrs_msg_facility = WRS_MSG_DEFAULT_FACILITY;
/* We use debug, info, warning, error and "silent" */ /* We use debug, info, warning, error and "silent" */
static int wrs_msg_used_levels[] = { static int wrs_msg_used_levels[] = {
...@@ -40,7 +41,7 @@ static FILE *wrs_msg_f = (FILE *)-1; /* Means "not yet set" */ ...@@ -40,7 +41,7 @@ static FILE *wrs_msg_f = (FILE *)-1; /* Means "not yet set" */
static char *prgname; /* always print argv[0], or we get lost */ static char *prgname; /* always print argv[0], or we get lost */
/* This function is optional, up to the user whether to call it or not */ /* This function is optional, up to the user whether to call it or not */
void wrs_msg_init(int argc, char **argv) void wrs_msg_init(int argc, char **argv, int facility)
{ {
int i; int i;
int max = ARRAY_SIZE(wrs_msg_used_levels) - 1; int max = ARRAY_SIZE(wrs_msg_used_levels) - 1;
...@@ -116,6 +117,7 @@ void wrs_msg_init(int argc, char **argv) ...@@ -116,6 +117,7 @@ void wrs_msg_init(int argc, char **argv)
} }
wrs_msg_level = wrs_msg_used_levels[wrs_msg_pos]; wrs_msg_level = wrs_msg_used_levels[wrs_msg_pos];
wrs_msg_facility = facility;
/* Prepare for run-time changes */ /* Prepare for run-time changes */
signal(SIGUSR1, wrs_msg_sighandler); signal(SIGUSR1, wrs_msg_sighandler);
...@@ -139,11 +141,11 @@ void __wrs_msg(int level, const char *func, int line, const char *fmt, ...) ...@@ -139,11 +141,11 @@ void __wrs_msg(int level, const char *func, int line, const char *fmt, ...)
{ {
va_list args; va_list args;
static char *header_string[] = { static char *header_string[] = {
[LOG_ALERT] = "", [LOG_ALERT] = "Alert ",
[LOG_ERR] = "Error: ", [LOG_ERR] = "Error ",
[LOG_WARNING] = "Warning: ", [LOG_WARNING] = "Warning",
[LOG_INFO] = "", [LOG_INFO] = "Info ",
[LOG_DEBUG] = "" [LOG_DEBUG] = "Debug "
}; };
/* If the user didn't set the file, nor init, enforce default now */ /* If the user didn't set the file, nor init, enforce default now */
...@@ -158,7 +160,8 @@ void __wrs_msg(int level, const char *func, int line, const char *fmt, ...) ...@@ -158,7 +160,8 @@ void __wrs_msg(int level, const char *func, int line, const char *fmt, ...)
asprintf(&prgname, "<pid-%i>", getpid()); asprintf(&prgname, "<pid-%i>", getpid());
/* Program name and header, and possibly function and line too */ /* Program name and header, and possibly function and line too */
fprintf(wrs_msg_f, "%s: %s", prgname, header_string[level]); fprintf(wrs_msg_f, "<%d>%s (%s):", (wrs_msg_facility | level),
header_string[level], prgname);
if (level >= WRS_MSG_DETAILS_AT) if (level >= WRS_MSG_DETAILS_AT)
fprintf(wrs_msg_f, "%s:%i: ", func, line); fprintf(wrs_msg_f, "%s:%i: ", func, line);
......
...@@ -1137,7 +1137,7 @@ int main(int argc, char *argv[]) ...@@ -1137,7 +1137,7 @@ int main(int argc, char *argv[])
/* try a pps_gen based approach */ /* try a pps_gen based approach */
uint64_t last_seconds = 0; uint64_t last_seconds = 0;
wrs_msg_init(argc, argv); wrs_msg_init(argc, argv, LOG_USER);
while ((opt = getopt(argc, argv, "himsoetabwqvH:")) != -1) { while ((opt = getopt(argc, argv, "himsoetabwqvH:")) != -1) {
switch(opt) switch(opt)
......
...@@ -591,7 +591,7 @@ int main(int argc, char **argv) ...@@ -591,7 +591,7 @@ int main(int argc, char **argv)
int i; int i;
int ep; int ep;
wrs_msg_init(1, argv); /* only use argv[0]: no cmdline */ wrs_msg_init(1, argv, LOG_USER); /* only use argv[0]: no cmdline */
if(argc<3) if(argc<3)
{ {
......
...@@ -12,7 +12,7 @@ int main(int argc, char **argv) ...@@ -12,7 +12,7 @@ int main(int argc, char **argv)
{ {
int err, verbose = 0; int err, verbose = 0;
wrs_msg_init(argc, argv); wrs_msg_init(argc, argv, LOG_USER);
me_lazy: me_lazy:
if (argc < 2 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { if (argc < 2 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
......
...@@ -266,7 +266,7 @@ int main(int argc, char *argv[]) ...@@ -266,7 +266,7 @@ int main(int argc, char *argv[])
{ {
int ret; int ret;
wrs_msg_init(argc,argv); wrs_msg_init(argc,argv, LOG_DAEMON);
prgName=argv[0]; prgName=argv[0];
......
...@@ -303,7 +303,7 @@ int main(int argc, char **argv) ...@@ -303,7 +303,7 @@ int main(int argc, char **argv)
struct shw_sfp_dom hal_sfp_raw_dom_lc[HAL_MAX_PORTS]; struct shw_sfp_dom hal_sfp_raw_dom_lc[HAL_MAX_PORTS];
wrs_msg_init(argc, argv); wrs_msg_init(argc, argv, LOG_USER);
nports = 18; nports = 18;
dump_port = 1; dump_port = 1;
......
...@@ -55,7 +55,7 @@ int main(int argc, char **argv) ...@@ -55,7 +55,7 @@ int main(int argc, char **argv)
int opt; int opt;
/* argc forced to 1: -q and -v are not "quiet" and "verbose" */ /* argc forced to 1: -q and -v are not "quiet" and "verbose" */
wrs_msg_init(argc, argv); wrs_msg_init(argc, argv, LOG_USER);
assert_init(shw_pio_mmap_init()); assert_init(shw_pio_mmap_init());
shw_io_init(); shw_io_init();
......
...@@ -115,7 +115,7 @@ int main(int argc, char *argv[]) ...@@ -115,7 +115,7 @@ int main(int argc, char *argv[])
prgname = argv[0]; prgname = argv[0];
wrs_msg_init(argc, argv); wrs_msg_init(argc, argv, LOG_USER);
if (shw_fpga_mmap_init() < 0) { if (shw_fpga_mmap_init() < 0) {
pr_error("%s: Can't access device memory\n", prgname); pr_error("%s: Can't access device memory\n", prgname);
......
...@@ -208,7 +208,7 @@ int main(int argc, char **argv) ...@@ -208,7 +208,7 @@ int main(int argc, char **argv)
char func='a'; char func='a';
/* argc forced to 1: -t and -v are not "terse" and "verbose" */ /* argc forced to 1: -t and -v are not "terse" and "verbose" */
wrs_msg_init(1, argv); wrs_msg_init(1, argv, LOG_USER);
if(argc>=2 && argv[1][0]=='-') if(argc>=2 && argv[1][0]=='-')
{ {
......
...@@ -161,7 +161,7 @@ int main(int argc, char *argv[]) ...@@ -161,7 +161,7 @@ int main(int argc, char *argv[])
char *prgname; char *prgname;
wrs_msg_level = LOG_WARNING; wrs_msg_level = LOG_WARNING;
wrs_msg_init(argc, argv); wrs_msg_init(argc, argv, LOG_USER);
prgname = argv[0]; prgname = argv[0];
if (NPORTS > 8 * sizeof(portmask)) { if (NPORTS > 8 * sizeof(portmask)) {
......
...@@ -275,7 +275,7 @@ int main(int argc, char *argv[]) ...@@ -275,7 +275,7 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
wrs_msg_init(argc, argv); wrs_msg_init(argc, argv, LOG_DAEMON);
if (shw_fpga_mmap_init() < 0) { if (shw_fpga_mmap_init() < 0) {
pr_error("%s: Can't access device memory\n", prgname); pr_error("%s: Can't access device memory\n", prgname);
......
...@@ -229,7 +229,7 @@ int main(int argc, char *argv[]) ...@@ -229,7 +229,7 @@ int main(int argc, char *argv[])
static timeout_t update_fan_tmo; static timeout_t update_fan_tmo;
static timeout_t update_all_tmo; static timeout_t update_all_tmo;
wrs_msg_init(argc, argv); wrs_msg_init(argc, argv, LOG_DAEMON);
/* Print HAL's version */ /* Print HAL's version */
pr_info("wrsw_hal. Commit %s, built on " __DATE__ "\n", __GIT_VER__); pr_info("wrsw_hal. Commit %s, built on " __DATE__ "\n", __GIT_VER__);
......
...@@ -375,7 +375,7 @@ int main(int argc, char **argv) ...@@ -375,7 +375,7 @@ int main(int argc, char **argv)
unsigned long aging_res = DEFAULT_AGING_RES; // Aging resolution [sec.] unsigned long aging_res = DEFAULT_AGING_RES; // Aging resolution [sec.]
unsigned long aging_time = DEFAULT_AGING_TIME; // Aging time [sec.] unsigned long aging_time = DEFAULT_AGING_TIME; // Aging time [sec.]
wrs_msg_init(argc, argv); wrs_msg_init(argc, argv, LOG_DAEMON);
/* Print RTUd's version */ /* Print RTUd's version */
pr_info("wrsw_rtud. Commit %s, built on " __DATE__ "\n", __GIT_VER__); pr_info("wrsw_rtud. Commit %s, built on " __DATE__ "\n", __GIT_VER__);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment