logging_domain.c
Go to the documentation of this file.
/* SPDX-FileCopyrightText: 2025 Greenbone AG
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "logging_domain.h"
struct gvm_logging_domain
{
gchar *log_domain;
gchar *prepend_string;
gchar *prepend_time_format;
gchar *log_file;
GLogLevelFlags *default_level;
GIOChannel *log_channel;
gchar *syslog_facility;
gchar *syslog_ident;
gchar *prepend_separator;
};
gvm_logging_domain_t *
gvm_logging_domain_new (gchar *log_domain)
{
gvm_logging_domain_t *log_domain_entry;
/* Create the struct. */
log_domain_entry = g_malloc (sizeof (gvm_logging_domain_t));
/* Set the logdomain. */
log_domain_entry->log_domain = log_domain;
/* Initialize everything else to NULL. */
log_domain_entry->prepend_string = NULL;
log_domain_entry->prepend_time_format = NULL;
log_domain_entry->log_file = NULL;
log_domain_entry->default_level = NULL;
log_domain_entry->log_channel = NULL;
log_domain_entry->syslog_facility = NULL;
log_domain_entry->syslog_ident = NULL;
log_domain_entry->prepend_separator = NULL;
return log_domain_entry;
}
void
gvm_logging_domain_free (gvm_logging_domain_t *log_domain)
{
g_free (log_domain->log_domain);
g_free (log_domain->prepend_string);
g_free (log_domain->prepend_time_format);
g_free (log_domain->log_file);
g_free (log_domain->default_level);
g_free (log_domain->syslog_ident);
g_free (log_domain->prepend_separator);
/* Drop the reference to the GIOChannel. */
if (log_domain->log_channel)
g_io_channel_unref (log_domain->log_channel);
/* Free the struct. */
g_free (log_domain);
}
gchar *
gvm_logging_domain_get_log_domain (gvm_logging_domain_t *log_domain)
{
return log_domain->log_domain;
}
gchar *
gvm_logging_domain_get_log_file (gvm_logging_domain_t *log_domain)
{
return log_domain->log_file;
}
void
gvm_logging_domain_set_log_file (gvm_logging_domain_t *log_domain,
gchar *log_file)
{
g_free (log_domain->log_file);
log_domain->log_file = log_file;
}
gchar *
gvm_logging_domain_get_prepend_string (gvm_logging_domain_t *log_domain)
{
return log_domain->prepend_string;
}
void
gvm_logging_domain_set_prepend_string (gvm_logging_domain_t *log_domain,
gchar *prepend_string)
{
g_free (log_domain->prepend_string);
log_domain->prepend_string = prepend_string;
}
gchar *
gvm_logging_domain_get_prepend_time_format (gvm_logging_domain_t *log_domain)
{
return log_domain->prepend_time_format;
}
void
gvm_logging_domain_set_prepend_time_format (gvm_logging_domain_t *log_domain,
gchar *prepend_time_format)
{
g_free (log_domain->prepend_time_format);
log_domain->prepend_time_format = prepend_time_format;
}
GLogLevelFlags *
gvm_logging_domain_get_default_level (gvm_logging_domain_t *log_domain)
{
return log_domain->default_level;
}
void
gvm_logging_domain_set_default_level (gvm_logging_domain_t *log_domain,
GLogLevelFlags default_level)
{
g_free (log_domain->default_level);
log_domain->default_level = g_malloc (sizeof (gint));
*log_domain->default_level = default_level;
}
gchar *
gvm_logging_domain_get_syslog_facility (gvm_logging_domain_t *log_domain)
{
return log_domain->syslog_facility;
}
void
gvm_logging_domain_set_syslog_facility (gvm_logging_domain_t *log_domain,
gchar *syslog_facility)
{
g_free (log_domain->syslog_facility);
log_domain->syslog_facility = syslog_facility;
}
gchar *
gvm_logging_domain_get_syslog_ident (gvm_logging_domain_t *log_domain)
{
return log_domain->syslog_ident;
}
void
gvm_logging_domain_set_syslog_ident (gvm_logging_domain_t *log_domain,
gchar *syslog_ident)
{
g_free (log_domain->syslog_ident);
log_domain->syslog_ident = syslog_ident;
}
gchar *
gvm_logging_domain_get_prepend_separator (gvm_logging_domain_t *log_domain)
{
return log_domain->prepend_separator;
}
void
gvm_logging_domain_set_prepend_separator (gvm_logging_domain_t *log_domain,
gchar *prepend_separator)
{
g_free (log_domain->prepend_separator);
log_domain->prepend_separator = prepend_separator;
}
GIOChannel *
gvm_logging_domain_get_log_channel (gvm_logging_domain_t *log_domain)
{
return log_domain->log_channel;
}
void
gvm_logging_domain_set_log_channel (gvm_logging_domain_t *log_domain,
GIOChannel *log_channel)
{
if (log_domain->log_channel)
g_io_channel_unref (log_domain->log_channel);
log_domain->log_channel = log_channel;
if (log_channel)
g_io_channel_ref (log_channel);
}
gvm_logging_domain_set_prepend_separator
void gvm_logging_domain_set_prepend_separator(gvm_logging_domain_t *log_domain, gchar *prepend_separator)
Sets the prepend separator for the logging domain.
Definition logging_domain.c:337
gvm_logging_domain_get_log_channel
GIOChannel * gvm_logging_domain_get_log_channel(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:355
gvm_logging_domain_set_log_file
void gvm_logging_domain_set_log_file(gvm_logging_domain_t *log_domain, gchar *log_file)
Sets the log file for the logging domain.
Definition logging_domain.c:133
gvm_logging_domain_set_syslog_ident
void gvm_logging_domain_set_syslog_ident(gvm_logging_domain_t *log_domain, gchar *syslog_ident)
Sets the syslog ident for the logging domain.
Definition logging_domain.c:303
gvm_logging_domain_set_prepend_time_format
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.
Definition logging_domain.c:202
gvm_logging_domain_set_syslog_facility
void gvm_logging_domain_set_syslog_facility(gvm_logging_domain_t *log_domain, gchar *syslog_facility)
Sets the syslog facility for the logging domain.
Definition logging_domain.c:270
gvm_logging_domain_get_default_level
GLogLevelFlags * gvm_logging_domain_get_default_level(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:220
gvm_logging_domain_new
gvm_logging_domain_t * gvm_logging_domain_new(gchar *log_domain)
Function to initialize logging instance.
Definition logging_domain.c:40
gvm_logging_domain_get_prepend_time_format
gchar * gvm_logging_domain_get_prepend_time_format(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:185
gvm_logging_domain_get_syslog_ident
gchar * gvm_logging_domain_get_syslog_ident(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:288
gvm_logging_domain_set_log_channel
void gvm_logging_domain_set_log_channel(gvm_logging_domain_t *log_domain, GIOChannel *log_channel)
Sets the log channel for the logging domain.
Definition logging_domain.c:370
gvm_logging_domain_free
void gvm_logging_domain_free(gvm_logging_domain_t *log_domain)
Frees the resources associated with the given logging domain.
Definition logging_domain.c:72
gvm_logging_domain_get_log_file
gchar * gvm_logging_domain_get_log_file(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:117
gvm_logging_domain_set_prepend_string
void gvm_logging_domain_set_prepend_string(gvm_logging_domain_t *log_domain, gchar *prepend_string)
Sets the preprend string for the logging domain.
Definition logging_domain.c:167
gvm_logging_domain_get_log_domain
gchar * gvm_logging_domain_get_log_domain(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:101
gvm_logging_domain_set_default_level
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.
Definition logging_domain.c:235
gvm_logging_domain_get_prepend_separator
gchar * gvm_logging_domain_get_prepend_separator(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:321
gvm_logging_domain_get_prepend_string
gchar * gvm_logging_domain_get_prepend_string(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:151
gvm_logging_domain_get_syslog_facility
gchar * gvm_logging_domain_get_syslog_facility(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:254
logging_domain.h
Implementation of logging domain handling.
gvm_logging_domain
Definition logging_domain.c:14
gvm_logging_domain::default_level
GLogLevelFlags * default_level
What severity level to use as default.
Definition logging_domain.c:19
gvm_logging_domain::log_channel
GIOChannel * log_channel
Gio Channel - FD holder for logfile.
Definition logging_domain.c:20
gvm_logging_domain::log_domain
gchar * log_domain
Affected logdomain e.g libnasl.
Definition logging_domain.c:15
gvm_logging_domain::log_file
gchar * log_file
Where to log to.
Definition logging_domain.c:18
gvm_logging_domain::syslog_facility
gchar * syslog_facility
Syslog facility to use for syslog logging.
Definition logging_domain.c:21
gvm_logging_domain::syslog_ident
gchar * syslog_ident
Syslog ident to use for syslog logging.
Definition logging_domain.c:22
gvm_logging_domain::prepend_separator
gchar * prepend_separator
Definition logging_domain.c:23
gvm_logging_domain::prepend_time_format
gchar * prepend_time_format
If prependstring has t, format for strftime.
Definition logging_domain.c:17
gvm_logging_domain::prepend_string
gchar * prepend_string
Prepend this string before every message.
Definition logging_domain.c:16