Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
| 11 | * |
| 12 | * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html> |
| 13 | * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/> |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 16 | #include "common.hpp" |
| 17 | |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 18 | #include "logging.hpp" |
| 19 | |
Alexander Afanasyev | 766cea7 | 2014-04-24 19:16:42 -0700 | [diff] [blame] | 20 | #ifdef NDN_CXX_HAVE_LOG4CXX |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 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 | using namespace log4cxx; |
| 31 | using namespace log4cxx::helpers; |
| 32 | |
| 33 | #include <unistd.h> |
| 34 | |
| 35 | void |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 36 | INIT_LOGGERS() |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 37 | { |
| 38 | static bool configured = false; |
| 39 | |
| 40 | if (configured) return; |
| 41 | |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 42 | if (access("log4cxx.properties", R_OK)==0) |
| 43 | PropertyConfigurator::configureAndWatch("log4cxx.properties"); |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 44 | else |
| 45 | { |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 46 | PatternLayoutPtr layout (new PatternLayout("%d{HH:mm:ss} %p %c{1} - %m%n")); |
| 47 | ConsoleAppenderPtr appender(new ConsoleAppender(layout)); |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 48 | |
| 49 | BasicConfigurator::configure( appender ); |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 50 | Logger::getRootLogger()->setLevel(log4cxx::Level::getInfo()); |
Jeff Thompson | e2cd587 | 2013-09-19 15:53:29 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | configured = true; |
| 54 | } |
| 55 | |
Alexander Afanasyev | 766cea7 | 2014-04-24 19:16:42 -0700 | [diff] [blame] | 56 | #endif // NDN_CXX_HAVE_LOG4CXX |