blob: d395ea09e13b1b8c85971db6afa8057939dd942c [file] [log] [blame]
Jeff Thompsone2cd5872013-09-19 15:53:29 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * 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 Thompsone2cd5872013-09-19 15:53:29 -070014 */
15
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080016#include "common.hpp"
17
Jeff Thompsone2cd5872013-09-19 15:53:29 -070018#include "logging.hpp"
19
Alexander Afanasyev766cea72014-04-24 19:16:42 -070020#ifdef NDN_CXX_HAVE_LOG4CXX
Jeff Thompsone2cd5872013-09-19 15:53:29 -070021
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>
30using namespace log4cxx;
31using namespace log4cxx::helpers;
32
33#include <unistd.h>
34
35void
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070036INIT_LOGGERS()
Jeff Thompsone2cd5872013-09-19 15:53:29 -070037{
38 static bool configured = false;
39
40 if (configured) return;
41
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070042 if (access("log4cxx.properties", R_OK)==0)
43 PropertyConfigurator::configureAndWatch("log4cxx.properties");
Jeff Thompsone2cd5872013-09-19 15:53:29 -070044 else
45 {
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070046 PatternLayoutPtr layout (new PatternLayout("%d{HH:mm:ss} %p %c{1} - %m%n"));
47 ConsoleAppenderPtr appender(new ConsoleAppender(layout));
Jeff Thompsone2cd5872013-09-19 15:53:29 -070048
49 BasicConfigurator::configure( appender );
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070050 Logger::getRootLogger()->setLevel(log4cxx::Level::getInfo());
Jeff Thompsone2cd5872013-09-19 15:53:29 -070051 }
52
53 configured = true;
54}
55
Alexander Afanasyev766cea72014-04-24 19:16:42 -070056#endif // NDN_CXX_HAVE_LOG4CXX