Greenbone Vulnerability Management Libraries 22.32.0
logging.h File Reference

Implementation of logging methods. More...

#include <glib.h>
Include dependency graph for logging.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LOG_REFERENCES_AVAILABLE
 for backward compatibility

Functions

GSList * load_log_configuration (gchar *)
 Loads parameters from a config file into a linked list.
void free_log_configuration (GSList *)
 Frees all resources loaded by the config loader.
gchar * get_time (gchar *)
 Returns time as specified in time_fmt strftime format.
void gvm_log_silent (const char *, GLogLevelFlags, const char *, gpointer)
 Returns immediately.
void gvm_log_func (const char *, GLogLevelFlags, const char *, gpointer)
 Creates the formatted string and outputs it to the log destination.
void log_func_for_gnutls (int, const char *)
 This function logs debug messages from gnutls.
int setup_log_handlers (GSList *)
 Sets up routing of logdomains to log handlers.
void gvm_log_lock (void)
 Try to lock logger_mutex.
void gvm_log_unlock (void)
 Unlock logger_mutex.
void set_log_reference (char *)
 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 set_log_tz (const gchar *)
 Set the log timezone.

Detailed Description

Implementation of logging methods.

Definition in file logging.h.

Macro Definition Documentation

◆ LOG_REFERENCES_AVAILABLE

#define LOG_REFERENCES_AVAILABLE

for backward compatibility

Definition at line 20 of file logging.h.

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 286 of file logging.c.

287{
288 GSList *log_domain_list_tmp;
289
290 /* Free the struct fields then the struct and then go the next
291 * item in the link list.
292 */
293
294 /* Go to the head of the list. */
295 log_domain_list_tmp = log_domain_list;
296 while (log_domain_list_tmp != NULL)
297 {
298 gvm_logging_domain_t *log_domain_entry;
299
300 /* Get the list data which is an gvm_logging_t struct. */
301 log_domain_entry = log_domain_list_tmp->data;
302
303 /* Free the struct contents. */
304 gvm_logging_domain_free (log_domain_entry);
305
306 /* Go to the next item. */
307 log_domain_list_tmp = g_slist_next (log_domain_list_tmp);
308 }
309 /* Free the link list. */
310 g_slist_free (log_domain_list);
311}
void gvm_logging_domain_free(gvm_logging_domain_t *log_domain)
Frees the resources associated with the given logging domain.
struct gvm_logging_domain gvm_logging_domain_t

References gvm_logging_domain_free().

Referenced by Ensure(), Ensure(), and Ensure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_log_reference()

void free_log_reference ( void )

Free the log reference object.

The reference object is used to detect corresponding logs.

Definition at line 412 of file logging.c.

413{
414 if (reference)
415 g_free ((char *) reference);
416 reference = NULL;
417}
static char * reference
Definition logging.c:368

References reference.

◆ get_log_reference()

char * get_log_reference ( void )

Get the log reference object.

This function returns the current log reference. This enables the possibility to save or modify the current reference value.

Returns
char*

Definition at line 400 of file logging.c.

401{
402 return (char *) reference;
403}

References reference.

◆ 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 57 of file logging.c.

58{
59 time_t now;
60 struct tm ts;
61 gchar buf[80], *original_tz;
62
63 if (!time_fmt)
64 return NULL;
65
66 if (log_tz)
67 {
68 original_tz = getenv ("TZ") ? g_strdup (getenv ("TZ")) : NULL;
69 setenv ("TZ", log_tz, 1);
70 tzset ();
71 }
72
73 /* Get the current time. */
74 now = time (NULL);
75
76 /* Format and print the time, "ddd yyyy-mm-dd hh:mm:ss zzz." */
77 localtime_r (&now, &ts);
78 strftime (buf, sizeof (buf), time_fmt, &ts);
79
80 if (log_tz)
81 {
82 /* Revert to stored TZ. */
83 if (original_tz)
84 {
85 setenv ("TZ", original_tz, 1);
86 g_free (original_tz);
87 tzset ();
88 }
89 else
90 unsetenv ("TZ");
91 }
92
93 return g_strdup_printf ("%s", buf);
94}
static gchar * log_tz
Timezone to use for logs.
Definition logging.c:43

