Mickey Sweatt | 617d2d4 | 2016-04-25 22:02:08 -0700 | [diff] [blame] | 1 | /* -*- 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 ===== |
| 36 | namespace logging = boost::log; |
| 37 | namespace src = boost::log::sources; |
| 38 | namespace sinks = boost::log::sinks; |
| 39 | namespace keywords = boost::log::keywords; |
| 40 | namespace expr = boost::log::expressions; |
| 41 | |
| 42 | namespace ndn { |
| 43 | namespace ntorrent { |
| 44 | |
Mickey Sweatt | ec9188b | 2016-05-03 10:31:20 -0700 | [diff] [blame] | 45 | log::severity_level LoggingUtil::severity_threshold = log::info; |
| 46 | |
Mickey Sweatt | 617d2d4 | 2016-04-25 22:02:08 -0700 | [diff] [blame] | 47 | void LoggingUtil::init() |
| 48 | { |
| 49 | logging::core::get()->set_filter |
| 50 | ( |
Mickey Sweatt | ec9188b | 2016-05-03 10:31:20 -0700 | [diff] [blame] | 51 | logging::trivial::severity >= severity_threshold |
Mickey Sweatt | 617d2d4 | 2016-04-25 22:02:08 -0700 | [diff] [blame] | 52 | ); |
| 53 | |
| 54 | logging::add_file_log |
| 55 | ( |
| 56 | keywords::file_name = "sample_%N.log", // < file name pattern > |
| 57 | keywords::rotation_size = 10 * 1024 * 1024, // < rotate files every 10 MiB... > |
| 58 | keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), // < ...or at midnight > |
| 59 | keywords::format = // < log record format > |
| 60 | ( |
| 61 | expr::stream |
| 62 | << expr::attr< unsigned int >("LineID") |
| 63 | << ": [" << expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S") << "]" |
| 64 | << ": <" << logging::trivial::severity |
| 65 | << "> " << expr::smessage |
| 66 | ) |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | } // end ntorrent |
| 71 | } // end ndn |
| 72 | |
| 73 | |