Jeff Thompson | fa30664 | 2013-06-17 15:06:57 -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 | * Alexander Afanasyev |
| 5 | * Zhenkai Zhu |
| 6 | * |
| 7 | * BSD license, See the LICENSE file for more information |
| 8 | * |
| 9 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 10 | * Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 11 | */ |
| 12 | |
| 13 | #include "logging.h" |
| 14 | |
| 15 | #ifdef HAVE_LOG4CXX |
| 16 | |
| 17 | #include <log4cxx/logger.h> |
| 18 | #include <log4cxx/basicconfigurator.h> |
| 19 | #include <log4cxx/consoleappender.h> |
| 20 | #include <log4cxx/patternlayout.h> |
| 21 | #include <log4cxx/level.h> |
| 22 | #include <log4cxx/propertyconfigurator.h> |
| 23 | #include <log4cxx/defaultconfigurator.h> |
| 24 | #include <log4cxx/helpers/exception.h> |
| 25 | using namespace log4cxx; |
| 26 | using namespace log4cxx::helpers; |
| 27 | |
| 28 | #include <unistd.h> |
| 29 | |
| 30 | void |
| 31 | INIT_LOGGERS () |
| 32 | { |
| 33 | static bool configured = false; |
| 34 | |
| 35 | if (configured) return; |
| 36 | |
| 37 | if (access ("log4cxx.properties", R_OK)==0) |
| 38 | PropertyConfigurator::configureAndWatch ("log4cxx.properties"); |
| 39 | else |
| 40 | { |
| 41 | PatternLayoutPtr layout (new PatternLayout ("%d{HH:mm:ss} %p %c{1} - %m%n")); |
| 42 | ConsoleAppenderPtr appender (new ConsoleAppender (layout)); |
| 43 | |
| 44 | BasicConfigurator::configure( appender ); |
| 45 | Logger::getRootLogger()->setLevel (log4cxx::Level::getInfo ()); |
| 46 | } |
| 47 | |
| 48 | configured = true; |
| 49 | } |
| 50 | |
| 51 | #endif |