References log_tz.

Referenced by Ensure(), and gvm_log_func().

Here is the caller graph for this function:

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

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

Definition at line 428 of file logging.c.

430{
431 gchar *prepend;
432 gchar *prepend_buf;
433 gchar *prepend_tmp;
434 gchar *prepend_tmp1;
435 gchar *tmp;
436 gchar *tmpstr;
437 int messagelen;
438
439 /* For link list operations. */
440 GSList *log_domain_list_tmp;
441 gvm_logging_domain_t *log_domain_entry = NULL;
442
443 /* Channel to log through. */
444 GIOChannel *channel = NULL;
445 GError *error = NULL;
446
447 /* The default parameters to be used. The group '*' will override
448 * these defaults if it's found.
449 */
450 gchar *prepend_format = "%t %s %p - ";
451 gchar *time_format = "%Y-%m-%d %Hh%M.%S %Z";
452 gchar *log_separator = ":";
453 gchar *log_file = "-";
454 GLogLevelFlags default_level = G_LOG_LEVEL_DEBUG;
455 gchar *syslog_facility = "local0";
456 gchar *syslog_ident = NULL;
457
458 /* Let's load the default configuration file directives from the
459 * linked list. Scanning the link list twice is inefficient but
460 * leaves the source cleaner.
461 */
462 if (gvm_log_config_list != NULL && log_domain != NULL)
463 {
464 /* Go to the head of the list. */
465 log_domain_list_tmp = (GSList *) gvm_log_config_list;
466
467 while (log_domain_list_tmp != NULL)
468 {
470
471 entry = log_domain_list_tmp->data;
472
473 /* Override defaults if the current linklist group name is '*'. */
474 if (g_ascii_strcasecmp (gvm_logging_domain_get_log_domain (entry),
475 "*")
476 == 0)
477 {
478 /* Get the list data for later use. */
479 log_domain_entry = entry;
480
481 /* Override defaults if the group items are not null. */
482 if (gvm_logging_domain_get_prepend_string (log_domain_entry))
483 prepend_format =
484 gvm_logging_domain_get_prepend_string (log_domain_entry);
485 if (gvm_logging_domain_get_prepend_time_format (log_domain_entry))
486 time_format =
488 if (gvm_logging_domain_get_log_file (log_domain_entry))
489 log_file = gvm_logging_domain_get_log_file (log_domain_entry);
490 if (gvm_logging_domain_get_default_level (log_domain_entry))
491 default_level =
492 *gvm_logging_domain_get_default_level (log_domain_entry);
493 if (gvm_logging_domain_get_log_channel (log_domain_entry))
494 channel = gvm_logging_domain_get_log_channel (log_domain_entry);
495 if (gvm_logging_domain_get_syslog_facility (log_domain_entry))
496 syslog_facility =
498 if (gvm_logging_domain_get_prepend_separator (log_domain_entry))
499 log_separator =
501 break;
502 }
503
504 /* Go to the next item. */
505 log_domain_list_tmp = g_slist_next (log_domain_list_tmp);
506 }
507 }
508
509 /* Let's load the configuration file directives if a linked list item for
510 * the log domain group exists.
511 */
512 if (gvm_log_config_list != NULL && log_domain != NULL)
513 {
514 /* Go to the head of the list. */
515 log_domain_list_tmp = (GSList *) gvm_log_config_list;
516
517 while (log_domain_list_tmp != NULL)
518 {
520
521 entry = log_domain_list_tmp->data;
522
523 /* Search for the log domain in the link list. */
524 if (g_ascii_strcasecmp (gvm_logging_domain_get_log_domain (entry),
525 log_domain)
526 == 0)
527 {
528 /* Get the list data which is an gvm_logging_t struct. */
529 log_domain_entry = entry;
530
531 /* Get the struct contents. */
532 if (gvm_logging_domain_get_prepend_string (log_domain_entry))
533 prepend_format =
534 gvm_logging_domain_get_prepend_string (log_domain_entry);
535 if (gvm_logging_domain_get_prepend_time_format (log_domain_entry))
536 time_format =
538 if (gvm_logging_domain_get_log_file (log_domain_entry))
539 log_file = gvm_logging_domain_get_log_file (log_domain_entry);
540 if (gvm_logging_domain_get_default_level (log_domain_entry))
541 default_level =
542 *gvm_logging_domain_get_default_level (log_domain_entry);
543 if (gvm_logging_domain_get_log_channel (log_domain_entry))
544 channel = gvm_logging_domain_get_log_channel (log_domain_entry);
545 if (gvm_logging_domain_get_syslog_facility (log_domain_entry))
546 syslog_facility =
548 if (gvm_logging_domain_get_syslog_ident (log_domain_entry))
549 syslog_ident =
550 gvm_logging_domain_get_syslog_ident (log_domain_entry);
551 if (gvm_logging_domain_get_prepend_separator (log_domain_entry))
552 log_separator =
554 break;
555 }
556
557 /* Go to the next item. */
558 log_domain_list_tmp = g_slist_next (log_domain_list_tmp);
559 }
560 }
561
562 /* If the current log entry is less severe than the specified log level,
563 * let's exit.
564 */
565 if (default_level < log_level)
566 return;
567
568 /* Prepend buf is a newly allocated empty string. Makes life easier. */
569 prepend_buf = g_strdup ("");
570
571 /* Make the tmp pointer (for iteration) point to the format string. */
572 tmp = prepend_format;
573
574 while (*tmp != '\0')
575 {
576 /* If the current char is a % and the next one is a p, get the pid. */
577 if ((*tmp == '%') && (*(tmp + 1) == 'p'))
578 {
579 if (reference)
580 {
581 prepend_tmp =
582 g_strdup_printf ("%s%d%s%s", prepend_buf, (int) getpid (),
583 log_separator, reference);
584 }
585 else
586 {
587 /* Use g_strdup, a new string returned. Store it in a tmp var
588 * until we free the old one. */
589 prepend_tmp =
590 g_strdup_printf ("%s%d", prepend_buf, (int) getpid ());
591 }
592 /* Free the old string. */
593 g_free (prepend_buf);
594 /* Point the buf ptr to the new string. */
595 prepend_buf = prepend_tmp;
596 /* Skip over the two chars we've processed '%p'. */
597 tmp += 2;
598 }
599 else if ((*tmp == '%') && (*(tmp + 1) == 't'))
600 {
601 /* Get time returns a newly allocated string.
602 * Store it in a tmp var.
603 */
604 prepend_tmp1 = get_time (time_format);
605 if (!prepend_tmp1)
606 {
607 prepend_tmp1 = g_strdup ("");
608 }
609 /* Use g_strdup. New string returned. Store it in a tmp var until
610 * we free the old one.
611 */
612 prepend_tmp = g_strdup_printf ("%s%s", prepend_buf, prepend_tmp1);
613 /* Free the time tmp var. */
614 g_free (prepend_tmp1);
615 /* Free the old string. */
616 g_free (prepend_buf);
617 /* Point the buf ptr to the new string. */
618 prepend_buf = prepend_tmp;
619 /* Skip over the two chars we've processed '%t.' */
620 tmp += 2;
621 }
622 else if ((*tmp == '%') && (*(tmp + 1) == 's'))
623 {
624 /* Use g_strdup. New string returned. Store it in a tmp var until
625 * we free the old one.
626 */
627 prepend_tmp = g_strdup_printf ("%s%s", prepend_buf, log_separator);
628 /* Free the old string. */
629 g_free (prepend_buf);
630 /* Point the buf ptr to the new string. */
631 prepend_buf = prepend_tmp;
632 /* Skip over the two chars we've processed '%s.' */
633 tmp += 2;
634 }
635 else
636 {
637 /* Jump to the next character. */
638 tmp++;
639 }
640 }
641
642 /* Step through all possible messages prefixing them with an appropriate
643 * tag.
644 */
645 switch (log_level)
646 {
647 case G_LOG_FLAG_RECURSION:
648 prepend = g_strdup_printf ("RECURSION%s%s", log_separator, prepend_buf);
649 break;
650
651 case G_LOG_FLAG_FATAL:
652 prepend = g_strdup_printf ("FATAL%s%s", log_separator, prepend_buf);
653 break;
654
655 case G_LOG_LEVEL_ERROR:
656 prepend = g_strdup_printf ("ERROR%s%s", log_separator, prepend_buf);
657 break;
658
659 case G_LOG_LEVEL_CRITICAL:
660 prepend = g_strdup_printf ("CRITICAL%s%s", log_separator, prepend_buf);
661 break;
662
663 case G_LOG_LEVEL_WARNING:
664 prepend = g_strdup_printf ("WARNING%s%s", log_separator, prepend_buf);
665 break;
666
667 case G_LOG_LEVEL_MESSAGE:
668 prepend = g_strdup_printf ("MESSAGE%s%s", log_separator, prepend_buf);
669 break;
670
671 case G_LOG_LEVEL_INFO:
672 prepend = g_strdup_printf (" INFO%s%s", log_separator, prepend_buf);
673 break;
674
675 case G_LOG_LEVEL_DEBUG:
676 prepend = g_strdup_printf (" DEBUG%s%s", log_separator, prepend_buf);
677 break;
678
679 default:
680 prepend = g_strdup_printf ("UNKNOWN%s%s", log_separator, prepend_buf);
681 break;
682 }
683
684 /* If the current log entry is more severe than the specified log
685 * level, print out the message. In case MESSAGE already ends in a
686 * LF and there is not only the LF, remove the LF to avoid empty
687 * lines in the log.
688 */
689 messagelen = message ? strlen (message) : 0;
690 if (messagelen > 1 && message[messagelen - 1] == '\n')
691 messagelen--;
692 tmpstr = g_strdup_printf ("%s%s%s%s %.*s\n", log_domain ? log_domain : "",
693 log_separator, prepend, log_separator, messagelen,
694 message);
695 g_free (prepend);
696
697 if (log_level <= G_LOG_LEVEL_WARNING)
698 gvm_sentry_log (message);
699
700 gvm_log_lock ();
701 /* Output everything to stderr if logfile is NULL, an empty string or "-". */
702 if (!log_file || g_ascii_strcasecmp (log_file, "-") == 0
703 || !g_strcmp0 (log_file, ""))
704 {
705 fprintf (stderr, "%s", tmpstr);
706 fflush (stderr);
707 }
708 /* Output everything to syslog if logfile is "syslog" */
709 else if (g_ascii_strcasecmp (log_file, "syslog") == 0)
710 {
711 int facility = facility_int_from_string (syslog_facility);
712 int syslog_level = LOG_INFO;
713
714 openlog (syslog_ident, LOG_CONS | LOG_PID | LOG_NDELAY, facility);
715
716 switch (log_level)
717 {
718 case G_LOG_FLAG_FATAL:
719 syslog_level = LOG_ALERT;
720 break;
721 case G_LOG_LEVEL_ERROR:
722 syslog_level = LOG_ERR;
723 break;
724 case G_LOG_LEVEL_CRITICAL:
725 syslog_level = LOG_CRIT;
726 break;
727 case G_LOG_LEVEL_WARNING:
728 syslog_level = LOG_WARNING;
729 break;
730 case G_LOG_LEVEL_MESSAGE:
731 syslog_level = LOG_NOTICE;
732 break;
733 case G_LOG_LEVEL_INFO:
734 syslog_level = LOG_INFO;
735 break;
736 case G_LOG_LEVEL_DEBUG:
737 syslog_level = LOG_DEBUG;
738 break;
739 default:
740 syslog_level = LOG_INFO;
741 break;
742 }
743
744 /* Syslog doesn't support messages longer than 1kb. The overflow data
745 will not be logged or will be shown in the hypervisor console
746 if it runs on a virtual machine. */
747 if (messagelen > 1000)
748 {
749 int pos;
750 char *message_aux, *message_aux2;
751 char buffer[1000];
752
753 message_aux2 = g_strdup (message);
754 message_aux = message_aux2;
755 for (pos = 0; pos <= messagelen; pos = pos + sizeof (buffer) - 1)
756 {
757 memcpy (buffer, message_aux, sizeof (buffer) - 1);
758 buffer[sizeof (buffer) - 1] = '\0';
759 message_aux = &(message_aux[sizeof (buffer) - 1]);
760 syslog (syslog_level, "%s", buffer);
761 }
762 g_free (message_aux2);
763 }
764 else
765 syslog (syslog_level, "%s", message);
766
767 closelog ();
768 }
769 else
770 {
771 /* Open a channel and store it in the struct or
772 * retrieve and use an already existing channel.
773 */
774 if (channel == NULL)
775 {
776 channel = g_io_channel_new_file (log_file, "a", &error);
777 if (!channel)
778 {
779 gchar *log = g_strdup (log_file);
780 gchar *dir = dirname (log);
781
782 /* Check error. In case of the directory does not exist, it will
783 * be handle below. In other case a message is printed to the
784 * stderr since the channel is still not created/accessible.
785 */
786 if (error->code != G_FILE_ERROR_NOENT)
787 fprintf (stderr, "Can not open '%s' logfile: %s\n", log_file,
788 error->message);
789 g_error_free (error);
790
791 /* Ensure directory exists. */
792 if (g_mkdir_with_parents (dir, 0755)) /* "rwxr-xr-x" */
793 {
794 g_warning ("Failed to create log file directory %s: %s", dir,
795 strerror (errno));
796 g_free (log);
797 g_free (tmpstr);
798 g_free (prepend_buf);
799 return;
800 }
801 g_free (log);
802
803 /* Try again. */
804 error = NULL;
805 channel = g_io_channel_new_file (log_file, "a", &error);
806 if (!channel)
807 {
808 g_error ("Can not open '%s' logfile: %s", log_file,
809 error->message);
810 }
811 }
812
813 /* Store it in the struct for later use. */
814 if (log_domain_entry != NULL)
815 gvm_logging_domain_set_log_channel (log_domain_entry, channel);
816 }
817 g_io_channel_write_chars (channel, (const gchar *) tmpstr, -1, NULL,
818 &error);
819 g_io_channel_flush (channel, NULL);
820 }
822 g_free (tmpstr);
823 g_free (prepend_buf);
824}
void gvm_sentry_log(const char *message)
Send a message to Sentry server if it was initialized.
Definition gvm_sentry.c:97
gchar * get_time(gchar *time_fmt)
Returns time as specified in time_fmt strftime format.
Definition logging.c:57
void gvm_log_unlock(void)
Unlock logger_mutex.
Definition logging.c:363
void gvm_log_lock(void)
Try to lock logger_mutex.
Definition logging.c:351
static gint facility_int_from_string(const gchar *facility)
Return the integer corresponding to a syslog facility string.
Definition logging.c:135
GIOChannel * gvm_logging_domain_get_log_channel(gvm_logging_domain_t *log_domain)
GLogLevelFlags * gvm_logging_domain_get_default_level(gvm_logging_domain_t *log_domain)
gchar * gvm_logging_domain_get_prepend_time_format(gvm_logging_domain_t *log_domain)
gchar * gvm_logging_domain_get_syslog_ident(gvm_logging_domain_t *log_domain)
void gvm_logging_domain_set_log_channel(gvm_logging_domain_t *log_domain, GIOChannel *log_channel)
Sets the log channel for the logging domain.
gchar * gvm_logging_domain_get_log_file(gvm_logging_domain_t *log_domain)
gchar * gvm_logging_domain_get_log_domain(gvm_logging_domain_t *log_domain)
gchar * gvm_logging_domain_get_prepend_separator(gvm_logging_domain_t *log_domain)
gchar * gvm_logging_domain_get_prepend_string(gvm_logging_domain_t *log_domain)
gchar * gvm_logging_domain_get_syslog_facility(gvm_logging_domain_t *log_domain)

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvm_log_lock()

