17#include <boost/date_time/posix_time/posix_time.hpp>
38 if (!parameters || !parameters->get(
"type") ||
39 parameters->get(
"type")->stringValue() ==
"logfile") {
58 for (
char const*
const& key : {
59 "type",
"user",
"password",
"host",
"name",
"trust-anchor",
60 "cert-file",
"key-file",
"cipher-list" }) {
63 db_parameters.emplace(key, value->stringValue());
68 for (
char const*
const& key : {
69 "connect-timeout",
"reconnect-wait-time",
"max-reconnect-tries"}) {
72 int64_t integer_value(value->intValue());
73 auto const max(numeric_limits<uint32_t>::max());
74 if (integer_value < 0 || max < integer_value) {
76 key <<
" value: " << integer_value
77 <<
" is out of range, expected value: 0.."
81 boost::lexical_cast<string>(integer_value);
85 string param_name =
"tcp-nodelay";
88 db_parameters.emplace(param_name,
89 param->boolValue() ?
"true" :
"false");
95 param_name =
"on-fail";
96 param = parameters->get(param_name);
98 on_fail_action = param->stringValue();
101 db_parameters.emplace(param_name, on_fail_action);
103 param_name =
"retry-on-startup";
104 param = parameters->get(param_name);
106 db_parameters.emplace(param_name,
107 param->boolValue() ?
"true" :
"false");
112 param = parameters->get(param_name);
114 port = param->intValue();
115 if ((port < 0) || (port > numeric_limits<uint16_t>::max())) {
117 <<
" is out of range, expected value: 0.."
118 << numeric_limits<uint16_t>::max());
120 db_parameters.emplace(param_name,
121 boost::lexical_cast<string>(port));
127 string const db_type(db_parameters[
"type"]);
134 file_parameters[
"type"] =
"logfile";
137 map = file_parameters;
142 for (
char const*
const& key : {
"path",
"base-name",
"time-unit",
"prerotate",
"postrotate" }) {
145 file_parameters.emplace(key, value->stringValue());
150 for (
char const*
const& key : {
"count" }) {
153 int64_t integer_value(value->intValue());
154 auto const max(numeric_limits<uint32_t>::max());
155 if (integer_value < 0 || max < integer_value) {
157 key <<
" value: " << integer_value
158 <<
" is out of range, expected value: 0.."
161 file_parameters[key] = boost::lexical_cast<string>(integer_value);
164 map = file_parameters;
174 for (
char const*
const& key : {
"request-parser-format",
"response-parser-format",
"timestamp-format" }) {
176 if (value && !value->stringValue().empty()) {
177 map.emplace(key, value->stringValue());
185 struct timespec timestamp = now();
186 localtime_r(×tamp.tv_sec, &time_info);
193 clock_gettime(CLOCK_REALTIME, &now);
216 string tmp_format = format;
217 for (
auto it = tmp_format.begin(); it < tmp_format.end(); ++it) {
218 if (*it ==
'%' && ((it + 1) < tmp_format.end())) {
219 if (*(it + 1) ==
'Q') {
221 string::size_type pos = it - tmp_format.begin();
224 usec << setw(6) << setfill(
'0') << (time.tv_nsec / 1000);
225 string microseconds = usec.str();
226 microseconds.insert(3, 1,
'.');
227 tmp_format.replace(it, it + 2, microseconds);
229 it = tmp_format.begin() + pos + microseconds.length() - 1;
238 localtime_r(&time.tv_sec, &time_info);
240 if (!strftime(buffer,
sizeof(buffer), tmp_format.c_str(), &time_info)) {
242 "strftime returned 0. Maybe the timestamp format '"
244 <<
"' result is too long, maximum length allowed: "
247 return (
string(buffer));
256 if (secs == 0xffffffff) {
257 return (
"infinite duration");
260 uint32_t seconds = secs % 60;
261 uint32_t remainder = secs / 60;
262 uint32_t minutes = remainder % 60;
264 uint32_t hours = remainder % 24;
265 uint32_t days = remainder / 24;
270 os << days <<
" days ";
273 os << hours <<
" hrs "
274 << minutes <<
" mins "
275 << seconds <<
" secs";
282 const string& delimiter) {
286 for (
auto const& it : bytes) {
290 tmp << setw(2) << setfill('0') << static_cast<unsigned int>(it);
301 return (
string(bytes.cbegin(), bytes.cend()));
332 timestamp_format_ = timestamp_format;
343 return (
"unknown-action");
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
static std::string redactedAccessString(const ParameterMap ¶meters)
Redact database access string.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
static CfgMgr & instance()
returns a single instance of Configuration Manager
Thrown if a LegalLogMgr encounters an error.
LegalLogMgr abstract class.
void setRequestFormatExpression(const std::string &extended_format)
Sets request extended format expression for custom logging.
static void parseFile(const isc::data::ConstElementPtr ¶meters, isc::db::DatabaseConnection::ParameterMap &map)
Parse file specification.
static std::string vectorHexDump(const std::vector< uint8_t > &bytes, const std::string &delimiter=":")
Creates a string of hex digit pairs from a vector of bytes.
static void parseDatabase(const isc::data::ConstElementPtr ¶meters, isc::db::DatabaseConnection::ParameterMap &map)
Parse database specification.
void setResponseFormatExpression(const std::string &extended_format)
Sets response extended format expression for custom logging.
static std::string genDurationString(const uint32_t secs)
Translates seconds into a text string of days, hours, minutes and seconds.
virtual struct timespec now() const
Returns the current system time.
static std::string getTimeString(const struct timespec &time, const std::string &format)
Returns a time as string.
static std::string vectorDump(const std::vector< uint8_t > &bytes)
Creates a string from a vector of printable bytes.
static void parseConfig(const isc::data::ConstElementPtr ¶meters, isc::db::DatabaseConnection::ParameterMap &map)
Parse database specification.
void setTimestampFormat(const std::string ×tamp_format)
Sets the timestamp format used for logging.
static void parseExtraParameters(const isc::data::ConstElementPtr ¶meters, isc::db::DatabaseConnection::ParameterMap &map)
Parse extra parameters which are not related to backend connection.
virtual std::string getNowString() const
Returns the current date and time as string.
Universe
defines option universe DHCPv4 or DHCPv6
Evaluation context, an interface to the expression evaluation.
bool parseString(const std::string &str, ParserType type=PARSER_BOOL)
Run the parser on the string specified.
@ PARSER_STRING
expression is expected to evaluate to string
isc::dhcp::Expression expression_
Parsed expression (output tokens are stored here)
static std::string onFailActionToText(OnFailAction action)
Convert action to string.
static OnFailAction onFailActionFromText(const std::string &text)
Convert string to action.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the abstract class for backend stores.
boost::shared_ptr< const Element > ConstElementPtr
const string actionToVerb(Action action)
Translates an Action into its corresponding verb.
std::vector< TokenPtr > Expression
This is a structure that holds an expression converted to RPN.
Action
Describe what kind of event is being logged.
Defines the logger used by the top-level component of kea-lfc.