|
Greenbone Vulnerability Management Libraries 22.32.0
|
Implementation of logging methods. More...
#include "logging.h"#include "gvm_sentry.h"#include "logging_domain.h"#include <errno.h>#include <libgen.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <syslog.h>#include <time.h>#include <unistd.h>

Go to the source code of this file.
Macros | |
| #define | SYSLOG_NAMES |
| #define | G_LOG_DOMAIN "libgvm base" |
| GLib log domain. | |
Functions | |
| gchar * | get_time (gchar *time_fmt) |
| Returns time as specified in time_fmt strftime format. | |
| static gint | level_int_from_string (const gchar *level) |
| Return the integer corresponding to a log level string. | |
| static gint | facility_int_from_string (const gchar *facility) |
| Return the integer corresponding to a syslog facility string. | |
| GSList * | load_log_configuration (gchar *config_file) |
| Loads parameters from a config file into a linked list. | |
| void | free_log_configuration (GSList *log_domain_list) |
| Frees all resources loaded by the config loader. | |
| void | gvm_log_silent (const char *log_domain, GLogLevelFlags log_level, const char *message, gpointer gvm_log_config_list) |
| Returns immediately. | |
| static void | gvm_log_lock_init (void) |
| Initialize logger_mutex mutex if it was not done before. | |
| void | gvm_log_lock (void) |
| Try to lock logger_mutex. | |
| void | gvm_log_unlock (void) |
| Unlock logger_mutex. | |
| void | set_log_reference (char *ref) |
| Set the log reference object. | |
| char * | get_log_reference (void) |
| Get the log reference object. | |
| void | free_log_reference (void) |
| Free the log reference object. | |
| void | gvm_log_func (const char *log_domain, GLogLevelFlags log_level, const char *message, gpointer gvm_log_config_list) |
| Creates the formatted string and outputs it to the log destination. | |
| void | log_func_for_gnutls (int level, const char *message) |
| This function logs debug messages from gnutls. | |
| static int | check_log_file (gvm_logging_domain_t *log_domain_entry) |
| Check permissions of log file and log file directory. | |
| void | set_log_tz (const gchar *tz) |
| Set the log timezone. | |
| static int | setup_log_handlers_internal (GSList *gvm_log_config_list, GLogFunc log_func, GLogFunc default_log_func, GLogFunc default_domain_log_func) |
| int | setup_log_handlers (GSList *gvm_log_config_list) |
| Sets up routing of logdomains to log handlers. | |
Variables | |
| static gchar * | log_tz = NULL |
| Timezone to use for logs. | |
| static GMutex * | logger_mutex = NULL |
| static char * | reference = NULL |
Implementation of logging methods.
This file contains all methods needed for logging. To enable logging, methods in this file are called.
The module reuses glib datatypes and api for memory management and logging.
Definition in file logging.c.
|
static |
Check permissions of log file and log file directory.
Do not check permissions if log file is syslog or empty string.
| log_domain_entry | Log domain entry. |
Definition at line 853 of file logging.c.
References gvm_logging_domain_get_log_file().
Referenced by Ensure(), and setup_log_handlers_internal().


|
static |
Return the integer corresponding to a syslog facility string.
| facility | Facility name. |
Definition at line 135 of file logging.c.
Referenced by Ensure(), and gvm_log_func().

| void free_log_configuration | ( | GSList * | log_domain_list | ) |
Frees all resources loaded by the config loader.
| log_domain_list | Head of the link list. |
Definition at line 286 of file logging.c.
References gvm_logging_domain_free().
Referenced by Ensure(), Ensure(), and Ensure().


| void free_log_reference | ( | void | ) |
| char * get_log_reference | ( | void | ) |
| gchar * get_time | ( | gchar * | time_fmt | ) |
Returns time as specified in time_fmt strftime format.
| time_fmt | ptr to the string format to use. The strftime man page documents the conversion specification. An example time_fmt string is "%Y-%m-%d %H:%M:%S". |
Definition at line 57 of file logging.c.
References log_tz.
Referenced by Ensure(), and gvm_log_func().

