OpenVAS Libraries  9.0.3
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"
Include dependency graph for openvas_logging.c:

Go to the source code of this file.

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.

Definition in file openvas_logging.c.

Macro Definition Documentation

◆ SYSLOG_NAMES

#define SYSLOG_NAMES

Definition at line 44 of file openvas_logging.c.

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.

Definition at line 298 of file openvas_logging.c.

299 {
300  GSList *log_domain_list_tmp;
301  openvas_logging_t *log_domain_entry;
302 
303  /* Free the struct fields then the struct and then go the next
304  * item in the link list.
305  */
306 
307  /* Go the the head of the list. */
308  log_domain_list_tmp = log_domain_list;
309  while (log_domain_list_tmp != NULL)
310  {
311  /* Get the list data which is an openvas_logging_t struct. */
312  log_domain_entry = log_domain_list_tmp->data;
313 
314  /* Free the struct contents. */
315  g_free (log_domain_entry->log_domain);
316  g_free (log_domain_entry->prepend_string);
317  g_free (log_domain_entry->prepend_time_format);
318  g_free (log_domain_entry->log_file);
319  g_free (log_domain_entry->default_level);
320  g_free (log_domain_entry->syslog_ident);
321 
322  /* Drop the reference to the GIOChannel. */
323  if (log_domain_entry->log_channel)
324  g_io_channel_unref (log_domain_entry->log_channel);
325 
326  /* Free the struct. */
327  g_free (log_domain_entry);
328 
329  /* Go to the next item. */
330  log_domain_list_tmp = g_slist_next (log_domain_list_tmp);
331 
332  }
333  /* Free the link list. */
334  g_slist_free (log_domain_list);
335 }
GLogLevelFlags * default_level
What severity level to use as default.
gchar * log_file
Where to log to.
gchar * prepend_string
Prepend this string before every message.
GIOChannel * log_channel
Gio Channel - FD holder for logfile.
gchar * prepend_time_format
If prependstring has t, format for strftime.
gchar * log_domain
Affected logdomain e.g libnasl.
gchar * syslog_ident
Syslog ident to use for syslog logging.

References openvas_logging_t::default_level, openvas_logging_t::log_channel, openvas_logging_t::log_domain, openvas_logging_t::log_file, openvas_logging_t::prepend_string, openvas_logging_t::prepend_time_format, and openvas_logging_t::syslog_ident.

◆ 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.

Definition at line 96 of file openvas_logging.c.

97 {
98  time_t now;
99  struct tm *ts;
100  gchar buf[80];
101 
102  /* Get the current time. */
103  now = time (NULL);
104 
105  /* Format and print the time, "ddd yyyy-mm-dd hh:mm:ss zzz." */
106  ts = localtime (&now);
107  strftime (buf, sizeof (buf), time_fmt, ts);
108 
109  return g_strdup_printf ("%s", buf);
110 }

◆ 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.

Definition at line 176 of file openvas_logging.c.

