| 1 |
/* |
| 2 |
* Copyright (C) 2016 Jan Pokorny <[email protected]> |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU General Public |
| 6 |
* License as published by the Free Software Foundation; either |
| 7 |
* version 2 of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This software is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License along |
| 15 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 16 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <stdint.h> |
| 20 |
#include <stdlib.h> |
| 21 |
|
| 22 |
#include <qb/qblog.h> |
| 23 |
|
| 24 |
#include "logging_libqb.h" |
| 25 |
|
| 26 |
int debug_level = 0; |
| 27 |
|
| 28 |
/* ENV_X definitions based on glue/lib/clplumbing/cl_log.c of glue project: |
| 29 |
http://hg.linux-ha.org/glue */ |
| 30 |
#define ENV_HADEBUGVAL "HA_debug" |
| 31 |
#define ENV_LOGFENV "HA_logfile" /* well-formed log file :-) */ |
| 32 |
#define ENV_DEBUGFENV "HA_debugfile" /* Debug log file */ |
| 33 |
#define ENV_LOGFACILITY "HA_logfacility"/* Facility to use for logger */ |
| 34 |
#define ENV_SYSLOGFMT "HA_syslogmsgfmt"/* TRUE if we should use syslog message formatting */ |
| 35 |
|
| 36 |
void |
| 37 |
alt_qb_inherit_logging_environment(void) |
| 38 |
{ |
| 39 |
char *inherit_env; |
| 40 |
|
| 41 |
/* Don't need to free the return pointer from getenv */ |
| 42 |
inherit_env = getenv(ENV_HADEBUGVAL); |
| 43 |
if (inherit_env != NULL && atoi(inherit_env) != 0 ) |
| 44 |
debug_level = atoi(inherit_env); |
| 45 |
|
| 46 |
inherit_env = getenv(ENV_LOGFENV); |
| 47 |
if (inherit_env != NULL && *inherit_env != '\0') { |
| 48 |
int32_t log_fd = qb_log_file_open(inherit_env); |
| 49 |
qb_log_ctl(log_fd, QB_LOG_CONF_ENABLED, QB_TRUE); |
| 50 |
/* do not log debug info even if debug_level non-zero */ |
| 51 |
qb_log_filter_ctl(log_fd, QB_LOG_FILTER_ADD, |
| 52 |
QB_LOG_FILTER_FILE, "*", LOG_INFO); |
| 53 |
} |
| 54 |
|
| 55 |
inherit_env = getenv(ENV_DEBUGFENV); |
| 56 |
if (inherit_env != NULL && *inherit_env != '\0') { |
| 57 |
int32_t log_fd = qb_log_file_open(inherit_env); |
| 58 |
qb_log_ctl(log_fd, QB_LOG_CONF_ENABLED, QB_TRUE); |
| 59 |
} |
| 60 |
|
| 61 |
inherit_env = getenv(ENV_LOGFACILITY); |
| 62 |
if (inherit_env != NULL && *inherit_env != '\0') { |
| 63 |
int fac = qb_log_facility2int(inherit_env); |
| 64 |
if (fac > 0) |
| 65 |
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_FACILITY, fac); |
| 66 |
else |
| 67 |
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE); |
| 68 |
} |
| 69 |
|
| 70 |
inherit_env = getenv(ENV_SYSLOGFMT); |
| 71 |
if (inherit_env != NULL && *inherit_env != '\0' |
| 72 |
&& ( !strcasecmp(inherit_env, "false") |
| 73 |
|| !strcasecmp(inherit_env, "off") |
| 74 |
|| !strcasecmp(inherit_env, "no") |
| 75 |
|| !strcasecmp(inherit_env, "n") |
| 76 |
|| !strcasecmp(inherit_env, "0"))){ |
| 77 |
enum qb_log_target_slot i; |
| 78 |
for (i = QB_LOG_TARGET_START; i < QB_LOG_TARGET_MAX; i++) { |
| 79 |
if (i == QB_LOG_SYSLOG || i == QB_LOG_BLACKBOX) |
| 80 |
continue; |
| 81 |
qb_log_format_set(i, NULL); |
| 82 |
} |
| 83 |
} |
| 84 |
} |