| void gvm_log_func | ( | const char * | log_domain, |
| GLogLevelFlags | log_level, | ||
| const char * | message, | ||
| gpointer | gvm_log_config_list ) |
Creates the formatted string and outputs it to the log destination.
| log_domain | A string containing the message's log domain. |
| log_level | Flags defining the message's log level. |
| message | A string containing the log message. |
| gvm_log_config_list | A pointer to the configuration linked list. |
Definition at line 428 of file logging.c.
References facility_int_from_string(), get_time(), gvm_log_lock(), gvm_log_unlock(), gvm_logging_domain_get_default_level(), gvm_logging_domain_get_log_channel(), gvm_logging_domain_get_log_domain(), gvm_logging_domain_get_log_file(), gvm_logging_domain_get_prepend_separator(), gvm_logging_domain_get_prepend_string(), gvm_logging_domain_get_prepend_time_format(), gvm_logging_domain_get_syslog_facility(), gvm_logging_domain_get_syslog_ident(), gvm_logging_domain_set_log_channel(), gvm_sentry_log(), and reference.
Referenced by setup_log_handlers().


| void gvm_log_lock | ( | void | ) |
Try to lock logger_mutex.
Definition at line 351 of file logging.c.
References gvm_log_lock_init(), and logger_mutex.
Referenced by gvm_log_func().


|
static |
Initialize logger_mutex mutex if it was not done before.
Definition at line 338 of file logging.c.
References logger_mutex.
Referenced by gvm_log_lock().

| void gvm_log_silent | ( | const char * | log_domain, |
| GLogLevelFlags | log_level, | ||
| const char * | message, | ||
| gpointer | gvm_log_config_list ) |
Returns immediately.
| log_domain | A string containing the message's log domain. |
| log_level | Flags defining the message's log level. |
| message | A string containing the log message. |
| gvm_log_config_list | A pointer to the configuration linked list. |
Definition at line 322 of file logging.c.
| void gvm_log_unlock | ( | void | ) |
Unlock logger_mutex.
Definition at line 363 of file logging.c.
References logger_mutex.
Referenced by gvm_log_func().

|
static |
Return the integer corresponding to a log level string.
| level | Level name or integer. |
Definition at line 104 of file logging.c.
Referenced by Ensure(), and load_log_configuration().

| GSList * load_log_configuration | ( | gchar * | config_file | ) |
Loads parameters from a config file into a linked list.
| config_file | A string containing the path to the configuration file to load. |
Definition at line 161 of file logging.c.
References gvm_logging_domain_new(), gvm_logging_domain_set_default_level(), gvm_logging_domain_set_log_file(), gvm_logging_domain_set_prepend_separator(), gvm_logging_domain_set_prepend_string(), gvm_logging_domain_set_prepend_time_format(), gvm_logging_domain_set_syslog_facility(), gvm_logging_domain_set_syslog_ident(), and level_int_from_string().
Referenced by Ensure(), Ensure(), and Ensure().


| void log_func_for_gnutls | ( | int | level, |
| const char * | message ) |
This function logs debug messages from gnutls.
| level | GnuTLS log level (integer from 0 to 99 according to GnuTLS documentation. |
| message | GnuTLS log message. |
To enable GNUTLS debug messages, the environment variable OPENVAS_GNUTLS_DEBUG is to be set to the desired log level as described in the GNUTLS manual.
Definition at line 838 of file logging.c.
| void set_log_reference | ( | char * | ref | ) |
Set the log reference object.
In order to be able to see which logs are related to each other, we define a common reference for them. E.g. when multiple scans in OpenVAS are running simultaniousely it is possible to detect all log corresponding to the same scan. The log reference is optional and must be set before calling setup_log_handlers. The data given must be freed by calling free_log_reference(). If called multiple times the old reference gets freed and the new one is set instead.
| ref |
Definition at line 384 of file logging.c.
References reference.
| void set_log_tz | ( | const gchar * | tz | ) |
| int setup_log_handlers | ( | GSList * | gvm_log_config_list | ) |
Sets up routing of logdomains to log handlers.
Iterates over the link list and adds the groups to the handler.
| gvm_log_config_list | A pointer to the configuration linked list. |
Definition at line 981 of file logging.c.
References gvm_log_func(), and setup_log_handlers_internal().

|
static |
Definition at line 910 of file logging.c.
References check_log_file(), and gvm_logging_domain_get_log_domain().
Referenced by Ensure(), Ensure(), Ensure(), and setup_log_handlers().


|
static |
Timezone to use for logs.
NULL means to use the current timezone.
Definition at line 43 of file logging.c.
Referenced by get_time(), and set_log_tz().
|
static |
Definition at line 332 of file logging.c.
Referenced by gvm_log_lock(), gvm_log_lock_init(), and gvm_log_unlock().
|
static |
Definition at line 368 of file logging.c.
Referenced by free_log_reference(), get_log_reference(), gvm_log_func(), and set_log_reference().