177 {
178  GKeyFile *key_file;
179  GKeyFileFlags flags;
180  GError *error = NULL;
181  /* key_file *_has_* functions requires this. */
182 
183  // FIXME: If a g_* function that takes error fails, then free error.
184 
185  /* Groups found in the conf file. */
186  gchar **groups;
187  /* Temp variable to iterate over groups. */
188  gchar **group;
189 
190  /* Structure to hold per group settings. */
191  openvas_logging_t *log_domain_entry;
192  /* The link list for the structure above and it's tmp helper */
193  GSList *log_domain_list = NULL;
194 
195  /* Create a new GKeyFile object and a bitwise list of flags. */
196  key_file = g_key_file_new ();
197  flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;
198 
199  /* Load the GKeyFile from conf or return. */
200  if (!g_key_file_load_from_file (key_file, config_file, flags, &error))
201  {
202  g_error ("%s: %s", config_file, error->message);
203  }
204 
205  /* Get all the groups available. */
206  groups = g_key_file_get_groups (key_file, NULL);
207 
208  /* Point to the group head. */
209  group = groups;
210  /* Iterate till we get to the end of the array. */
211  while (*group != NULL)
212  {
213  /* Create the struct. */
214  log_domain_entry = g_malloc (sizeof (openvas_logging_t));
215  /* Set the logdomain. */
216  log_domain_entry->log_domain = g_strdup (*group);
217  /* Initialize everything else to NULL. */
218  log_domain_entry->prepend_string = NULL;
219  log_domain_entry->prepend_time_format = NULL;
220  log_domain_entry->log_file = NULL;
221  log_domain_entry->default_level = NULL;
222  log_domain_entry->log_channel = NULL;
223  log_domain_entry->syslog_facility = NULL;
224  log_domain_entry->syslog_ident = NULL;
225 
226 
227  /* Look for the prepend string. */
228  if (g_key_file_has_key (key_file, *group, "prepend", &error))
229  {
230  log_domain_entry->prepend_string =
231  g_key_file_get_value (key_file, *group, "prepend", &error);
232  }
233 
234  /* Look for the prepend time format string. */
235  if (g_key_file_has_key (key_file, *group, "prepend_time_format", &error))
236  {
237  log_domain_entry->prepend_time_format =
238  g_key_file_get_value (key_file, *group, "prepend_time_format",
239  &error);
240  }
241 
242  /* Look for the log file string. */
243  if (g_key_file_has_key (key_file, *group, "file", &error))
244  {
245  log_domain_entry->log_file =
246  g_key_file_get_value (key_file, *group, "file", &error);
247  }
248 
249  /* Look for the prepend log level string. */
250  if (g_key_file_has_key (key_file, *group, "level", &error))
251  {
252  gchar *level;
253 
254  level = g_key_file_get_value (key_file, *group, "level", &error);
255  level = g_strchug (level);
256  log_domain_entry->default_level = g_malloc (sizeof (gint));
257  *log_domain_entry->default_level = level_int_from_string (level);
258  g_free (level);
259  }
260 
261  /* Look for the syslog_facility string. */
262  if (g_key_file_has_key (key_file, *group, "syslog_facility", &error))
263  {
264  log_domain_entry->syslog_facility =
265  g_key_file_get_value (key_file, *group, "syslog_facility", &error);
266  }
267  else
268  log_domain_entry->syslog_facility = "local0";
269 
270  /* Look for the syslog_ident string. */
271  if (g_key_file_has_key (key_file, *group, "syslog_ident", &error))
272  {
273  log_domain_entry->syslog_ident =
274  g_key_file_get_value (key_file, *group, "syslog_ident", &error);
275  }
276  else
277  log_domain_entry->syslog_ident = g_strdup (*group);
278 
279  /* Attach the struct to the list. */
280  log_domain_list = g_slist_prepend (log_domain_list, log_domain_entry);
281  group++;
282  }
283  /* Free the groups array. */
284  g_strfreev (groups);
285 
286  /* Free the key file. */
287  g_key_file_free (key_file);
288 
289  return log_domain_list;
290 }
GLogLevelFlags * default_level
What severity level to use as default.
gchar * log_file
Where to log to.
gchar * prepend_string
Prepend this string before every message.
GIOChannel * log_channel
Gio Channel - FD holder for logfile.
gchar * prepend_time_format
If prependstring has t, format for strftime.
gchar * log_domain
Affected logdomain e.g libnasl.
gchar * syslog_ident
Syslog ident to use for syslog logging.
gchar * syslog_facility
Syslog facility to use for syslog logging.

References openvas_logging_t::default_level, openvas_logging_t::log_channel, openvas_logging_t::log_domain, openvas_logging_t::log_file, openvas_logging_t::prepend_string, openvas_logging_t::prepend_time_format, openvas_logging_t::syslog_facility, and openvas_logging_t::syslog_ident.

◆ 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.

Definition at line 851 of file openvas_logging.c.

852 {
853  if (!legacy_log_handler)
854  fflush (stderr);
855 }

Referenced by openvas_get_socket_from_connection().

Here is the caller graph for this function:

◆ 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

Definition at line 832 of file openvas_logging.c.

833 {
834  va_list arg_ptr;
835 
836  va_start (arg_ptr, format);
837  if (legacy_log_handler)
838  legacy_log_handler (format, arg_ptr);
839  else
840  vfprintf (stderr, format, arg_ptr);
841  va_end (arg_ptr);
842 }

