Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2016, Regents of the University of California. |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 5 | * This file is part of ChronoShare, a decentralized file sharing application over NDN. |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 6 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 7 | * ChronoShare is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 10 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 11 | * ChronoShare 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 General Public License for more details. |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 14 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ChronoShare authors and contributors. |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
Alexander Afanasyev | f4cde4e | 2016-12-25 13:42:57 -0800 | [diff] [blame] | 21 | #include "logging.hpp" |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 22 | |
| 23 | #ifdef HAVE_LOG4CXX |
| 24 | |
| 25 | #include <log4cxx/logger.h> |
| 26 | #include <log4cxx/basicconfigurator.h> |
| 27 | #include <log4cxx/consoleappender.h> |
| 28 | #include <log4cxx/patternlayout.h> |
| 29 | #include <log4cxx/level.h> |
| 30 | #include <log4cxx/propertyconfigurator.h> |
| 31 | #include <log4cxx/defaultconfigurator.h> |
| 32 | #include <log4cxx/helpers/exception.h> |
| 33 | using namespace log4cxx; |
| 34 | using namespace log4cxx::helpers; |
| 35 | |
| 36 | #include <unistd.h> |
| 37 | |
| 38 | void |
| 39 | INIT_LOGGERS () |
| 40 | { |
| 41 | static bool configured = false; |
| 42 | |
| 43 | if (configured) return; |
| 44 | |
| 45 | if (access ("log4cxx.properties", R_OK)==0) |
| 46 | PropertyConfigurator::configureAndWatch ("log4cxx.properties"); |
| 47 | else |
| 48 | { |
| 49 | PatternLayoutPtr layout (new PatternLayout ("%d{HH:mm:ss} %p %c{1} - %m%n")); |
| 50 | ConsoleAppenderPtr appender (new ConsoleAppender (layout)); |
| 51 | |
| 52 | BasicConfigurator::configure( appender ); |
| 53 | Logger::getRootLogger()->setLevel (log4cxx::Level::getInfo ()); |
| 54 | } |
| 55 | |
| 56 | configured = true; |
| 57 | } |
| 58 | |
| 59 | #endif |