summaryrefslogtreecommitdiffstats
path: root/src/lib/log/output_option.cc
blob: 0073c7fab887ff747b9f57bf8d3d32de1344d3ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (C) 2011-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <config.h>

#include <string>

#include <boost/algorithm/string.hpp>

#include <log/log_messages.h>
#include <log/macros.h>
#include <log/output_option.h>

namespace isc {
namespace log {

/// Default layout pattern for console logs
const std::string OutputOption::DEFAULT_CONSOLE_PATTERN = "%D{%Y-%m-%d %H:%M:%S.%q} %-5p [%c/%i.%t] %m\n";

/// Default layout pattern for file logs
const std::string OutputOption::DEFAULT_FILE_PATTERN = "%D{%Y-%m-%d %H:%M:%S.%q} %-5p [%c/%i.%t] %m\n";

/// Default layout pattern for syslog logs
const std::string OutputOption::DEFAULT_SYSLOG_PATTERN = "%-5p [%c.%t] %m\n";

OutputOption::Destination
getDestination(const std::string& dest_str) {
    if (boost::iequals(dest_str, "console")) {
        return OutputOption::DEST_CONSOLE;
    } else if (boost::iequals(dest_str, "file")) {
        return OutputOption::DEST_FILE;
    } else if (boost::iequals(dest_str, "syslog")) {
        return OutputOption::DEST_SYSLOG;
    } else {
        Logger logger("log");
        LOG_ERROR(logger, LOG_BAD_DESTINATION).arg(dest_str);
        return OutputOption::DEST_CONSOLE;
    }
}

OutputOption::Stream
getStream(const std::string& stream_str) {
    if (boost::iequals(stream_str, "stderr")) {
        return OutputOption::STR_STDERR;
    } else if (boost::iequals(stream_str, "stdout")) {
        return OutputOption::STR_STDOUT;
    } else {
        Logger logger("log");
        LOG_ERROR(logger, LOG_BAD_STREAM).arg(stream_str);
        return OutputOption::STR_STDOUT;
    }
}

} // namespace log
} // namespace isc