Kea: legal_syslog.cc Source File

| Kea 3.2.0-git

legal_syslog.cc
Go to the documentation of this file.
1// Copyright (C) 2025 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <dhcpsrv/cfgmgr.h>
10#include <legal_log_log.h>
11#include <legal_syslog.h>
12#include <log/logger_manager.h>
13#include <log/message_initializer.h>
14#include <log/macros.h>
15#include <process/logging_info.h>
16
17using namespace isc;
18using namespace isc::db;
19using namespace isc::dhcp;
20using namespace isc::log;
21using namespace isc::process;
22using namespace std;
23
24namespace isc {
25namespace legal_log {
26
27LegalSyslog::LegalSyslog(const DatabaseConnection::ParameterMap& parameters)
28 : LegalLogMgr(parameters) {
29 LoggingInfo info;
30 // Remove default destinations as we are going to replace them.
31 info.clearDestinations();
39 info.name_ = "legal-log-";
40 info.name_ += boost::lexical_cast<std::string>(reinterpret_cast<uint64_t>(this));
41 logger_.reset(new Logger(info.name_.c_str()));
42 LoggingDestination dest;
43 dest.output_ = "syslog:";
44 if (parameters.find("facility") != parameters.end()) {
45 dest.output_ += parameters.at("facility");
46 } else {
47 dest.output_ += "LOCAL0";
48 }
49 if (parameters.find("pattern") != parameters.end()) {
50 dest.pattern_ = parameters.at("pattern");
51 }
52 info.destinations_.push_back(dest);
53 CfgMgr::instance().getStagingCfg()->addLoggingInfo(info);
54}
55
56void
57LegalSyslog::open() {
58}
59
60void
61LegalSyslog::close() {
62}
63
64void
65LegalSyslog::writeln(const string& text, const string&) {
66 LOG_INFO(*logger_, LEGAL_LOG_SYSLOG)
67 .arg(text);
68}
69
70string
71LegalSyslog::getType() const {
72 return ("syslog");
73}
74
75 LegalLogMgrPtr
76LegalSyslog::factory(const DatabaseConnection::ParameterMap& parameters) {
77 LOG_INFO(legal_log_logger, LEGAL_LOG_SYSLOG_STORE_OPEN)
78 .arg(DatabaseConnection::redactedAccessString(parameters));
79 return (LegalLogMgrPtr(new LegalSyslog(parameters)));
80}
81
82} // namespace legal_log
83} // namespace isc
cfgmgr.h
isc::db::DatabaseConnection::redactedAccessString
static std::string redactedAccessString(const ParameterMap &parameters)
Redact database access string.
Definition database_connection.cc:108
isc::db::DatabaseConnection::ParameterMap
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Definition database_connection.h:137
isc::dhcp::CfgMgr::instance
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition cfgmgr.cc:29
isc::dhcp::CfgMgr::getStagingCfg
SrvConfigPtr getStagingCfg()
Returns a pointer to the staging configuration.
Definition cfgmgr.cc:121
isc::dhcp::LegalLogMgr::LegalLogMgr
LegalLogMgr(const isc::db::DatabaseConnection::ParameterMap parameters)
Constructor.
Definition legal_log_mgr.h:45
isc::legal_log::LegalSyslog::getType
virtual std::string getType() const
Return backend type.
Definition legal_syslog.cc:71
isc::legal_log::LegalSyslog::LegalSyslog
LegalSyslog(const isc::db::DatabaseConnection::ParameterMap &parameters)
Constructor.
Definition legal_syslog.cc:27
isc::legal_log::LegalSyslog::writeln
virtual void writeln(const std::string &text, const std::string &addr)
Appends a string to the store with a timestamp and address.
Definition legal_syslog.cc:65
isc::legal_log::LegalSyslog::factory
static isc::dhcp::LegalLogMgrPtr factory(const isc::db::DatabaseConnection::ParameterMap &parameters)
Factory class method.
Definition legal_syslog.cc:76
isc::legal_log::LegalSyslog::close
virtual void close()
Closes the store.
Definition legal_syslog.cc:61
isc::legal_log::LegalSyslog::open
virtual void open()
Opens the store.
Definition legal_syslog.cc:57
isc::log::Logger
Logger Class.
Definition log/logger.h:142
isc::process::LoggingInfo
structure that describes one logging entry
Definition logging_info.h:81
legal_log_log.h
LEGAL_LOG_SYSLOG
const isc::log::MessageID LEGAL_LOG_SYSLOG
LEGAL_LOG_SYSLOG_STORE_OPEN
const isc::log::MessageID LEGAL_LOG_SYSLOG_STORE_OPEN
legal_syslog.h
logger_manager.h
logging_info.h
macros.h
LOG_INFO
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition macros.h:20
message_initializer.h
isc::db
Definition audit_entry.cc:14
isc::db::info
@ info
Definition db_log.h:126
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::LegalLogMgrPtr
boost::shared_ptr< LegalLogMgr > LegalLogMgrPtr
Defines a smart pointer to a LegalLogMgr.
Definition legal_log_mgr.h:36
isc::legal_log
Definition legal_log_log.cc:13
isc::legal_log::legal_log_logger
isc::log::Logger legal_log_logger("legal-log-hooks")
Legal Log Logger.
Definition legal_log_log.h:22
isc::log
Definition buffer_appender_impl.cc:17
isc::process
Definition cb_ctl_base.h:22
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
isc::process::LoggingDestination
Defines single logging destination.
Definition logging_info.h:23
isc::process::LoggingDestination::output_
std::string output_
defines logging destination output
Definition logging_info.h:30
isc::process::LoggingDestination::pattern_
std::string pattern_
defines the log format pattern It dictates what additional elements are output
Definition logging_info.h:43