Referenced by arg_dump(), build_encode_URL(), close_stream_connection(), exec_nasl_script(), get_plugin_preference_fname(), getinterfaces(), getipv4routes(), getipv6routes(), ids_open_sock_tcp(), internal_recv(), internal_send(), nasl_cert_close(), nasl_cert_open(), nasl_cert_query(), nasl_smb_connect(), nasl_smb_file_group_sid(), nasl_smb_file_owner_sid(), nasl_smb_file_SDDL(), nasl_smb_file_trustee_rights(), nasl_socket_get_error(), nasl_win_cmd_exec(), nasl_wmi_connect(), nasl_wmi_connect_reg(), nasl_wmi_connect_rsop(), nasl_wmi_query(), nasl_wmi_query_rsop(), nasl_wmi_reg_create_key(), nasl_wmi_reg_delete_key(), nasl_wmi_reg_enum_key(), nasl_wmi_reg_enum_value(), nasl_wmi_reg_get_bin_val(), nasl_wmi_reg_get_dword_val(), nasl_wmi_reg_get_ex_string_val(), nasl_wmi_reg_get_mul_string_val(), nasl_wmi_reg_get_qword_val(), nasl_wmi_reg_get_sz(), nasl_wmi_reg_set_dword_val(), nasl_wmi_reg_set_ex_string_val(), nasl_wmi_reg_set_qword_val(), nasl_wmi_reg_set_string_val(), nrecv(), open_sock_option(), open_stream_connection_ext(), openvas_get_socket_from_connection(), openvas_popen4(), plugin_run_openvas_tcp_scanner(), rm_packet(), socket_get_cert(), socket_get_ssl_ciphersuite(), socket_get_ssl_compression(), socket_get_ssl_session_id(), socket_get_ssl_version(), socket_negotiate_ssl(), tlserror(), and v6_sendpacket().

◆ 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.

Definition at line 389 of file openvas_logging.c.