void gvm_log_lock ( void )

Try to lock logger_mutex.

Definition at line 351 of file logging.c.

352{
353 /* Initialize logger lock if not done already. */
355
356 g_mutex_lock (logger_mutex);
357}
static GMutex * logger_mutex
Definition logging.c:332
static void gvm_log_lock_init(void)
Initialize logger_mutex mutex if it was not done before.
Definition logging.c:338

References gvm_log_lock_init(), and logger_mutex.

Referenced by gvm_log_func().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvm_log_silent()

void gvm_log_silent ( const char * log_domain,
GLogLevelFlags log_level,
const char * message,
gpointer gvm_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.
gvm_log_config_listA pointer to the configuration linked list.

Definition at line 322 of file logging.c.

324{
325 (void) log_domain;
326 (void) log_level;
327 (void) message;
328 (void) gvm_log_config_list;
329 return;
330}

◆ gvm_log_unlock()

void gvm_log_unlock ( void )

Unlock logger_mutex.

Definition at line 363 of file logging.c.

364{
365 g_mutex_unlock (logger_mutex);
366}

References logger_mutex.

Referenced by gvm_log_func().

Here is the caller graph for this function:

◆ 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 161 of file logging.c.

162{
163 GKeyFile *key_file;
164 GKeyFileFlags flags;
165 GError *error = NULL;
166 /* key_file *_has_* functions requires this. */
167
168 // FIXME: If a g_* function that takes error fails, then free error.
169
170 /* Groups found in the conf file. */
171 gchar **groups;
172 /* Temp variable to iterate over groups. */
173 gchar **group;
174
175 /* The link list for the structure above and it's tmp helper */
176 GSList *log_domain_list = NULL;
177
178 /* Create a new GKeyFile object and a bitwise list of flags. */
179 key_file = g_key_file_new ();
180 flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;
181
182 /* Load the GKeyFile from conf or return. */
183 if (!g_key_file_load_from_file (key_file, config_file, flags, &error))
184 {
185 g_error ("%s: %s", config_file, error->message);
186 }
187
188 /* Get all the groups available. */
189 groups = g_key_file_get_groups (key_file, NULL);
190
191 /* Point to the group head. */
192 group = groups;
193 /* Iterate till we get to the end of the array. */
194 while (*group != NULL)
195 {
196 /* Structure to hold per group settings. */
197 gvm_logging_domain_t *log_domain_entry =
198 gvm_logging_domain_new (g_strdup (*group));
199
200 /* Look for the prepend string. */
201 if (g_key_file_has_key (key_file, *group, "prepend", &error))
202 {
204 log_domain_entry,
205 g_key_file_get_value (key_file, *group, "prepend", &error));
206 }
207
208 /* Look for the log_separator string. */
209 if (g_key_file_has_key (key_file, *group, "separator", &error))
210 {
212 log_domain_entry,
213 g_key_file_get_value (key_file, *group, "separator", &error));
214 }
215
216 /* Look for the prepend time format string. */
217 if (g_key_file_has_key (key_file, *group, "prepend_time_format", &error))
218 {
220 log_domain_entry,
221 g_key_file_get_value (key_file, *group, "prepend_time_format",
222 &error));
223 }
224
225 /* Look for the log file string. */
226 if (g_key_file_has_key (key_file, *group, "file", &error))
227 {
229 log_domain_entry,
230 g_key_file_get_value (key_file, *group, "file", &error));
231 }
232
233 /* Look for the prepend log level string. */
234 if (g_key_file_has_key (key_file, *group, "level", &error))
235 {
236 gchar *level;
237
238 level = g_key_file_get_value (key_file, *group, "level", &error);
239 level = g_strchug (level);
240 gvm_logging_domain_set_default_level (log_domain_entry,
241 level_int_from_string (level));
242 g_free (level);
243 }
244
245 /* Look for the syslog_facility string. */
246 if (g_key_file_has_key (key_file, *group, "syslog_facility", &error))
247 {
249 log_domain_entry,
250 g_key_file_get_value (key_file, *group, "syslog_facility", &error));
251 }
252 else
254 g_strdup ("local0"));
255
256 /* Look for the syslog_ident string. */
257 if (g_key_file_has_key (key_file, *group, "syslog_ident", &error))
258 {
260 log_domain_entry,
261 g_key_file_get_value (key_file, *group, "syslog_ident", &error));
262 }
263 else
264 gvm_logging_domain_set_syslog_ident (log_domain_entry,
265 g_strdup (*group));
266
267 /* Attach the struct to the list. */
268 log_domain_list = g_slist_prepend (log_domain_list, log_domain_entry);
269 group++;
270 }
271 /* Free the groups array. */
272 g_strfreev (groups);
273
274 /* Free the key file. */
275 g_key_file_free (key_file);
276
277 return log_domain_list;
278}
static gint level_int_from_string(const gchar *level)
Return the integer corresponding to a log level string.
Definition logging.c:104
void gvm_logging_domain_set_prepend_separator(gvm_logging_domain_t *log_domain, gchar *prepend_separator)
Sets the prepend separator for the logging domain.
void gvm_logging_domain_set_log_file(gvm_logging_domain_t *log_domain, gchar *log_file)
Sets the log file for the logging domain.
void gvm_logging_domain_set_syslog_ident(gvm_logging_domain_t *log_domain, gchar *syslog_ident)
Sets the syslog ident for the logging domain.
void gvm_logging_domain_set_prepend_time_format(gvm_logging_domain_t *log_domain, gchar *prepend_time_format)
Sets the prepend time format for the logging domain.
void gvm_logging_domain_set_syslog_facility(gvm_logging_domain_t *log_domain, gchar *syslog_facility)
Sets the syslog facility for the logging domain.
gvm_logging_domain_t * gvm_logging_domain_new(gchar *log_domain)
Function to initialize logging instance.
void gvm_logging_domain_set_prepend_string(gvm_logging_domain_t *log_domain, gchar *prepend_string)
Sets the preprend string for the logging domain.
void gvm_logging_domain_set_default_level(gvm_logging_domain_t *log_domain, GLogLevelFlags default_level)
Sets the default log level for the logging domain.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_func_for_gnutls()

