blob: b067c807a7d20746460b8fbfc7502d0bb78496ec [file] [log] [blame]
Mickey Sweatt617d2d42016-04-25 22:02:08 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3* Copyright (c) 2016 Regents of the University of California.
4*
5* This file is part of the nTorrent codebase.
6*
7* nTorrent is free software: you can redistribute it and/or modify it under the
8* terms of the GNU Lesser General Public License as published by the Free Software
9* Foundation, either version 3 of the License, or (at your option) any later version.
10*
11* nTorrent is distributed in the hope that it will be useful, but WITHOUT ANY
12* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14*
15* You should have received copies of the GNU General Public License and GNU Lesser
16* General Public License along with nTorrent, e.g., in COPYING.md file. If not, see
17* <http://www.gnu.org/licenses/>.
18*
19* See AUTHORS for complete list of nTorrent authors and contributors.
20*/
21
22
23#include "util/logging.hpp"
24
25#include <boost/date_time/posix_time/posix_time_types.hpp>
26#include <boost/log/core.hpp>
27#include <boost/log/expressions.hpp>
28#include <boost/log/sinks/text_file_backend.hpp>
29#include <boost/log/sources/record_ostream.hpp>
30#include <boost/log/sources/severity_logger.hpp>
31#include <boost/log/support/date_time.hpp>
32#include <boost/log/trivial.hpp>
33#include <boost/log/utility/setup/file.hpp>
34
35// ===== log macros =====
36namespace logging = boost::log;
37namespace src = boost::log::sources;
38namespace sinks = boost::log::sinks;
39namespace keywords = boost::log::keywords;
40namespace expr = boost::log::expressions;
41
42namespace ndn {
43namespace ntorrent {
44
45void LoggingUtil::init()
46{
47 logging::core::get()->set_filter
48 (
49 logging::trivial::severity >= SEVERITY_THRESHOLD
50 );
51
52 logging::add_file_log
53 (
54 keywords::file_name = "sample_%N.log", // < file name pattern >
55 keywords::rotation_size = 10 * 1024 * 1024, // < rotate files every 10 MiB... >
56 keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), // < ...or at midnight >
57 keywords::format = // < log record format >
58 (
59 expr::stream
60 << expr::attr< unsigned int >("LineID")
61 << ": [" << expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S") << "]"
62 << ": <" << logging::trivial::severity
63 << "> " << expr::smessage
64 )
65 );
66}
67
68} // end ntorrent
69} // end ndn
70
71