logging: rework a bit, maybe support syslog
Seems journal logging fails on NetBSD (no surprise), but has some unwanted/not-fully-understood side-effects. In any case, outside Linux there's no use in even trying to use journald; so we don't do that anymore. Add conditional support for syslog (requires glib 2.80).
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2020-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2020-2024 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
@ -17,6 +17,9 @@
|
||||
**
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "mu-logger.hh"
|
||||
|
||||
#define G_LOG_USE_STRUCTURED
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
@ -31,8 +34,6 @@
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
#include "mu-logger.hh"
|
||||
|
||||
using namespace Mu;
|
||||
|
||||
static bool MuLogInitialized = false;
|
||||
@ -118,10 +119,29 @@ log_stdouterr(GLogLevelFlags level, const GLogField* fields, gsize n_fields, gpo
|
||||
return g_log_writer_standard_streams(level, fields, n_fields, user_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// log to some logging system; the one that is available & works of journal,
|
||||
// syslog, file.
|
||||
static GLogWriterOutput
|
||||
log_journal(GLogLevelFlags level, const GLogField* fields, gsize n_fields, gpointer user_data)
|
||||
log_system(GLogLevelFlags level, const GLogField* fields, gsize n_fields, gpointer user_data)
|
||||
{
|
||||
return g_log_writer_journald(level, fields, n_fields, user_data);
|
||||
GLogWriterOutput res = G_LOG_WRITER_UNHANDLED;
|
||||
|
||||
#ifdef MAYBE_USE_JOURNAL
|
||||
res = g_log_writer_journald(level, fields, n_fields, user_data);
|
||||
if (res == G_LOG_WRITER_HANDLED)
|
||||
return res;
|
||||
#endif /*MAYBE_USE_JOURNAL*/
|
||||
|
||||
#ifdef MAYBE_USE_SYSLOG
|
||||
/* since glib 2.80 */
|
||||
res = g_log_writer_syslog(level, fields, n_fields, user_data);
|
||||
if (res == G_LOG_WRITER_HANDLED)
|
||||
return res;
|
||||
#endif /*MAYBE_USE_SYSLOG*/
|
||||
|
||||
return res = log_file(level, fields, n_fields, user_data);
|
||||
}
|
||||
|
||||
|
||||
@ -156,11 +176,10 @@ Mu::Logger::Logger(const std::string& path, Mu::Logger::Options opts)
|
||||
}
|
||||
|
||||
// log to the journal, or, if not available to a file.
|
||||
if (any_of(MuLogOptions & Options::File) ||
|
||||
log_journal(level, fields, n_fields, user_data) != G_LOG_WRITER_HANDLED)
|
||||
return log_file(level, fields, n_fields, user_data);
|
||||
else
|
||||
return G_LOG_WRITER_HANDLED;
|
||||
if (any_of(MuLogOptions & Options::File))
|
||||
return log_file(level, fields, n_fields, user_data);
|
||||
|
||||
return log_system(level, fields, n_fields, user_data);
|
||||
},
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
@ -50,7 +50,7 @@ test('test-logger',
|
||||
executable('test-logger', '../mu-logger.cc',
|
||||
install: false,
|
||||
cpp_args: ['-DBUILD_TESTS'],
|
||||
dependencies: [glib_dep, lib_mu_utils_dep, thread_dep ]))
|
||||
dependencies: [glib_dep, lib_mu_utils_dep,config_h_dep,thread_dep ]))
|
||||
|
||||
test('test-option',
|
||||
executable('test-option', '../mu-option.cc',
|
||||
|
||||
19
meson.build
19
meson.build
@ -203,6 +203,23 @@ if xapver.version_compare('>= 1.4.23')
|
||||
config_h_data.set('HAVE_XAPIAN_FLAG_NGRAMS', 1)
|
||||
endif
|
||||
|
||||
host_system = host_machine.system()
|
||||
#
|
||||
# soft dependencies
|
||||
#
|
||||
|
||||
|
||||
# logging
|
||||
|
||||
# if we're on a linux machine, perhaps there's systemd/journald.
|
||||
# otherwise, we don't bother.
|
||||
if host_machine.system() == 'linux'
|
||||
config_h_data.set('MAYBE_USE_JOURNAL', 1)
|
||||
endif
|
||||
if cc.has_function('g_log_writer_syslog',dependencies: glib_dep)
|
||||
config_h_data.set('MAYBE_USE_SYSLOG', 1)
|
||||
endif
|
||||
|
||||
# optionally, use Compact Language Detector2 if we can find it.
|
||||
cld2_dep = meson.get_compiler('cpp').find_library('cld2', required: get_option('cld2'))
|
||||
if not get_option('cld2').disabled() and cld2_dep.found()
|
||||
@ -211,7 +228,7 @@ else
|
||||
message('CLD2 not found or disabled; no support for language detection')
|
||||
endif
|
||||
|
||||
# soft dependencies
|
||||
# guile
|
||||
guile_dep = dependency('guile-3.0', required: get_option('guile'))
|
||||
# allow for a custom guile-extension-dir
|
||||
if guile_dep.found()
|
||||
|
||||
Reference in New Issue
Block a user