blob: 6d89450b374b41aab117ddbf5aff30cadc702326 [file] [log] [blame]
Alexander Afanasyev59a42ec2014-09-02 18:21:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
4 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "logger.hpp"
21
22#include <log4cxx/logger.h>
23#include <log4cxx/basicconfigurator.h>
24#include <log4cxx/consoleappender.h>
25#include <log4cxx/patternlayout.h>
26#include <log4cxx/level.h>
27#include <log4cxx/propertyconfigurator.h>
28#include <log4cxx/defaultconfigurator.h>
29#include <log4cxx/helpers/exception.h>
30
31#include <unistd.h>
32
33namespace ndn {
34namespace ndns {
35namespace log {
36
37void
Shock Jiang3016c982014-11-11 11:35:17 -080038init(const std::string& configFile/*= DEFAULT_CONFIG_PATH "/" "log4cxx.properties"*/)
Alexander Afanasyev59a42ec2014-09-02 18:21:16 -070039{
40 using namespace log4cxx;
41 using namespace log4cxx::helpers;
42
43 if (access(configFile.c_str(), R_OK) == 0) {
44 PropertyConfigurator::configureAndWatch(configFile.c_str());
45 }
46 else {
47 PatternLayoutPtr layout(new PatternLayout("%d{HH:mm:ss} %p %c{1} - %m%n"));
Alexander Afanasyev4ca504c2014-11-27 16:42:56 -080048 ConsoleAppenderPtr appender(new ConsoleAppender(layout, ConsoleAppender::getSystemErr()));
Alexander Afanasyev59a42ec2014-09-02 18:21:16 -070049 BasicConfigurator::configure(appender);
50 Logger::getRootLogger()->setLevel(log4cxx::Level::getInfo());
51 }
52}
53
54} // namespace log
55} // namespace ndns
56} // namespace ndn