void log_func_for_gnutls ( int level,
const char * message )

This function logs debug messages from gnutls.

Parameters
levelGnuTLS log level (integer from 0 to 99 according to GnuTLS documentation.
messageGnuTLS 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.

839{
840 g_log ("x gnutls", G_LOG_LEVEL_INFO, "tls(%d): %s", level, message);
841}

◆ set_log_reference()

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.

Parameters
ref

Definition at line 384 of file logging.c.

385{
386 if (reference)
387 g_free ((char *) reference);
388 reference = ref;
389}

References reference.

◆ set_log_tz()

void set_log_tz ( const gchar * tz)

Set the log timezone.

This is the timezone used for dates in log messages. If NULL then the current timezone is used.

Parameters
tzTimezone.

Definition at line 903 of file logging.c.

904{
905 g_free (log_tz);
906 log_tz = tz ? g_strdup (tz) : NULL;
907}

References log_tz.

◆ setup_log_handlers()

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.

Parameters
gvm_log_config_listA pointer to the configuration linked list.
Returns
0 on success, -1 if not able to create log file directory or open log file for some domain.

Definition at line 981 of file logging.c.

982{
983 return setup_log_handlers_internal (gvm_log_config_list, gvm_log_func,
985}
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.
Definition logging.c:428
static int setup_log_handlers_internal(GSList *gvm_log_config_list, GLogFunc log_func, GLogFunc default_log_func, GLogFunc default_domain_log_func)
Definition logging.c:910

References gvm_log_func(), and setup_log_handlers_internal().

Here is the call graph for this function: