OpenVAS Libraries  9.0.1
Data Structures | Macros | Functions
openvas_logging.c File Reference

Implementation of logging methods for OpenVAS. More...

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <syslog.h>
#include <unistd.h>
#include <stdarg.h>
#include <libgen.h>
#include <errno.h>
#include <gnutls/gnutls.h>
#include "openvas_logging.h"

Data Structures

struct  openvas_logging_t
 

Macros

#define SYSLOG_NAMES
 

Functions

gchar * get_time (gchar *time_fmt)
 Returns time as specified in time_fmt strftime format. More...
 
GSList * load_log_configuration (gchar *config_file)
 Loads parameters from a config file into a linked list. More...
 
void free_log_configuration (GSList *log_domain_list)
 Frees all resources loaded by the config loader. More...
 
void openvas_log_silent (const char *log_domain, GLogLevelFlags log_level, const char *message, gpointer openvas_log_config_list)
 Returns immediately. More...
 
void openvas_log_func (const char *log_domain, GLogLevelFlags log_level, const char *message, gpointer openvas_log_config_list)
 Creates the formatted string and outputs it to the log destination. More...
 
void setup_log_handlers (GSList *openvas_log_config_list)
 Sets up routing of logdomains to log handlers. More...
 
void setup_legacy_log_handler (void(*handler)(const char *, va_list))
 Sets up a simple logging function. More...
 
void log_legacy_write (const char *format,...)
 Legacy function to write a log message. More...
 
void log_legacy_fflush (void)
 Legacy function to flush a log message. More...
 

Detailed Description

Implementation of logging methods for OpenVAS.

Todo:
This module fulfils the reqirements to be placed in the base library.

This file contains all methods needed for openvas logging. To enable logging, methods in this file are called. Have a look at openvas-server/openvassd/openvassd.c for an example.

The module reuses glib datatypes and api for memory management and logging.

Macro Definition Documentation

◆ SYSLOG_NAMES

#define SYSLOG_NAMES

Function Documentation

◆ free_log_configuration()

void free_log_configuration ( GSList *  log_domain_list)

Frees all resources loaded by the config loader.

Parameters
log_domain_listHead of the link list.

◆ get_time()

gchar* get_time ( gchar *  time_fmt)

Returns time as specified in time_fmt strftime format.

Parameters
time_fmtptr 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".
Returns
NULL in case the format string is NULL. A ptr to a string that contains the formatted date time value. This value must be freed using glib's g_free.

◆ load_log_configuration()

GSList* load_log_configuration ( gchar *  config_file)

Loads parameters from a config file into a linked list.

Parameters
config_fileA string containing the path to the configuration file to load.
Returns
NULL in case the config file could not be loaded or an error occurred otherwise, a singly linked list of parameter groups is returned.

◆ log_legacy_fflush()

void log_legacy_fflush ( void  )

Legacy function to flush a log message.

This function shall be used instead of fflush for log messages via fprintf. It will eventually be removed.

◆ log_legacy_write()

void log_legacy_write ( const char *  format,
  ... 
)

Legacy function to write a log message.

This function shall be used instead of fprintf in legacy code. It will eventually be replaced by glib log functions.

Parameters
formatprintf style format string

◆ openvas_log_func()

void openvas_log_func ( const char *  log_domain,
GLogLevelFlags  log_level,
const char *  message,
gpointer  openvas_log_config_list 
)

Creates the formatted string and outputs it to the log destination.

Parameters
log_domainA string containing the message's log domain.
log_levelFlags defining the message's log level.
messageA string containing the log message.
openvas_log_config_listA pointer to the configuration linked list.
Todo:
Move log_separator to the conf file too.
Todo:
Check what error this is.

◆ openvas_log_silent()

void openvas_log_silent ( const char *  log_domain,
GLogLevelFlags  log_level,
const char *  message,
gpointer  openvas_log_config_list 
)

Returns immediately.

Parameters
log_domainA string containing the message's log domain.
log_levelFlags defining the message's log level.
messageA string containing the log message.
openvas_log_config_listA pointer to the configuration linked list.

◆ setup_legacy_log_handler()

void setup_legacy_log_handler ( void(*)(const char *, va_list)  handler)

Sets up a simple logging function.

The openvas-scanner has not yet been changed to use the new logging facility. However, it uses library functions and those should use a proper log function instead of writing to stderr. This function can be used to register an existing log handler which will then be used by log_legacy_write.

Parameters
handlerA printf style log handler or NULL to use stderr.

◆ setup_log_handlers()

void setup_log_handlers ( GSList *  openvas_log_config_list)

Sets up routing of logdomains to log handlers.

Iterates over the link list and adds the groups to the handler.

Parameters
openvas_log_config_listA pointer to the configuration linked list.