blob: b92f83a17f2f2370f8b2f1167929f0c1b70a2bcb [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
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080025#include <log4cxx/basicconfigurator.h>
26#include <log4cxx/consoleappender.h>
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080027#include <log4cxx/defaultconfigurator.h>
28#include <log4cxx/helpers/exception.h>
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080029#include <log4cxx/level.h>
30#include <log4cxx/logger.h>
31#include <log4cxx/patternlayout.h>
32#include <log4cxx/propertyconfigurator.h>
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080033using namespace log4cxx;
34using namespace log4cxx::helpers;
35
36#include <unistd.h>
37
38void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080039INIT_LOGGERS()
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080040{
41 static bool configured = false;
42
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080043 if (configured)
44 return;
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080045
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080046 if (access("log4cxx.properties", R_OK) == 0)
47 PropertyConfigurator::configureAndWatch("log4cxx.properties");
48 else {
49 PatternLayoutPtr layout(new PatternLayout("%d{HH:mm:ss} %p %c{1} - %m%n"));
50 ConsoleAppenderPtr appender(new ConsoleAppender(layout));
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080051
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080052 BasicConfigurator::configure(appender);
53 Logger::getRootLogger()->setLevel(log4cxx::Level::getInfo());
54 }
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080055
56 configured = true;
57}
58
59#endif