Greenbone Vulnerability Management Libraries: base/logging_domain.c Source File

Greenbone Vulnerability Management Libraries 23.1.2

logging_domain.c
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Greenbone AG
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
6#include "logging_domain.h"
7
13 struct gvm_logging_domain
14{
15 gchar *log_domain;
16 gchar *prepend_string;
17 gchar *prepend_time_format;
18 gchar *log_file;
19 GLogLevelFlags *default_level;
20 GIOChannel *log_channel;
21 gchar *syslog_facility;
22 gchar *syslog_ident;
23 gchar *prepend_separator;
25};
26
39 gvm_logging_domain_t *
40gvm_logging_domain_new (gchar *log_domain)
41{
42 gvm_logging_domain_t *log_domain_entry;
43 /* Create the struct. */
44 log_domain_entry = g_malloc (sizeof (gvm_logging_domain_t));
45 /* Set the logdomain. */
46 log_domain_entry->log_domain = log_domain;
47 /* Initialize everything else to NULL. */
48 log_domain_entry->prepend_string = NULL;
49 log_domain_entry->prepend_time_format = NULL;
50 log_domain_entry->log_file = NULL;
51 log_domain_entry->default_level = NULL;
52 log_domain_entry->log_channel = NULL;
53 log_domain_entry->syslog_facility = NULL;
54 log_domain_entry->syslog_ident = NULL;
55 log_domain_entry->prepend_separator = NULL;
56
57 return log_domain_entry;
58}
59
71void
72gvm_logging_domain_free (gvm_logging_domain_t *log_domain)
73{
74 if (log_domain == NULL)
75 return;
76
77 g_free (log_domain->log_domain);
78 g_free (log_domain->prepend_string);
79 g_free (log_domain->prepend_time_format);
80 g_free (log_domain->log_file);
81 g_free (log_domain->default_level);
82 g_free (log_domain->syslog_facility);
83 g_free (log_domain->syslog_ident);
84 g_free (log_domain->prepend_separator);
85
86 /* Drop the reference to the GIOChannel. */
87 if (log_domain->log_channel)
88 g_io_channel_unref (log_domain->log_channel);
89
90 /* Free the struct. */
91 g_free (log_domain);
92}
93
104gchar *
105gvm_logging_domain_get_log_domain (gvm_logging_domain_t *log_domain)
106{
107 return log_domain->log_domain;
108}
109
120gchar *
121gvm_logging_domain_get_log_file (gvm_logging_domain_t *log_domain)
122{
123 return log_domain->log_file;
124}
125
136void
137gvm_logging_domain_set_log_file (gvm_logging_domain_t *log_domain,
138 gchar *log_file)
139{
140 g_free (log_domain->log_file);
141 log_domain->log_file = log_file;
142}
143
154gchar *
155gvm_logging_domain_get_prepend_string (gvm_logging_domain_t *log_domain)
156{
157 return log_domain->prepend_string;
158}
159
170void
171gvm_logging_domain_set_prepend_string (gvm_logging_domain_t *log_domain,
172 gchar *prepend_string)
173{
174 g_free (log_domain->prepend_string);
175 log_domain->prepend_string = prepend_string;
176}
177
188gchar *
189gvm_logging_domain_get_prepend_time_format (gvm_logging_domain_t *log_domain)
190{
191 return log_domain->prepend_time_format;
192}
193
205void
206gvm_logging_domain_set_prepend_time_format (gvm_logging_domain_t *log_domain,
207 gchar *prepend_time_format)
208{
209 g_free (log_domain->prepend_time_format);
210 log_domain->prepend_time_format = prepend_time_format;
211}
212
223GLogLevelFlags *
224gvm_logging_domain_get_default_level (gvm_logging_domain_t *log_domain)
225{
226 return log_domain->default_level;
227}
228
238void
239gvm_logging_domain_set_default_level (gvm_logging_domain_t *log_domain,
240 GLogLevelFlags default_level)
241{
242 g_free (log_domain->default_level);
243 log_domain->default_level = g_malloc (sizeof (gint));
244 *log_domain->default_level = default_level;
245}
246
257gchar *
258gvm_logging_domain_get_syslog_facility (gvm_logging_domain_t *log_domain)
259{
260 return log_domain->syslog_facility;
261}
262
273void
274gvm_logging_domain_set_syslog_facility (gvm_logging_domain_t *log_domain,
275 gchar *syslog_facility)
276{
277 g_free (log_domain->syslog_facility);
278 log_domain->syslog_facility = syslog_facility;
279}
280
291gchar *
292gvm_logging_domain_get_syslog_ident (gvm_logging_domain_t *log_domain)
293{
294 return log_domain->syslog_ident;
295}
296
306void
307gvm_logging_domain_set_syslog_ident (gvm_logging_domain_t *log_domain,
308 gchar *syslog_ident)
309{
310 g_free (log_domain->syslog_ident);
311 log_domain->syslog_ident = syslog_ident;
312}
313
324gchar *
325gvm_logging_domain_get_prepend_separator (gvm_logging_domain_t *log_domain)
326{
327 return log_domain->prepend_separator;
328}
329
340void
341gvm_logging_domain_set_prepend_separator (gvm_logging_domain_t *log_domain,
342 gchar *prepend_separator)
343{
344 g_free (log_domain->prepend_separator);
345 log_domain->prepend_separator = prepend_separator;
346}
347
358GIOChannel *
359gvm_logging_domain_get_log_channel (gvm_logging_domain_t *log_domain)
360{
361 return log_domain->log_channel;
362}
363
373void
374gvm_logging_domain_set_log_channel (gvm_logging_domain_t *log_domain,
375 GIOChannel *log_channel)
376{
377 if (log_domain->log_channel)
378 g_io_channel_unref (log_domain->log_channel);
379 log_domain->log_channel = log_channel;
380 if (log_channel)
381 g_io_channel_ref (log_channel);
382}
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:341
gvm_logging_domain_get_log_channel
GIOChannel * gvm_logging_domain_get_log_channel(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:359
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:137
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:307
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:206
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:274
gvm_logging_domain_get_default_level
GLogLevelFlags * gvm_logging_domain_get_default_level(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:224
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:189
gvm_logging_domain_get_syslog_ident
gchar * gvm_logging_domain_get_syslog_ident(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:292
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:374
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:121
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:171
gvm_logging_domain_get_log_domain
gchar * gvm_logging_domain_get_log_domain(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:105
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:239
gvm_logging_domain_get_prepend_separator
gchar * gvm_logging_domain_get_prepend_separator(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:325
gvm_logging_domain_get_prepend_string
gchar * gvm_logging_domain_get_prepend_string(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:155
gvm_logging_domain_get_syslog_facility
gchar * gvm_logging_domain_get_syslog_facility(gvm_logging_domain_t *log_domain)
Definition logging_domain.c:258
logging_domain.h
Implementation of logging domain handling.
gvm_logging_domain_t
struct gvm_logging_domain gvm_logging_domain_t
Definition logging_domain.h:15
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