blob: 9780a5a45ef004cc34d302190e8723747d4072fd [file] [log] [blame]
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Alexander Afanasyev8722d872014-07-02 13:00:29 -07003 * Copyright (c) 2012-2014 University of California, Los Angeles
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -07004 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -07005 * This file is part of ChronoSync, synchronization library for distributed realtime
6 * applications for NDN.
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -07007 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -07008 * ChronoSync is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation, either
10 * version 3 of the License, or (at your option) any later version.
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070011 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -070012 * ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070015 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -070016 * You should have received a copy of the GNU General Public License along with
17 * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
20 * @author Chaoyi Bian <bcy@pku.edu.cn>
21 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070022 */
23
Alexander Afanasyevce001692013-07-14 11:34:41 -070024#include "sync-logging.h"
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070025
26#ifdef HAVE_LOG4CXX
27
28#include <log4cxx/logger.h>
29#include <log4cxx/basicconfigurator.h>
30#include <log4cxx/consoleappender.h>
31#include <log4cxx/patternlayout.h>
32#include <log4cxx/level.h>
33#include <log4cxx/propertyconfigurator.h>
34#include <log4cxx/defaultconfigurator.h>
35#include <log4cxx/helpers/exception.h>
36using namespace log4cxx;
37using namespace log4cxx::helpers;
38
39#include <unistd.h>
40
41void
42INIT_LOGGERS ()
43{
44 static bool configured = false;
45
46 if (configured) return;
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070047
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070048 if (access ("log4cxx.properties", R_OK)==0)
49 PropertyConfigurator::configureAndWatch ("log4cxx.properties");
50 else
51 {
52 PatternLayoutPtr layout (new PatternLayout ("%d{HH:mm:ss} %p %c{1} - %m%n"));
53 ConsoleAppenderPtr appender (new ConsoleAppender (layout));
54
55 BasicConfigurator::configure( appender );
56 Logger::getRootLogger()->setLevel (log4cxx::Level::getInfo ());
57 }
58
59 configured = true;
60}
61
62#endif