blob: 113e3a949fe3fd0adb7489bf2fd0137ce9d5fd12 [file] [log] [blame]
Jeff Thompsone2cd5872013-09-19 15:53:29 -07001/* -*- 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
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08009#include "common.hpp"
10
Jeff Thompsone2cd5872013-09-19 15:53:29 -070011#include "logging.hpp"
12
Alexander Afanasyev766cea72014-04-24 19:16:42 -070013#ifdef NDN_CXX_HAVE_LOG4CXX
Jeff Thompsone2cd5872013-09-19 15:53:29 -070014
15#include <log4cxx/logger.h>
16#include <log4cxx/basicconfigurator.h>
17#include <log4cxx/consoleappender.h>
18#include <log4cxx/patternlayout.h>
19#include <log4cxx/level.h>
20#include <log4cxx/propertyconfigurator.h>
21#include <log4cxx/defaultconfigurator.h>
22#include <log4cxx/helpers/exception.h>
23using namespace log4cxx;
24using namespace log4cxx::helpers;
25
26#include <unistd.h>
27
28void
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070029INIT_LOGGERS()
Jeff Thompsone2cd5872013-09-19 15:53:29 -070030{
31 static bool configured = false;
32
33 if (configured) return;
34
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070035 if (access("log4cxx.properties", R_OK)==0)
36 PropertyConfigurator::configureAndWatch("log4cxx.properties");
Jeff Thompsone2cd5872013-09-19 15:53:29 -070037 else
38 {
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070039 PatternLayoutPtr layout (new PatternLayout("%d{HH:mm:ss} %p %c{1} - %m%n"));
40 ConsoleAppenderPtr appender(new ConsoleAppender(layout));
Jeff Thompsone2cd5872013-09-19 15:53:29 -070041
42 BasicConfigurator::configure( appender );
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070043 Logger::getRootLogger()->setLevel(log4cxx::Level::getInfo());
Jeff Thompsone2cd5872013-09-19 15:53:29 -070044 }
45
46 configured = true;
47}
48
Alexander Afanasyev766cea72014-04-24 19:16:42 -070049#endif // NDN_CXX_HAVE_LOG4CXX