diff --git a/configure.in b/configure.in index 204aaf1..dac1e3e 100644 --- a/configure.in +++ b/configure.in @@ -50,6 +50,14 @@ if test "${ac_cv_c_Wextra}" != "no"; then CXXFLAGS+=" -Wextra" fi +dnl Logging +AC_ARG_ENABLE([logging],AC_HELP_STRING([--enable-logging],[logging (default disabled)])) +if test "${enable_logging}" = "yes"; then + want_logging=1 +else + want_logging=0 +fi + dnl Debug mode AC_ARG_ENABLE([debug],AC_HELP_STRING([--enable-debug],[debug mode (default disabled)])) if test "${enable_debug}" = "yes"; then @@ -116,6 +124,19 @@ PKG_CHECK_MODULES(LIBCONFIG, [libconfig++], AC_DEFINE(HAVE_LIBCONFIG, 1, [Define to 1 if you have the libconfig library])], [has_libconfig=0]) +dnl Check for liblog4cxx +PKG_CHECK_MODULES(LOG4CXX, [liblog4cxx], + [has_log4cxx=1 + AC_DEFINE(HAVE_LIBLOG4CXX, 1, [Define to 1 if you have the liblog4cxx library])], + [has_log4cxx=0]) +AS_IF([test "${want_logging}" = "1"], + [AS_IF([test "${has_log4cxx}" = "1"], + [with_logging=1 + AC_DEFINE(USE_LOGGING, 1, [Define to 1 if you want to enable logging])], + [AC_MSG_ERROR([Logging requested, but liblog4cxx could not be found on your system (using pkg-config)])])]) +# Conditional, to avoid a useless dependency (in the case of shared library) +AM_CONDITIONAL([WITH_LOGGING], [test "${with_logging}" = "1"]) + dnl Check for Expat AX_LIB_EXPAT([2.0.1]) diff --git a/dic/Makefile.am b/dic/Makefile.am index 6c6c492..350d362 100644 --- a/dic/Makefile.am +++ b/dic/Makefile.am @@ -20,9 +20,10 @@ noinst_LIBRARIES = libdic.a localedir = $(datadir)/locale -AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" -I$(top_srcdir) -I../intl -I$(top_srcdir)/intl $(INCICONV) +AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" -I$(top_srcdir) -I../intl -I$(top_srcdir)/intl $(INCICONV) @LOG4CXX_CFLAGS@ libdic_a_SOURCES = \ + logging.h \ base_exception.cpp base_exception.h \ dic_exception.cpp dic_exception.h \ header.cpp header.h \ @@ -57,5 +58,11 @@ listdic_LDADD=libdic.a @LIBINTL@ regexp_SOURCES=regexpmain.cpp regexp_LDADD=libdic.a @LIBINTL@ +if WITH_LOGGING +compdic_LDADD += @LOG4CXX_LIBS@ +listdic_LDADD += @LOG4CXX_LIBS@ +regexp_LDADD += @LOG4CXX_LIBS@ +endif + endif diff --git a/dic/compdic.cpp b/dic/compdic.cpp index f34e561..1114fd2 100644 --- a/dic/compdic.cpp +++ b/dic/compdic.cpp @@ -65,6 +65,8 @@ #define fmt(a) boost::format(a) +INIT_LOGGER(CompDic::logger, "Compdic"); + CompDic::CompDic() : m_currentRec(0), m_maxRec(0), m_loadTime(0), m_buildTime(0) { @@ -184,15 +186,8 @@ void CompDic::writeNode(uint32_t *ioEdges, unsigned int num, ostream &outFile) ioEdges[i] = htonl(ioEdges[i]); } -#ifdef DEBUG_OUTPUT - cout << fmt(_("writing %1% edges")) % num << endl; - for (int i = 0; i < num; i++) - { - outFile.write((char*)(ioEdges + i), sizeof(DicEdge)); - } -#else + LOG_TRACE(logger, fmt("writing %1% edges") % num); outFile.write((char*)ioEdges, num * sizeof(DicEdge)); -#endif } #define MAX_EDGES 2000 diff --git a/dic/compdic.h b/dic/compdic.h index f787fb8..7016576 100644 --- a/dic/compdic.h +++ b/dic/compdic.h @@ -26,6 +26,7 @@ #include #include +#include "logging.h" #include "header.h" #include "dic_internals.h" @@ -41,6 +42,7 @@ using namespace std; class CompDic { + DEFINE_LOGGER(logger); typedef boost::unordered_map, unsigned int> HashMap; public: diff --git a/dic/logging.h b/dic/logging.h new file mode 100644 index 0000000..d8fb24b --- /dev/null +++ b/dic/logging.h @@ -0,0 +1,51 @@ +/***************************************************************************** + * Eliot + * Copyright (C) 2011 Olivier Teulière + * Authors: Olivier Teulière + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + *****************************************************************************/ + +#ifndef DIC_LOGGING_H_ +#define DIC_LOGGING_H_ + +#include + +#ifdef USE_LOGGING +# include + +# define DEFINE_LOGGER(logger) static log4cxx::LoggerPtr logger; +# define INIT_LOGGER(logger, name) log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(name)) + +# define LOG_TRACE(a, b) LOG4CXX_TRACE(a, b) +# define LOG_DEBUG(a, b) LOG4CXX_DEBUG(a, b) +# define LOG_INFO(a, b) LOG4CXX_INFO(a, b) +# define LOG_WARN(a, b) LOG4CXX_WARN(a, b) +# define LOG_ERROR(a, b) LOG4CXX_ERROR(a, b) +# define LOG_FATAL(a, b) LOG4CXX_FATAL(a, b) +#else +# define DEFINE_LOGGER(logger) +# define INIT_LOGGER(logger, name) + +# define LOG_TRACE(a, b) +# define LOG_DEBUG(a, b) +# define LOG_INFO(a, b) +# define LOG_WARN(a, b) +# define LOG_ERROR(a, b) +# define LOG_FATAL(a, b) +#endif // USE_LOGGING + +#endif + diff --git a/game/Makefile.am b/game/Makefile.am index db7e356..4cc781e 100644 --- a/game/Makefile.am +++ b/game/Makefile.am @@ -19,7 +19,7 @@ noinst_LIBRARIES = libgame.a -AM_CPPFLAGS = -I$(top_srcdir)/dic -I../intl -I$(top_srcdir)/intl @LIBCONFIG_CFLAGS@ @ARABICA_CFLAGS@ @EXPAT_CFLAGS@ +AM_CPPFLAGS = -I$(top_srcdir)/dic -I../intl -I$(top_srcdir)/intl @LIBCONFIG_CFLAGS@ @ARABICA_CFLAGS@ @EXPAT_CFLAGS@ @LOG4CXX_CFLAGS@ libgame_a_SOURCES= \ game_exception.cpp game_exception.h \ diff --git a/qt/Makefile.am b/qt/Makefile.am index 83cf6de..811fad0 100644 --- a/qt/Makefile.am +++ b/qt/Makefile.am @@ -20,7 +20,7 @@ localedir = $(datadir)/locale if BUILD_QT -AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" @QT_CFLAGS@ -DQT4LOCALEDIR=\"@QT4LOCALEDIR@\" -I$(top_srcdir) -I../intl -I$(top_srcdir)/dic -I$(top_srcdir)/game +AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" @QT_CFLAGS@ -DQT4LOCALEDIR=\"@QT4LOCALEDIR@\" -I$(top_srcdir) -I../intl -I$(top_srcdir)/dic -I$(top_srcdir)/game @LOG4CXX_CFLAGS@ SUFFIXES=.ui.h .moc.cpp @@ -113,6 +113,10 @@ eliot_LDADD = ../game/libgame.a ../dic/libdic.a @QT_LIBS@ @LIBINTL@ @LIBCONFIG_L # Needed for proper stack trace handling eliot_LDFLAGS = -rdynamic +if WITH_LOGGING +eliot_LDADD += @LOG4CXX_LIBS@ +endif + # Generate a cpp file from the resources resources.cpp: eliot.qrc $(RESOURCES) $(RCC) -o $@ $< diff --git a/utils/Makefile.am b/utils/Makefile.am index 86bbee1..5c2160f 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -17,7 +17,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA localedir = $(datadir)/locale -AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" -I$(top_srcdir)/dic -I$(top_srcdir)/game -I../intl -I$(top_srcdir)/intl +AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" -I$(top_srcdir)/dic -I$(top_srcdir)/game -I../intl -I$(top_srcdir)/intl @LOG4CXX_CFLAGS@ noinst_PROGRAMS = bin_PROGRAMS = @@ -30,11 +30,18 @@ eliottxt_LDADD = $(top_builddir)/game/libgame.a $(top_builddir)/dic/libdic.a @LI if HAS_READLINE eliottxt_LDADD += -lreadline endif +if WITH_LOGGING +eliottxt_LDADD += @LOG4CXX_LIBS@ +endif endif if BUILD_NCURSES bin_PROGRAMS += eliotcurses eliotcurses_SOURCES = ncurses.cpp ncurses.h eliotcurses_LDADD = ../game/libgame.a ../dic/libdic.a -lncursesw @LIBINTL@ @LIBCONFIG_LIBS@ @ARABICA_LIBS@ @EXPAT_LDFLAGS@ +if WITH_LOGGING +eliotcurses_LDADD += @LOG4CXX_LIBS@ +endif + endif