391 {
392  gchar *prepend;
393  gchar *prepend_buf;
394  gchar *prepend_tmp;
395  gchar *prepend_tmp1;
396  gchar *tmp;
397  gchar *tmpstr;
398  int messagelen;
399 
400  /* For link list operations. */
401  GSList *log_domain_list_tmp;
402  openvas_logging_t *log_domain_entry = NULL;
403 
404  /* Channel to log through. */
405  GIOChannel *channel;
406  GError *error = NULL;
407 
408  /* The default parameters to be used. The group '*' will override
409  * these defaults if it's found.
410  */
411  gchar *prepend_format = "%p %t - ";
412  gchar *time_format = "%Y-%m-%d %Hh%M.%S %Z";
413 
415  gchar *log_separator = ":";
416  gchar *log_file = "-";
417  GLogLevelFlags default_level = G_LOG_LEVEL_DEBUG;
418  channel = NULL;
419  gchar *syslog_facility = "local0";
420  gchar *syslog_ident = NULL;
421 
422  /* Initialize logger lock if not done. */
423  openvas_log_lock_init ();
424 
425  /* Let's load the default configuration file directives from the
426  * linked list. Scanning the link list twice is inefficient but
427  * leaves the source cleaner.
428  */
429  if (openvas_log_config_list != NULL && log_domain != NULL)
430  {
431 
432  /* Go the the head of the list. */
433  log_domain_list_tmp = (GSList *) openvas_log_config_list;
434 
435  while (log_domain_list_tmp != NULL)
436  {
437  openvas_logging_t *entry;
438 
439  entry = log_domain_list_tmp->data;
440 
441  /* Override defaults if the current linklist group name is '*'. */
442  if (g_ascii_strcasecmp (entry->log_domain, "*") == 0)
443  {
444  /* Get the list data for later use. */
445  log_domain_entry = entry;
446 
447  /* Override defaults if the group items are not null. */
448  if (log_domain_entry->prepend_string)
449  prepend_format = log_domain_entry->prepend_string;
450  if (log_domain_entry->prepend_time_format)
451  time_format = log_domain_entry->prepend_time_format;
452  if (log_domain_entry->log_file)
453  log_file = log_domain_entry->log_file;
454  if (log_domain_entry->default_level)
455  default_level = *log_domain_entry->default_level;
456  if (log_domain_entry->log_channel)
457  channel = log_domain_entry->log_channel;
458  if (log_domain_entry->syslog_facility)
459  syslog_facility = log_domain_entry->syslog_facility;
460  break;
461  }
462 
463  /* Go to the next item. */
464  log_domain_list_tmp = g_slist_next (log_domain_list_tmp);
465  }
466  }
467 
468  /* Let's load the configuration file directives if a linked list item for
469  * the log domain group exists.
470  */
471  if (openvas_log_config_list != NULL && log_domain != NULL)
472  {
473 
474  /* Go the the head of the list. */
475  log_domain_list_tmp = (GSList *) openvas_log_config_list;
476 
477  while (log_domain_list_tmp != NULL)
478  {
479  openvas_logging_t *entry;
480 
481  entry = log_domain_list_tmp->data;
482 
483  /* Search for the log domain in the link list. */
484  if (g_ascii_strcasecmp (entry->log_domain, log_domain) == 0)
485  {
486  /* Get the list data which is an openvas_logging_t struct. */
487  log_domain_entry = entry;
488 
489  /* Get the struct contents. */
490  prepend_format = log_domain_entry->prepend_string;
491  time_format = log_domain_entry->prepend_time_format;
492  log_file = log_domain_entry->log_file;
493  if (log_domain_entry->default_level)
494  default_level = *log_domain_entry->default_level;
495  channel = log_domain_entry->log_channel;
496  syslog_facility = log_domain_entry->syslog_facility;
497  syslog_ident = log_domain_entry->syslog_ident;
498  break;
499  }
500 
501  /* Go to the next item. */
502  log_domain_list_tmp = g_slist_next (log_domain_list_tmp);
503  }
504  }
505 
506  /* If the current log entry is less severe than the specified log level,
507  * let's exit.
508  */
509  if (default_level < log_level)
510  return;
511 
512 
513  /* Prepend buf is a newly allocated empty string. Makes life easier. */
514  prepend_buf = g_strdup ("");
515 
516 
517  /* Make the tmp pointer (for iteration) point to the format string. */
518  tmp = prepend_format;
519 
520  while (*tmp != '\0')
521  {
522  /* If the current char is a % and the next one is a p, get the pid. */
523  if ((*tmp == '%') && (*(tmp + 1) == 'p'))
524  {
525  /* Use g_strdup, a new string returned. Store it in a tmp var until
526  * we free the old one. */
527  prepend_tmp =
528  g_strdup_printf ("%s%s%d", prepend_buf, log_separator,
529  (int) getpid ());
530  /* Free the old string. */
531  g_free (prepend_buf);
532  /* Point the buf ptr to the new string. */
533  prepend_buf = prepend_tmp;
534  /* Skip over the two chars we've processed '%p'. */
535  tmp += 2;
536  }
537  else if ((*tmp == '%') && (*(tmp + 1) == 't'))
538  {
539  /* Get time returns a newly allocated string.
540  * Store it in a tmp var.
541  */
542  prepend_tmp1 = get_time (time_format);
543  /* Use g_strdup. New string returned. Store it in a tmp var until
544  * we free the old one.
545  */
546  prepend_tmp =
547  g_strdup_printf ("%s%s%s", prepend_buf, log_separator,
548  prepend_tmp1);
549  /* Free the time tmp var. */
550  g_free (prepend_tmp1);
551  /* Free the old string. */
552  g_free (prepend_buf);
553  /* Point the buf ptr to the new string. */
554  prepend_buf = prepend_tmp;
555  /* Skip over the two chars we've processed '%t.' */
556  tmp += 2;
557  }
558  else
559  {
560  /* Jump to the next character. */
561  tmp++;
562  }
563  }
564 
565  /* Step through all possible messages prefixing them with an appropriate
566  * tag.
567  */
568  switch (log_level)
569  {
570  case G_LOG_FLAG_RECURSION:
571  prepend = g_strdup_printf ("RECURSION%s", prepend_buf);
572  break;
573 
574  case G_LOG_FLAG_FATAL:
575  prepend = g_strdup_printf ("FATAL%s", prepend_buf);
576  break;
577 
578  case G_LOG_LEVEL_ERROR:
579  prepend = g_strdup_printf ("ERROR%s", prepend_buf);
580  break;
581 
582  case G_LOG_LEVEL_CRITICAL:
583  prepend = g_strdup_printf ("CRITICAL%s", prepend_buf);
584  break;
585 
586  case G_LOG_LEVEL_WARNING:
587  prepend = g_strdup_printf ("WARNING%s", prepend_buf);
588  break;
589 
590  case G_LOG_LEVEL_MESSAGE:
591  prepend = g_strdup_printf ("MESSAGE%s", prepend_buf);
592  break;
593 
594  case G_LOG_LEVEL_INFO:
595  prepend = g_strdup_printf (" INFO%s", prepend_buf);
596  break;
597 
598  case G_LOG_LEVEL_DEBUG:
599  prepend = g_strdup_printf (" DEBUG%s", prepend_buf);
600  break;
601 
602  default:
603  prepend = g_strdup_printf ("UNKNOWN%s", prepend_buf);
604  break;
605  }
606 
607  /* If the current log entry is more severe than the specified log
608  * level, print out the message. In case MESSAGE already ends in a
609  * LF and there is not only the LF, remove the LF to avoid empty
610  * lines in the log.
611  */
612  messagelen = message? strlen (message) : 0;
613  if (messagelen > 1 && message[messagelen-1] == '\n')
614  messagelen--;
615  tmpstr = g_strdup_printf ("%s%s%s%s %.*s\n",
616  log_domain ? log_domain : "", log_separator,
617  prepend, log_separator, messagelen, message);
618  g_free (prepend);
619 
620  openvas_log_lock ();
621  /* Output everything to stderr if logfile is "-". */
622  if (g_ascii_strcasecmp (log_file, "-") == 0)
623  {
624  fprintf (stderr, "%s", tmpstr);
625  fflush (stderr);
626  }
627  /* Output everything to syslog if logfile is "syslog" */
628  else if (g_ascii_strcasecmp (log_file, "syslog") == 0)
629  {
630  int facility = facility_int_from_string (syslog_facility);
631  int syslog_level = LOG_INFO;
632 
633  openlog (syslog_ident, LOG_CONS | LOG_PID | LOG_NDELAY, facility);
634 
635  switch (log_level)
636  {
637  case G_LOG_FLAG_FATAL:
638  syslog_level = LOG_ALERT;
639  break;
640  case G_LOG_LEVEL_ERROR:
641  syslog_level = LOG_ERR;
642  break;
643  case G_LOG_LEVEL_CRITICAL:
644  syslog_level = LOG_CRIT;
645  break;
646  case G_LOG_LEVEL_WARNING:
647  syslog_level = LOG_WARNING;
648  break;
649  case G_LOG_LEVEL_MESSAGE:
650  syslog_level = LOG_NOTICE;
651  break;
652  case G_LOG_LEVEL_INFO:
653  syslog_level = LOG_INFO;
654  break;
655  case G_LOG_LEVEL_DEBUG:
656  syslog_level = LOG_DEBUG;
657  break;
658  default:
659  syslog_level = LOG_INFO;
660  break;
661  }
662 
663  syslog (syslog_level, "%s", message);
664 
665  closelog ();
666  }
667  else
668  {
669  /* Open a channel and store it in the struct or
670  * retrieve and use an already existing channel.
671  */
672  if (channel == NULL)
673  {
674  channel = g_io_channel_new_file (log_file, "a", &error);
675  if (!channel)
676  {
677  gchar *log = g_strdup (log_file);
678  gchar *dir = dirname (log);
679 
681  g_error_free (error);
682 
683  /* Ensure directory exists. */
684  if (g_mkdir_with_parents (dir, 0755)) /* "rwxr-xr-x" */
685  {
686  g_warning ("Failed to create log file directory %s: %s", dir,
687  strerror (errno));
688  g_free (log);
689  g_free (tmpstr);
690  g_free (prepend_buf);
691  return;
692  }
693  g_free (log);
694 
695  /* Try again. */
696  error = NULL;
697  channel = g_io_channel_new_file (log_file, "a", &error);
698  if (!channel)
699  {
700  g_error ("Can not open '%s' logfile: %s", log_file,
701  error->message);
702  }
703  }
704 
705  /* Store it in the struct for later use. */
706  if (log_domain_entry != NULL)
707  log_domain_entry->log_channel = channel;
708  }
709  g_io_channel_write_chars (channel, (const gchar *) tmpstr, -1, NULL,
710  &error);
711  g_io_channel_flush (channel, NULL);
712 
713  }
714  openvas_log_unlock ();
715  g_free (tmpstr);
716  g_free (prepend_buf);
717 }
GLogLevelFlags * default_level
What severity level to use as default.
gchar * log_file
Where to log to.
gchar * prepend_string
Prepend this string before every message.
GIOChannel * log_channel
Gio Channel - FD holder for logfile.
gchar * prepend_time_format
If prependstring has t, format for strftime.
gchar * log_domain
Affected logdomain e.g libnasl.
gchar * syslog_ident
Syslog ident to use for syslog logging.
gchar * syslog_facility
Syslog facility to use for syslog logging.
gchar * get_time(gchar *time_fmt)
Returns time as specified in time_fmt strftime format.

