blob: f381a7a60ea1eb0730c21a89d9abd252a48b4b3a [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2016, Regents of the University of California.
Alexander Afanasyevc507ac22013-01-21 16:01:58 -08004 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08005 * This file is part of ChronoShare, a decentralized file sharing application over NDN.
Alexander Afanasyevc507ac22013-01-21 16:01:58 -08006 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08007 * ChronoShare is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080010 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080011 * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080014 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080015 * You should have received copies of the GNU General Public License along with
16 * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ChronoShare authors and contributors.
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080019 */
20
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080021#include "logging.hpp"
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080022
23#ifdef HAVE_LOG4CXX
24
25#include <log4cxx/logger.h>
26#include <log4cxx/basicconfigurator.h>
27#include <log4cxx/consoleappender.h>
28#include <log4cxx/patternlayout.h>
29#include <log4cxx/level.h>
30#include <log4cxx/propertyconfigurator.h>
31#include <log4cxx/defaultconfigurator.h>
32#include <log4cxx/helpers/exception.h>
33using namespace log4cxx;
34using namespace log4cxx::helpers;
35
36#include <unistd.h>
37
38void
39INIT_LOGGERS ()
40{
41 static bool configured = false;
42
43 if (configured) return;
44
45 if (access ("log4cxx.properties", R_OK)==0)
46 PropertyConfigurator::configureAndWatch ("log4cxx.properties");
47 else
48 {
49 PatternLayoutPtr layout (new PatternLayout ("%d{HH:mm:ss} %p %c{1} - %m%n"));
50 ConsoleAppenderPtr appender (new ConsoleAppender (layout));
51
52 BasicConfigurator::configure( appender );
53 Logger::getRootLogger()->setLevel (log4cxx::Level::getInfo ());
54 }
55
56 configured = true;
57}
58
59#endif