Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 5 | * @author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 6 | * See COPYING for copyright and distribution information. |
| 7 | */ |
| 8 | |
| 9 | #include "logging.hpp" |
| 10 | |
Jeff Thompson | b752300 | 2013-10-09 10:25:00 -0700 | [diff] [blame] | 11 | #ifdef NDN_CPP_HAVE_LOG4CXX |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 12 | |
| 13 | #include <log4cxx/logger.h> |
| 14 | #include <log4cxx/basicconfigurator.h> |
| 15 | #include <log4cxx/consoleappender.h> |
| 16 | #include <log4cxx/patternlayout.h> |
| 17 | #include <log4cxx/level.h> |
| 18 | #include <log4cxx/propertyconfigurator.h> |
| 19 | #include <log4cxx/defaultconfigurator.h> |
| 20 | #include <log4cxx/helpers/exception.h> |
| 21 | using namespace log4cxx; |
| 22 | using namespace log4cxx::helpers; |
| 23 | |
| 24 | #include <unistd.h> |
| 25 | |
| 26 | void |
| 27 | INIT_LOGGERS () |
| 28 | { |
| 29 | static bool configured = false; |
| 30 | |
| 31 | if (configured) return; |
| 32 | |
| 33 | if (access ("log4cxx.properties", R_OK)==0) |
| 34 | PropertyConfigurator::configureAndWatch ("log4cxx.properties"); |
| 35 | else |
| 36 | { |
| 37 | PatternLayoutPtr layout (new PatternLayout ("%d{HH:mm:ss} %p %c{1} - %m%n")); |
| 38 | ConsoleAppenderPtr appender (new ConsoleAppender (layout)); |
| 39 | |
| 40 | BasicConfigurator::configure( appender ); |
| 41 | Logger::getRootLogger()->setLevel (log4cxx::Level::getInfo ()); |
| 42 | } |
| 43 | |
| 44 | configured = true; |
| 45 | } |
| 46 | |
| 47 | #endif |