Alexander Afanasyev | 59a42ec | 2014-09-02 18:21:16 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 33 | namespace ndn { |
| 34 | namespace ndns { |
| 35 | namespace log { |
| 36 | |
| 37 | void |
Shock Jiang | 3016c98 | 2014-11-11 11:35:17 -0800 | [diff] [blame] | 38 | init(const std::string& configFile/*= DEFAULT_CONFIG_PATH "/" "log4cxx.properties"*/) |
Alexander Afanasyev | 59a42ec | 2014-09-02 18:21:16 -0700 | [diff] [blame] | 39 | { |
| 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 Afanasyev | 4ca504c | 2014-11-27 16:42:56 -0800 | [diff] [blame] | 48 | ConsoleAppenderPtr appender(new ConsoleAppender(layout, ConsoleAppender::getSystemErr())); |
Alexander Afanasyev | 59a42ec | 2014-09-02 18:21:16 -0700 | [diff] [blame] | 49 | BasicConfigurator::configure(appender); |
| 50 | Logger::getRootLogger()->setLevel(log4cxx::Level::getInfo()); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | } // namespace log |
| 55 | } // namespace ndns |
| 56 | } // namespace ndn |