Referenced by setup_log_handlers().

Here is the caller graph for this function:

◆ 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.

Definition at line 346 of file openvas_logging.c.

348 {
349  (void) log_domain;
350  (void) log_level;
351  (void) message;
352  (void) openvas_log_config_list;
353  return;
354 }

◆ 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.

Definition at line 817 of file openvas_logging.c.

818 {
819  legacy_log_handler = handler;
820 }

◆ 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.

Definition at line 742 of file openvas_logging.c.

743 {
744  GSList *log_domain_list_tmp;
745  openvas_logging_t *log_domain_entry;
746  if (openvas_log_config_list != NULL)
747  {
748  /* Go to the head of the list. */
749  log_domain_list_tmp = (GSList *) openvas_log_config_list;
750 
751  while (log_domain_list_tmp != NULL)
752  {
753  /* Get the list data which is an openvas_logging_t struct. */
754  log_domain_entry = log_domain_list_tmp->data;
755 
756  GLogFunc logfunc =
757 #if 0
758  (!strcmp (log_domain_entry, "syslog")) ? openvas_syslog_func :
759 #endif
761 
762  if (g_ascii_strcasecmp (log_domain_entry->log_domain, "*"))
763  {
764  g_log_set_handler (log_domain_entry->log_domain,
765  (GLogLevelFlags) (G_LOG_LEVEL_DEBUG |
766  G_LOG_LEVEL_INFO |
767  G_LOG_LEVEL_MESSAGE |
768  G_LOG_LEVEL_WARNING |
769  G_LOG_LEVEL_CRITICAL |
770  G_LOG_LEVEL_ERROR |
771  G_LOG_FLAG_FATAL |
772  G_LOG_FLAG_RECURSION),
773  (GLogFunc) logfunc, openvas_log_config_list);
774  }
775  else
776  {
777  g_log_set_default_handler ((GLogFunc) logfunc,
778  openvas_log_config_list);
779  }
780 
781  /* Go to the next item. */
782  log_domain_list_tmp = g_slist_next (log_domain_list_tmp);
783  }
784  }
785  g_log_set_handler ("",
786  (GLogLevelFlags) (G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO |
787  G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_WARNING
788  | G_LOG_LEVEL_CRITICAL |
789  G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL |
790  G_LOG_FLAG_RECURSION),
791  (GLogFunc) openvas_log_func, openvas_log_config_list);
792 
793  /* Check whether GNUTLS debugging has been enabled. */
794  {
795  const char *s;
796  if ((s=getenv ("OPENVAS_GNUTLS_DEBUG")))
797  {
798  gnutls_global_set_log_function (log_func_for_gnutls);
799  gnutls_global_set_log_level (atoi (s));
800  }
801  }
802 }
gchar * log_domain
Affected logdomain e.g libnasl.
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.

References openvas_logging_t::log_domain, and openvas_log_func().

Here is the call graph for this function: