diff options
author | khburdette <kburdet1@ford.com> | 2013-04-19 15:58:59 -0400 |
---|---|---|
committer | khburdette <kburdet1@ford.com> | 2013-04-19 15:58:59 -0400 |
commit | a46991cd5da4dbcc5510457c6bae2dab340c1ed2 (patch) | |
tree | 9f4d9ccec060c4b6cd378aa631442f710c140962 /SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src | |
download | smartdevicelink-a46991cd5da4dbcc5510457c6bae2dab340c1ed2.tar.gz |
Initial Ford commit with Core and Proxies
Diffstat (limited to 'SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src')
58 files changed, 15183 insertions, 0 deletions
diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/CMakeLists.txt b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/CMakeLists.txt new file mode 100644 index 000000000..3f70a05a6 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/CMakeLists.txt @@ -0,0 +1,194 @@ +set (log4cplus_sources + appenderattachableimpl.cxx + appender.cxx + asyncappender.cxx + clogger.cxx + configurator.cxx + consoleappender.cxx + cygwin-win32.cxx + env.cxx + factory.cxx + fileappender.cxx + fileinfo.cxx + filter.cxx + global-init.cxx + hierarchy.cxx + hierarchylocker.cxx + layout.cxx + log4judpappender.cxx + lockfile.cxx + logger.cxx + loggerimpl.cxx + loggingevent.cxx + loggingmacros.cxx + loglevel.cxx + loglog.cxx + logloguser.cxx + mdc.cxx + ndc.cxx + nullappender.cxx + objectregistry.cxx + patternlayout.cxx + pointer.cxx + property.cxx + queue.cxx + rootlogger.cxx + sleep.cxx + snprintf.cxx + socketappender.cxx + socketbuffer.cxx + socket.cxx + stringhelper.cxx + stringhelper-clocale.cxx + stringhelper-cxxlocale.cxx + stringhelper-iconv.cxx + syncprims.cxx + syslogappender.cxx + threads.cxx + timehelper.cxx + tls.cxx + version.cxx) + +#message (STATUS "Type: ${UNIX}|${CYGWIN}|${WIN32}") + +if ("${UNIX}" OR "${CYGWIN}") + set (log4cplus_sources ${log4cplus_sources} + socket-unix.cxx) +elseif (WIN32) + set (log4cplus_sources ${log4cplus_sources} + nteventlogappender.cxx + socket-win32.cxx + win32consoleappender.cxx + win32debugappender.cxx) + + #add_definitions (-DLOG4CPLUS_STATIC) + #set (log4cplus_postfix "${log4cplus_postfix}S") +endif () + +if (UNICODE) + add_definitions (-DUNICODE -D_UNICODE -UMBCS -U_MBCS) +endif (UNICODE) + +add_library (${log4cplus} ${log4cplus_sources}) + +set (log4cplus_LIBS ${CMAKE_THREAD_LIBS_INIT}) +if (LIBRT) + list (APPEND log4cplus_LIBS ${LIBRT}) +endif () +if (LIBPOSIX4) + list (APPEND log4cplus_LIBS ${LIBPOSIX4}) +endif () +if (LIBCPOSIX) + list (APPEND log4cplus_LIBS ${LIBCPOSIX}) +endif () +if (LIBSOCKET) + list (APPEND log4cplus_LIBS ${LIBSOCKET}) +endif () +if (LIBNSL) + list (APPEND log4cplus_LIBS ${LIBNSL}) +endif () +if (LOG4CPLUS_WITH_ICONV AND LIBICONV) + list (APPEND log4cplus_LIBS ${LIBICONV}) +endif () +target_link_libraries (${log4cplus} ${log4cplus_LIBS}) + +set_target_properties (${log4cplus} PROPERTIES + VERSION "${log4cplus_version_major}.${log4cplus_version_minor}.${log4cplus_version_patch}" + SOVERSION "${log4cplus_soversion}" + COMPILE_FLAGS "-DINSIDE_LOG4CPLUS") + +if (WIN32) + set_target_properties (${log4cplus} PROPERTIES + DEBUG_POSTFIX "D") + target_link_libraries (${log4cplus} ws2_32 advapi32) +endif () + +install(TARGETS ${log4cplus} LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin) + +install(FILES ../include/log4cplus/appender.h + ../include/log4cplus/asyncappender.h + ../include/log4cplus/clogger.h + ../include/log4cplus/config.hxx + ../include/log4cplus/configurator.h + ../include/log4cplus/consoleappender.h + ../include/log4cplus/fileappender.h + ../include/log4cplus/fstreams.h + ../include/log4cplus/hierarchy.h + ../include/log4cplus/hierarchylocker.h + ../include/log4cplus/layout.h + ../include/log4cplus/log4judpappender.h + ../include/log4cplus/logger.h + ../include/log4cplus/loggingmacros.h + ../include/log4cplus/loglevel.h + ../include/log4cplus/mdc.h + ../include/log4cplus/ndc.h + ../include/log4cplus/nteventlogappender.h + ../include/log4cplus/nullappender.h + ../include/log4cplus/socketappender.h + ../include/log4cplus/streams.h + ../include/log4cplus/syslogappender.h + ../include/log4cplus/tchar.h + ../include/log4cplus/tracelogger.h + ../include/log4cplus/tstring.h + ../include/log4cplus/version.h + ../include/log4cplus/win32debugappender.h + ../include/log4cplus/win32consoleappender.h + DESTINATION include/log4cplus ) + +install(FILES ../include/log4cplus/boost/deviceappender.hxx + DESTINATION include/log4cplus/boost ) + + +install(FILES ../include/log4cplus/helpers/appenderattachableimpl.h + ../include/log4cplus/helpers/fileinfo.h + ../include/log4cplus/helpers/lockfile.h + ../include/log4cplus/helpers/loglog.h + ../include/log4cplus/helpers/logloguser.h + ../include/log4cplus/helpers/pointer.h + ../include/log4cplus/helpers/property.h + ../include/log4cplus/helpers/queue.h + ../include/log4cplus/helpers/sleep.h + ../include/log4cplus/helpers/snprintf.h + ../include/log4cplus/helpers/socket.h + ../include/log4cplus/helpers/socketbuffer.h + ../include/log4cplus/helpers/stringhelper.h + ../include/log4cplus/helpers/thread-config.h + ../include/log4cplus/helpers/timehelper.h + DESTINATION include/log4cplus/helpers ) + +install(FILES ../include/log4cplus/internal/env.h + ../include/log4cplus/internal/internal.h + ../include/log4cplus/internal/socket.h + DESTINATION include/log4cplus/internal ) + +install(FILES ../include/log4cplus/spi/appenderattachable.h + ../include/log4cplus/spi/factory.h + ../include/log4cplus/spi/filter.h + ../include/log4cplus/spi/loggerfactory.h + ../include/log4cplus/spi/loggerimpl.h + ../include/log4cplus/spi/loggingevent.h + ../include/log4cplus/spi/objectregistry.h + ../include/log4cplus/spi/rootlogger.h + DESTINATION include/log4cplus/spi ) + +install(FILES ../include/log4cplus/thread/impl/syncprims-impl.h +# ../include/log4cplus/thread/impl/syncprims-pmsm.h + ../include/log4cplus/thread/impl/syncprims-pthreads.h + ../include/log4cplus/thread/impl/syncprims-win32.h + ../include/log4cplus/thread/impl/threads-impl.h + ../include/log4cplus/thread/impl/tls.h + DESTINATION include/log4cplus/thread/impl ) + +install(FILES ../include/log4cplus/thread/syncprims-pub-impl.h + ../include/log4cplus/thread/syncprims.h + ../include/log4cplus/thread/threads.h + DESTINATION include/log4cplus/thread ) + +install(FILES ../include/log4cplus/config/macosx.h + ../include/log4cplus/config/win32.h + ../include/log4cplus/config/windowsh-inc.h + ${log4cplus_BINARY_DIR}/include/log4cplus/config/defines.hxx + DESTINATION include/log4cplus/config ) + diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/Makefile.am b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/Makefile.am new file mode 100644 index 000000000..9d8214263 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/Makefile.am @@ -0,0 +1,146 @@ +lib_LTLIBRARIES = liblog4cplus.la + +AM_CPPFLAGS = -DINSIDE_LOG4CPLUS \ + -I$(top_srcdir)/include -I$(top_builddir)/include \ + @LOG4CPLUS_NDEBUG@ + +AM_CXXFLAGS=-no-suppress @LOG4CPLUS_PROFILING_CXXFLAGS@ + +AM_LDFLAGS=@LOG4CPLUS_PROFILING_LDFLAGS@ + +INCLUDES_SRC_PATH = $(top_srcdir)/include/log4cplus + +INCLUDES_SRC = \ + $(INCLUDES_SRC_PATH)/appender.h \ + $(INCLUDES_SRC_PATH)/asyncappender.h \ + $(INCLUDES_SRC_PATH)/boost/deviceappender.hxx \ + $(INCLUDES_SRC_PATH)/clogger.h \ + $(INCLUDES_SRC_PATH)/config.hxx \ + $(INCLUDES_SRC_PATH)/config/macosx.h \ + $(INCLUDES_SRC_PATH)/config/win32.h \ + $(INCLUDES_SRC_PATH)/config/windowsh-inc.h \ + $(INCLUDES_SRC_PATH)/configurator.h \ + $(INCLUDES_SRC_PATH)/consoleappender.h \ + $(INCLUDES_SRC_PATH)/fileappender.h \ + $(INCLUDES_SRC_PATH)/fstreams.h \ + $(INCLUDES_SRC_PATH)/helpers/appenderattachableimpl.h \ + $(INCLUDES_SRC_PATH)/helpers/fileinfo.h \ + $(INCLUDES_SRC_PATH)/helpers/lockfile.h \ + $(INCLUDES_SRC_PATH)/helpers/loglog.h \ + $(INCLUDES_SRC_PATH)/helpers/logloguser.h \ + $(INCLUDES_SRC_PATH)/helpers/pointer.h \ + $(INCLUDES_SRC_PATH)/helpers/property.h \ + $(INCLUDES_SRC_PATH)/helpers/queue.h \ + $(INCLUDES_SRC_PATH)/helpers/sleep.h \ + $(INCLUDES_SRC_PATH)/helpers/snprintf.h \ + $(INCLUDES_SRC_PATH)/helpers/socketbuffer.h \ + $(INCLUDES_SRC_PATH)/helpers/socket.h \ + $(INCLUDES_SRC_PATH)/helpers/stringhelper.h \ + $(INCLUDES_SRC_PATH)/helpers/thread-config.h \ + $(INCLUDES_SRC_PATH)/helpers/timehelper.h \ + $(INCLUDES_SRC_PATH)/hierarchy.h \ + $(INCLUDES_SRC_PATH)/hierarchylocker.h \ + $(INCLUDES_SRC_PATH)/internal/cygwin-win32.h \ + $(INCLUDES_SRC_PATH)/internal/env.h \ + $(INCLUDES_SRC_PATH)/internal/internal.h \ + $(INCLUDES_SRC_PATH)/internal/socket.h \ + $(INCLUDES_SRC_PATH)/layout.h \ + $(INCLUDES_SRC_PATH)/log4judpappender.h \ + $(INCLUDES_SRC_PATH)/logger.h \ + $(INCLUDES_SRC_PATH)/loggingmacros.h \ + $(INCLUDES_SRC_PATH)/loglevel.h \ + $(INCLUDES_SRC_PATH)/mdc.h \ + $(INCLUDES_SRC_PATH)/ndc.h \ + $(INCLUDES_SRC_PATH)/nteventlogappender.h \ + $(INCLUDES_SRC_PATH)/nullappender.h \ + $(INCLUDES_SRC_PATH)/spi/appenderattachable.h \ + $(INCLUDES_SRC_PATH)/spi/factory.h \ + $(INCLUDES_SRC_PATH)/spi/filter.h \ + $(INCLUDES_SRC_PATH)/spi/loggerfactory.h \ + $(INCLUDES_SRC_PATH)/spi/loggerimpl.h \ + $(INCLUDES_SRC_PATH)/spi/loggingevent.h \ + $(INCLUDES_SRC_PATH)/spi/objectregistry.h \ + $(INCLUDES_SRC_PATH)/spi/rootlogger.h \ + $(INCLUDES_SRC_PATH)/socketappender.h \ + $(INCLUDES_SRC_PATH)/streams.h \ + $(INCLUDES_SRC_PATH)/syslogappender.h \ + $(INCLUDES_SRC_PATH)/tchar.h \ + $(INCLUDES_SRC_PATH)/thread/impl/syncprims-impl.h \ + $(INCLUDES_SRC_PATH)/thread/impl/syncprims-pmsm.h \ + $(INCLUDES_SRC_PATH)/thread/impl/syncprims-pthreads.h \ + $(INCLUDES_SRC_PATH)/thread/impl/syncprims-win32.h \ + $(INCLUDES_SRC_PATH)/thread/impl/threads-impl.h \ + $(INCLUDES_SRC_PATH)/thread/impl/tls.h \ + $(INCLUDES_SRC_PATH)/thread/syncprims.h \ + $(INCLUDES_SRC_PATH)/thread/syncprims-pub-impl.h \ + $(INCLUDES_SRC_PATH)/thread/threads.h \ + $(INCLUDES_SRC_PATH)/tracelogger.h \ + $(INCLUDES_SRC_PATH)/tstring.h \ + $(INCLUDES_SRC_PATH)/version.h \ + $(INCLUDES_SRC_PATH)/win32consoleappender.h \ + $(INCLUDES_SRC_PATH)/win32debugappender.h \ + $(top_builddir)/include/log4cplus/config/defines.hxx + +SINGLE_THREADED_SRC = \ + $(INCLUDES_SRC) \ + appenderattachableimpl.cxx \ + appender.cxx \ + asyncappender.cxx \ + clogger.cxx \ + configurator.cxx \ + consoleappender.cxx \ + cygwin-win32.cxx \ + env.cxx \ + factory.cxx \ + fileappender.cxx \ + fileinfo.cxx \ + filter.cxx \ + global-init.cxx \ + hierarchy.cxx \ + hierarchylocker.cxx \ + layout.cxx \ + log4judpappender.cxx \ + lockfile.cxx \ + logger.cxx \ + loggerimpl.cxx \ + loggingevent.cxx \ + loggingmacros.cxx \ + loglevel.cxx \ + loglog.cxx \ + logloguser.cxx \ + mdc.cxx \ + ndc.cxx \ + nullappender.cxx \ + nteventlogappender.cxx \ + objectregistry.cxx \ + patternlayout.cxx \ + pointer.cxx \ + property.cxx \ + queue.cxx \ + rootlogger.cxx \ + sleep.cxx \ + snprintf.cxx \ + socketappender.cxx \ + socketbuffer.cxx \ + socket.cxx \ + socket-unix.cxx \ + socket-win32.cxx \ + stringhelper.cxx \ + stringhelper-clocale.cxx \ + stringhelper-cxxlocale.cxx \ + stringhelper-iconv.cxx \ + syncprims.cxx \ + syslogappender.cxx \ + threads.cxx \ + timehelper.cxx \ + tls.cxx \ + version.cxx \ + win32consoleappender.cxx \ + win32debugappender.cxx + +LIB_SRC = $(SINGLE_THREADED_SRC) + +liblog4cplus_la_SOURCES = $(LIB_SRC) + +#liblog4cplus_a_LIBADD = @LIBOBJS@ @ALLOCA@ +liblog4cplus_la_LDFLAGS = -no-undefined -version-info @LT_VERSION@ -release @LT_RELEASE@ diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/Makefile.in b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/Makefile.in new file mode 100644 index 000000000..cb8e3eb1a --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/Makefile.in @@ -0,0 +1,827 @@ +# Makefile.in generated by automake 1.12.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2012 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +am__make_dryrun = \ + { \ + am__dry=no; \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ + | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ + *) \ + for am__flg in $$MAKEFLAGS; do \ + case $$am__flg in \ + *=*|--*) ;; \ + *n*) am__dry=yes; break;; \ + esac; \ + done;; \ + esac; \ + test $$am__dry = yes; \ + } +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = src +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ + $(top_srcdir)/depcomp $(top_srcdir)/mkinstalldirs +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/acinclude.m4 $(top_srcdir)/m4/ax_c_ifdef.m4 \ + $(top_srcdir)/m4/ax_append_flag.m4 \ + $(top_srcdir)/m4/ax_cflags_warn_all.m4 \ + $(top_srcdir)/m4/ax_type_socklen_t.m4 \ + $(top_srcdir)/m4/ax_compiler_vendor.m4 \ + $(top_srcdir)/m4/ax_cflags_gcc_option.m4 \ + $(top_srcdir)/m4/ax_cflags_sun_option.m4 \ + $(top_srcdir)/m4/ax_cflags_aix_option.m4 \ + $(top_srcdir)/m4/ax_pthread.m4 $(top_srcdir)/m4/ax_declspec.m4 \ + $(top_srcdir)/m4/ax_tls_support.m4 \ + $(top_srcdir)/m4/ax__sync.m4 \ + $(top_srcdir)/m4/ax_macro_va_args.m4 \ + $(top_srcdir)/m4/ax_macro_function.m4 \ + $(top_srcdir)/m4/ax_gethostbyname_r.m4 \ + $(top_srcdir)/m4/ax_getaddrinfo.m4 \ + $(top_srcdir)/m4/ax_log4cplus_wrappers.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/log4cplus/config.h \ + $(top_builddir)/include/log4cplus/config/defines.hxx +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(libdir)" +LTLIBRARIES = $(lib_LTLIBRARIES) +liblog4cplus_la_LIBADD = +am__objects_1 = +am__objects_2 = $(am__objects_1) appenderattachableimpl.lo appender.lo \ + asyncappender.lo clogger.lo configurator.lo consoleappender.lo \ + cygwin-win32.lo env.lo factory.lo fileappender.lo fileinfo.lo \ + filter.lo global-init.lo hierarchy.lo hierarchylocker.lo \ + layout.lo log4judpappender.lo lockfile.lo logger.lo \ + loggerimpl.lo loggingevent.lo loggingmacros.lo loglevel.lo \ + loglog.lo logloguser.lo mdc.lo ndc.lo nullappender.lo \ + nteventlogappender.lo objectregistry.lo patternlayout.lo \ + pointer.lo property.lo queue.lo rootlogger.lo sleep.lo \ + snprintf.lo socketappender.lo socketbuffer.lo socket.lo \ + socket-unix.lo socket-win32.lo stringhelper.lo \ + stringhelper-clocale.lo stringhelper-cxxlocale.lo \ + stringhelper-iconv.lo syncprims.lo syslogappender.lo \ + threads.lo timehelper.lo tls.lo version.lo \ + win32consoleappender.lo win32debugappender.lo +am__objects_3 = $(am__objects_2) +am_liblog4cplus_la_OBJECTS = $(am__objects_3) +liblog4cplus_la_OBJECTS = $(am_liblog4cplus_la_OBJECTS) +liblog4cplus_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ + $(CXXFLAGS) $(liblog4cplus_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(liblog4cplus_la_SOURCES) +DIST_SOURCES = $(liblog4cplus_la_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LOG4CPLUS_NDEBUG = @LOG4CPLUS_NDEBUG@ +LOG4CPLUS_PROFILING_CXXFLAGS = @LOG4CPLUS_PROFILING_CXXFLAGS@ +LOG4CPLUS_PROFILING_LDFLAGS = @LOG4CPLUS_PROFILING_LDFLAGS@ +LTLIBOBJS = @LTLIBOBJS@ +LT_RELEASE = @LT_RELEASE@ +LT_VERSION = @LT_VERSION@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +PTHREAD_CXXFLAGS = @PTHREAD_CXXFLAGS@ +PTHREAD_LIBS = @PTHREAD_LIBS@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +ax_pthread_config = @ax_pthread_config@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +lib_LTLIBRARIES = liblog4cplus.la +AM_CPPFLAGS = -DINSIDE_LOG4CPLUS \ + -I$(top_srcdir)/include -I$(top_builddir)/include \ + @LOG4CPLUS_NDEBUG@ + +AM_CXXFLAGS = -no-suppress @LOG4CPLUS_PROFILING_CXXFLAGS@ +AM_LDFLAGS = @LOG4CPLUS_PROFILING_LDFLAGS@ +INCLUDES_SRC_PATH = $(top_srcdir)/include/log4cplus +INCLUDES_SRC = \ + $(INCLUDES_SRC_PATH)/appender.h \ + $(INCLUDES_SRC_PATH)/asyncappender.h \ + $(INCLUDES_SRC_PATH)/boost/deviceappender.hxx \ + $(INCLUDES_SRC_PATH)/clogger.h \ + $(INCLUDES_SRC_PATH)/config.hxx \ + $(INCLUDES_SRC_PATH)/config/macosx.h \ + $(INCLUDES_SRC_PATH)/config/win32.h \ + $(INCLUDES_SRC_PATH)/config/windowsh-inc.h \ + $(INCLUDES_SRC_PATH)/configurator.h \ + $(INCLUDES_SRC_PATH)/consoleappender.h \ + $(INCLUDES_SRC_PATH)/fileappender.h \ + $(INCLUDES_SRC_PATH)/fstreams.h \ + $(INCLUDES_SRC_PATH)/helpers/appenderattachableimpl.h \ + $(INCLUDES_SRC_PATH)/helpers/fileinfo.h \ + $(INCLUDES_SRC_PATH)/helpers/lockfile.h \ + $(INCLUDES_SRC_PATH)/helpers/loglog.h \ + $(INCLUDES_SRC_PATH)/helpers/logloguser.h \ + $(INCLUDES_SRC_PATH)/helpers/pointer.h \ + $(INCLUDES_SRC_PATH)/helpers/property.h \ + $(INCLUDES_SRC_PATH)/helpers/queue.h \ + $(INCLUDES_SRC_PATH)/helpers/sleep.h \ + $(INCLUDES_SRC_PATH)/helpers/snprintf.h \ + $(INCLUDES_SRC_PATH)/helpers/socketbuffer.h \ + $(INCLUDES_SRC_PATH)/helpers/socket.h \ + $(INCLUDES_SRC_PATH)/helpers/stringhelper.h \ + $(INCLUDES_SRC_PATH)/helpers/thread-config.h \ + $(INCLUDES_SRC_PATH)/helpers/timehelper.h \ + $(INCLUDES_SRC_PATH)/hierarchy.h \ + $(INCLUDES_SRC_PATH)/hierarchylocker.h \ + $(INCLUDES_SRC_PATH)/internal/cygwin-win32.h \ + $(INCLUDES_SRC_PATH)/internal/env.h \ + $(INCLUDES_SRC_PATH)/internal/internal.h \ + $(INCLUDES_SRC_PATH)/internal/socket.h \ + $(INCLUDES_SRC_PATH)/layout.h \ + $(INCLUDES_SRC_PATH)/log4judpappender.h \ + $(INCLUDES_SRC_PATH)/logger.h \ + $(INCLUDES_SRC_PATH)/loggingmacros.h \ + $(INCLUDES_SRC_PATH)/loglevel.h \ + $(INCLUDES_SRC_PATH)/mdc.h \ + $(INCLUDES_SRC_PATH)/ndc.h \ + $(INCLUDES_SRC_PATH)/nteventlogappender.h \ + $(INCLUDES_SRC_PATH)/nullappender.h \ + $(INCLUDES_SRC_PATH)/spi/appenderattachable.h \ + $(INCLUDES_SRC_PATH)/spi/factory.h \ + $(INCLUDES_SRC_PATH)/spi/filter.h \ + $(INCLUDES_SRC_PATH)/spi/loggerfactory.h \ + $(INCLUDES_SRC_PATH)/spi/loggerimpl.h \ + $(INCLUDES_SRC_PATH)/spi/loggingevent.h \ + $(INCLUDES_SRC_PATH)/spi/objectregistry.h \ + $(INCLUDES_SRC_PATH)/spi/rootlogger.h \ + $(INCLUDES_SRC_PATH)/socketappender.h \ + $(INCLUDES_SRC_PATH)/streams.h \ + $(INCLUDES_SRC_PATH)/syslogappender.h \ + $(INCLUDES_SRC_PATH)/tchar.h \ + $(INCLUDES_SRC_PATH)/thread/impl/syncprims-impl.h \ + $(INCLUDES_SRC_PATH)/thread/impl/syncprims-pmsm.h \ + $(INCLUDES_SRC_PATH)/thread/impl/syncprims-pthreads.h \ + $(INCLUDES_SRC_PATH)/thread/impl/syncprims-win32.h \ + $(INCLUDES_SRC_PATH)/thread/impl/threads-impl.h \ + $(INCLUDES_SRC_PATH)/thread/impl/tls.h \ + $(INCLUDES_SRC_PATH)/thread/syncprims.h \ + $(INCLUDES_SRC_PATH)/thread/syncprims-pub-impl.h \ + $(INCLUDES_SRC_PATH)/thread/threads.h \ + $(INCLUDES_SRC_PATH)/tracelogger.h \ + $(INCLUDES_SRC_PATH)/tstring.h \ + $(INCLUDES_SRC_PATH)/version.h \ + $(INCLUDES_SRC_PATH)/win32consoleappender.h \ + $(INCLUDES_SRC_PATH)/win32debugappender.h \ + $(top_builddir)/include/log4cplus/config/defines.hxx + +SINGLE_THREADED_SRC = \ + $(INCLUDES_SRC) \ + appenderattachableimpl.cxx \ + appender.cxx \ + asyncappender.cxx \ + clogger.cxx \ + configurator.cxx \ + consoleappender.cxx \ + cygwin-win32.cxx \ + env.cxx \ + factory.cxx \ + fileappender.cxx \ + fileinfo.cxx \ + filter.cxx \ + global-init.cxx \ + hierarchy.cxx \ + hierarchylocker.cxx \ + layout.cxx \ + log4judpappender.cxx \ + lockfile.cxx \ + logger.cxx \ + loggerimpl.cxx \ + loggingevent.cxx \ + loggingmacros.cxx \ + loglevel.cxx \ + loglog.cxx \ + logloguser.cxx \ + mdc.cxx \ + ndc.cxx \ + nullappender.cxx \ + nteventlogappender.cxx \ + objectregistry.cxx \ + patternlayout.cxx \ + pointer.cxx \ + property.cxx \ + queue.cxx \ + rootlogger.cxx \ + sleep.cxx \ + snprintf.cxx \ + socketappender.cxx \ + socketbuffer.cxx \ + socket.cxx \ + socket-unix.cxx \ + socket-win32.cxx \ + stringhelper.cxx \ + stringhelper-clocale.cxx \ + stringhelper-cxxlocale.cxx \ + stringhelper-iconv.cxx \ + syncprims.cxx \ + syslogappender.cxx \ + threads.cxx \ + timehelper.cxx \ + tls.cxx \ + version.cxx \ + win32consoleappender.cxx \ + win32debugappender.cxx + +LIB_SRC = $(SINGLE_THREADED_SRC) +liblog4cplus_la_SOURCES = $(LIB_SRC) + +#liblog4cplus_a_LIBADD = @LIBOBJS@ @ALLOCA@ +liblog4cplus_la_LDFLAGS = -no-undefined -version-info @LT_VERSION@ -release @LT_RELEASE@ +all: all-am + +.SUFFIXES: +.SUFFIXES: .cxx .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ + } + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } +liblog4cplus.la: $(liblog4cplus_la_OBJECTS) $(liblog4cplus_la_DEPENDENCIES) $(EXTRA_liblog4cplus_la_DEPENDENCIES) + $(liblog4cplus_la_LINK) -rpath $(libdir) $(liblog4cplus_la_OBJECTS) $(liblog4cplus_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/appender.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/appenderattachableimpl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asyncappender.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clogger.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/configurator.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/consoleappender.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cygwin-win32.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/env.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/factory.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fileappender.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fileinfo.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filter.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/global-init.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hierarchy.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hierarchylocker.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/layout.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lockfile.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log4judpappender.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/logger.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/loggerimpl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/loggingevent.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/loggingmacros.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/loglevel.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/loglog.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/logloguser.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mdc.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ndc.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nteventlogappender.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nullappender.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/objectregistry.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/patternlayout.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pointer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/property.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/queue.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rootlogger.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sleep.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snprintf.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socket-unix.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socket-win32.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socket.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socketappender.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socketbuffer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stringhelper-clocale.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stringhelper-cxxlocale.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stringhelper-iconv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stringhelper.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/syncprims.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/syslogappender.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/threads.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timehelper.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tls.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/version.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/win32consoleappender.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/win32debugappender.Plo@am__quote@ + +.cxx.o: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< + +.cxx.obj: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cxx.lo: +@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +cscopelist: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(libdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-libLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-libLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool cscopelist ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am \ + install-libLTLIBRARIES install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-libLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/appender.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/appender.cxx new file mode 100644 index 000000000..1c88f916c --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/appender.cxx @@ -0,0 +1,350 @@ +// Module: Log4CPLUS +// File: appender.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/appender.h> +#include <log4cplus/layout.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/pointer.h> +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/spi/factory.h> +#include <log4cplus/spi/loggingevent.h> +#include <log4cplus/internal/internal.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <stdexcept> + + +namespace log4cplus +{ + + +/////////////////////////////////////////////////////////////////////////////// +// log4cplus::ErrorHandler dtor +/////////////////////////////////////////////////////////////////////////////// + +ErrorHandler::ErrorHandler () +{ } + + +ErrorHandler::~ErrorHandler() +{ } + + + +/////////////////////////////////////////////////////////////////////////////// +// log4cplus::OnlyOnceErrorHandler +/////////////////////////////////////////////////////////////////////////////// + +OnlyOnceErrorHandler::OnlyOnceErrorHandler() + : firstTime(true) +{ } + + +OnlyOnceErrorHandler::~OnlyOnceErrorHandler () +{ } + + +void +OnlyOnceErrorHandler::error(const log4cplus::tstring& err) +{ + if(firstTime) { + helpers::getLogLog().error(err); + firstTime = false; + } +} + + + +void +OnlyOnceErrorHandler::reset() +{ + firstTime = true; +} + + + +/////////////////////////////////////////////////////////////////////////////// +// log4cplus::Appender ctors +/////////////////////////////////////////////////////////////////////////////// + +Appender::Appender() + : layout(new SimpleLayout()), + name( LOG4CPLUS_TEXT("") ), + threshold(NOT_SET_LOG_LEVEL), + errorHandler(new OnlyOnceErrorHandler), + useLockFile(false), + closed(false) +{ +} + + + +Appender::Appender(const log4cplus::helpers::Properties & properties) + : layout(new SimpleLayout()) + , name() + , threshold(NOT_SET_LOG_LEVEL) + , errorHandler(new OnlyOnceErrorHandler) + , useLockFile(false) + , closed(false) +{ + if(properties.exists( LOG4CPLUS_TEXT("layout") )) + { + log4cplus::tstring const & factoryName + = properties.getProperty( LOG4CPLUS_TEXT("layout") ); + spi::LayoutFactory* factory + = spi::getLayoutFactoryRegistry().get(factoryName); + if(factory == 0) { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("Cannot find LayoutFactory: \"") + + factoryName + + LOG4CPLUS_TEXT("\"") ); + return; + } + + helpers::Properties layoutProperties = + properties.getPropertySubset( LOG4CPLUS_TEXT("layout.") ); + try { + std::auto_ptr<Layout> newLayout(factory->createObject(layoutProperties)); + if(newLayout.get() == 0) { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("Failed to create appender: ") + + factoryName); + } + else { + layout = newLayout; + } + } + catch(std::exception const & e) { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("Error while creating Layout: ") + + LOG4CPLUS_C_STR_TO_TSTRING(e.what())); + return; + } + + } + + // Support for appender.Threshold in properties configuration file + if(properties.exists(LOG4CPLUS_TEXT("Threshold"))) { + tstring tmp = properties.getProperty(LOG4CPLUS_TEXT("Threshold")); + tmp = log4cplus::helpers::toUpper(tmp); + threshold = log4cplus::getLogLevelManager().fromString(tmp); + } + + // Configure the filters + helpers::Properties filterProps + = properties.getPropertySubset( LOG4CPLUS_TEXT("filters.") ); + unsigned filterCount = 0; + spi::FilterPtr filterChain; + tstring filterName; + while (filterProps.exists( + filterName = helpers::convertIntegerToString (++filterCount))) + { + tstring const & factoryName = filterProps.getProperty(filterName); + spi::FilterFactory* factory + = spi::getFilterFactoryRegistry().get(factoryName); + + if(! factory) + { + tstring err = LOG4CPLUS_TEXT("Appender::ctor()- Cannot find FilterFactory: "); + helpers::getLogLog().error(err + factoryName); + continue; + } + spi::FilterPtr tmpFilter = factory->createObject ( + filterProps.getPropertySubset(filterName + LOG4CPLUS_TEXT("."))); + if (! tmpFilter) + { + tstring err = LOG4CPLUS_TEXT("Appender::ctor()- Failed to create filter: "); + helpers::getLogLog().error(err + filterName); + } + if (! filterChain) + filterChain = tmpFilter; + else + filterChain->appendFilter(tmpFilter); + } + setFilter(filterChain); + + properties.getBool (useLockFile, LOG4CPLUS_TEXT("UseLockFile")); + if (useLockFile) + { + tstring const & lockFileName + = properties.getProperty (LOG4CPLUS_TEXT ("LockFile")); + if (! lockFileName.empty ()) + { + try + { + lockFile.reset (new helpers::LockFile (lockFileName)); + } + catch (std::runtime_error const &) + { + return; + } + } + else + { + helpers::getLogLog ().debug ( + LOG4CPLUS_TEXT ( + "UseLockFile is true but LockFile is not specified")); + } + } +} + + +Appender::~Appender() +{ } + + + +/////////////////////////////////////////////////////////////////////////////// +// log4cplus::Appender public methods +/////////////////////////////////////////////////////////////////////////////// + +void +Appender::destructorImpl() +{ + helpers::getLogLog().debug( LOG4CPLUS_TEXT("Destroying appender named [") + + name + + LOG4CPLUS_TEXT("].")); + + // An appender might be closed then destroyed. There is no + // point in closing twice. + if(closed) + return; + + close(); + closed = true; +} + + + +void +Appender::doAppend(const log4cplus::spi::InternalLoggingEvent& event) +{ + thread::MutexGuard guard (access_mutex); + + if(closed) { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("Attempted to append to closed appender named [") + + name + + LOG4CPLUS_TEXT("].")); + return; + } + + // Check appender's threshold logging level. + + if (! isAsSevereAsThreshold(event.getLogLevel())) + return; + + // Evaluate filters attached to this appender. + + if (checkFilter(filter.get(), event) == spi::DENY) + return; + + // Lock system wide lock. + + helpers::LockFileGuard lfguard; + if (useLockFile && lockFile.get ()) + { + try + { + lfguard.attach_and_lock (*lockFile); + } + catch (std::runtime_error const &) + { + return; + } + } + + // Finally append given event. + + append(event); +} + + +tstring & +Appender::formatEvent (const spi::InternalLoggingEvent& event) const +{ + internal::appender_sratch_pad & appender_sp = internal::get_appender_sp (); + detail::clear_tostringstream (appender_sp.oss); + layout->formatAndAppend(appender_sp.oss, event); + appender_sp.oss.str().swap (appender_sp.str); + return appender_sp.str; +} + + +log4cplus::tstring +Appender::getName() +{ + return name; +} + + + +void +Appender::setName(const log4cplus::tstring& n) +{ + this->name = n; +} + + +ErrorHandler* +Appender::getErrorHandler() +{ + return errorHandler.get(); +} + + + +void +Appender::setErrorHandler(std::auto_ptr<ErrorHandler> eh) +{ + if (! eh.get()) + { + // We do not throw exception here since the cause is probably a + // bad config file. + helpers::getLogLog().warn( + LOG4CPLUS_TEXT("You have tried to set a null error-handler.")); + return; + } + + thread::MutexGuard guard (access_mutex); + + this->errorHandler = eh; +} + + + +void +Appender::setLayout(std::auto_ptr<Layout> lo) +{ + thread::MutexGuard guard (access_mutex); + + this->layout = lo; +} + + + +Layout* +Appender::getLayout() +{ + return layout.get(); +} + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/appenderattachableimpl.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/appenderattachableimpl.cxx new file mode 100644 index 000000000..7eb6953a5 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/appenderattachableimpl.cxx @@ -0,0 +1,174 @@ +// Module: Log4CPLUS +// File: appenderattachableimpl.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// +// Copyright 2001-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +#include <log4cplus/appender.h> +#include <log4cplus/helpers/appenderattachableimpl.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/spi/loggingevent.h> +#include <log4cplus/thread/syncprims-pub-impl.h> + +#include <algorithm> + + +namespace log4cplus +{ + + +namespace spi +{ + + +AppenderAttachable::~AppenderAttachable() +{ } + + +} // namespace spi + + +namespace helpers +{ + + +////////////////////////////////////////////////////////////////////////////// +// log4cplus::helpers::AppenderAttachableImpl ctor and dtor +////////////////////////////////////////////////////////////////////////////// + +AppenderAttachableImpl::AppenderAttachableImpl() +{ } + + +AppenderAttachableImpl::~AppenderAttachableImpl() +{ } + + + +/////////////////////////////////////////////////////////////////////////////// +// log4cplus::helpers::AppenderAttachableImpl public methods +/////////////////////////////////////////////////////////////////////////////// + +void +AppenderAttachableImpl::addAppender(SharedAppenderPtr newAppender) +{ + if(newAppender == NULL) { + getLogLog().warn( LOG4CPLUS_TEXT("Tried to add NULL appender") ); + return; + } + + thread::MutexGuard guard (appender_list_mutex); + + ListType::iterator it = + std::find(appenderList.begin(), appenderList.end(), newAppender); + if(it == appenderList.end()) { + appenderList.push_back(newAppender); + } +} + + + +AppenderAttachableImpl::ListType +AppenderAttachableImpl::getAllAppenders() +{ + thread::MutexGuard guard (appender_list_mutex); + + return appenderList; +} + + + +SharedAppenderPtr +AppenderAttachableImpl::getAppender(const log4cplus::tstring& name) +{ + thread::MutexGuard guard (appender_list_mutex); + + for(ListType::iterator it=appenderList.begin(); + it!=appenderList.end(); + ++it) + { + if((*it)->getName() == name) { + return *it; + } + } + + return SharedAppenderPtr(NULL); +} + + + +void +AppenderAttachableImpl::removeAllAppenders() +{ + thread::MutexGuard guard (appender_list_mutex); + + appenderList.erase(appenderList.begin(), appenderList.end()); +} + + + +void +AppenderAttachableImpl::removeAppender(SharedAppenderPtr appender) +{ + if(appender == NULL) { + getLogLog().warn( LOG4CPLUS_TEXT("Tried to remove NULL appender") ); + return; + } + + thread::MutexGuard guard (appender_list_mutex); + + ListType::iterator it = + std::find(appenderList.begin(), appenderList.end(), appender); + if(it != appenderList.end()) { + appenderList.erase(it); + } +} + + + +void +AppenderAttachableImpl::removeAppender(const log4cplus::tstring& name) +{ + removeAppender(getAppender(name)); +} + + + +int +AppenderAttachableImpl::appendLoopOnAppenders(const spi::InternalLoggingEvent& event) const +{ + int count = 0; + + thread::MutexGuard guard (appender_list_mutex); + + for(ListType::const_iterator it=appenderList.begin(); + it!=appenderList.end(); + ++it) + { + ++count; + (*it)->doAppend(event); + } + + return count; +} + + +} // namespace helpers + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/asyncappender.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/asyncappender.cxx new file mode 100644 index 000000000..c30c5eb61 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/asyncappender.cxx @@ -0,0 +1,198 @@ +// Copyright (C) 2009-2010, Vaclav Haisman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <log4cplus/config.hxx> +#ifndef LOG4CPLUS_SINGLE_THREADED + +#include <log4cplus/asyncappender.h> +#include <log4cplus/spi/factory.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/thread/syncprims-pub-impl.h> + + +namespace log4cplus +{ + + +namespace +{ + + +class QueueThread + : public thread::AbstractThread +{ +public: + QueueThread (AsyncAppenderPtr const &, thread::QueuePtr const &); + + virtual void run(); + +private: + AsyncAppenderPtr appenders; + thread::QueuePtr queue; +}; + + +QueueThread::QueueThread (AsyncAppenderPtr const & aai, + thread::QueuePtr const & q) + : appenders (aai) + , queue (q) +{ } + + +void +QueueThread::run() +{ + typedef log4cplus::thread::Queue::queue_storage_type ev_buf_type; + ev_buf_type ev_buf; + + while (true) + { + unsigned flags = queue->get_events (&ev_buf); + if (flags & thread::Queue::EVENT) + { + ev_buf_type::const_iterator const ev_buf_end = ev_buf.end (); + for (ev_buf_type::const_iterator it = ev_buf.begin (); + it != ev_buf_end; ++it) + appenders->appendLoopOnAppenders (*it); + } + + if (((thread::Queue::EXIT | thread::Queue::DRAIN + | thread::Queue::EVENT) & flags) + == (thread::Queue::EXIT | thread::Queue::DRAIN + | thread::Queue::EVENT)) + continue; + else if (thread::Queue::EXIT & flags) + break; + } +} + + +} // namespace + + +AsyncAppender::AsyncAppender (SharedAppenderPtr const & app, + unsigned queue_len) +{ + addAppender (app); + init_queue_thread (queue_len); +} + + +AsyncAppender::AsyncAppender (helpers::Properties const & props) +{ + tstring const & appender_name ( + props.getProperty (LOG4CPLUS_TEXT ("Appender"))); + if (appender_name.empty ()) + { + getErrorHandler ()->error ( + LOG4CPLUS_TEXT ("Unspecified appender for AsyncAppender.")); + return; + } + + spi::AppenderFactoryRegistry & appender_registry + = spi::getAppenderFactoryRegistry (); + spi::AppenderFactory * factory = appender_registry.get (appender_name); + if (! factory) + { + tstring const err (LOG4CPLUS_TEXT ("AsyncAppender::AsyncAppender()") + LOG4CPLUS_TEXT (" - Cannot find AppenderFactory: ")); + helpers::getLogLog ().error (err + appender_name); + // Add at least null appender so that we do not crash unexpectedly + // elsewhere. + // XXX: What about throwing an exception instead? + factory = appender_registry.get ( + LOG4CPLUS_TEXT ("log4cplus::NullAppender")); + } + + helpers::Properties appender_props = props.getPropertySubset ( + LOG4CPLUS_TEXT ("Appender.")); + addAppender (factory->createObject (appender_props)); + + unsigned queue_len = 100; + props.getUInt (queue_len, LOG4CPLUS_TEXT ("QueueLimit")); + + init_queue_thread (queue_len); +} + + +AsyncAppender::~AsyncAppender () +{ + destructorImpl (); +} + + +void +AsyncAppender::init_queue_thread (unsigned queue_len) +{ + queue = new thread::Queue (queue_len); + queue_thread = new QueueThread (AsyncAppenderPtr (this), queue); + queue_thread->start (); + helpers::getLogLog ().debug (LOG4CPLUS_TEXT("Queue thread started.")); +} + + +void +AsyncAppender::close () +{ + unsigned ret = queue->signal_exit (); + if (ret & (thread::Queue::ERROR_BIT | thread::Queue::ERROR_AFTER)) + getErrorHandler ()->error ( + LOG4CPLUS_TEXT ("Error in AsyncAppender::close")); + queue_thread->join (); +} + + +void +AsyncAppender::append (spi::InternalLoggingEvent const & ev) +{ + if (queue_thread && queue_thread->isRunning ()) + { + unsigned ret = queue->put_event (ev); + if (ret & (thread::Queue::ERROR_BIT | thread::Queue::ERROR_AFTER)) + { + getErrorHandler ()->error ( + LOG4CPLUS_TEXT ("Error in AsyncAppender::append,") + LOG4CPLUS_TEXT (" event queue has been lost.")); + // Exit the queue consumer thread without draining + // the events queue. + queue->signal_exit (false); + queue_thread->join (); + queue_thread = 0; + queue = 0; + appendLoopOnAppenders (ev); + } + } + else + { + // If the thread has died for any reason, fall back to synchronous + // operation. + appendLoopOnAppenders (ev); + } +} + + +} // namespace log4cplus + + +#endif // #ifndef LOG4CPLUS_SINGLE_THREADED diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/clfsappender.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/clfsappender.cxx new file mode 100644 index 000000000..06a406263 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/clfsappender.cxx @@ -0,0 +1,301 @@ +// Module: Log4cplus +// File: clfsappender.cxx +// Created: 5/2012 +// Author: Vaclav Zeman +// +// +// Copyright (C) 2012, Vaclav Zeman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <log4cplus/config.hxx> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/clfsappender.h> +#include <log4cplus/spi/factory.h> +#include <sstream> +#include <iomanip> +#include <cstring> +#include <log4cplus/config/windowsh-inc.h> +#include <clfsw32.h> +#include <clfsmgmtw32.h> + + +// Forward Declarations +namespace log4cplus +{ + +const unsigned CLFS_APPENDER_INITIAL_LOG_SIZE = 512 * 1024; +const ULONG CLFS_APPENDER_DEFAULT_BUFFER_SIZE = 1024 * 64; + + +namespace +{ + +static +void +loglog_win32_error (tchar const * msg) +{ + DWORD err = GetLastError (); + tostringstream oss; + oss << LOG4CPLUS_TEXT ("CLFSAppender: ") << msg << LOG4CPLUS_TEXT(": ") + << err << LOG4CPLUS_TEXT (" / 0x") + << std::setw (8) << std::setfill (LOG4CPLUS_TEXT ('0')) << std::hex + << err; + helpers::getLogLog ().error (oss.str ()); +} + +} + + +struct CLFSAppender::Data +{ + Data () + : log_name () + , log_handle (INVALID_HANDLE_VALUE) + , buffer (0) + , buffer_size (0) + { } + + tstring log_name; + HANDLE log_handle; + void * buffer; + ULONG buffer_size; +}; + + +CLFSAppender::CLFSAppender (tstring const & logname, unsigned long logsize, + unsigned long buffersize) + : Appender () + , data (new Data) +{ + init (logname, logsize, buffersize); +} + + +CLFSAppender::CLFSAppender (helpers::Properties const & props) + : Appender (props) + , data (new Data) +{ + tstring logname = props.getProperty (LOG4CPLUS_TEXT ("LogName")); + + unsigned long logsize = CLFS_APPENDER_INITIAL_LOG_SIZE; + props.getULong (logsize, LOG4CPLUS_TEXT ("LogSize")); + + unsigned long buffersize = CLFS_APPENDER_DEFAULT_BUFFER_SIZE; + props.getULong (buffersize, LOG4CPLUS_TEXT ("BufferSize")); + + init (logname, logsize, buffersize); +} + + +CLFSAppender::~CLFSAppender () +{ + destructorImpl (); + delete data; +} + + +void +CLFSAppender::init (tstring const & logname, unsigned long logsize, + unsigned long buffersize) +{ + data->log_name = logname; + data->buffer_size = buffersize; + + if (data->log_name.empty ()) + helpers::getLogLog ().error ( + LOG4CPLUS_TEXT ("CLFSAppender: empty log name"), true); + + CLFS_MGMT_POLICY log_policy; + std::memset (&log_policy, 0, sizeof (log_policy)); + log_policy.Version = CLFS_MGMT_POLICY_VERSION; + log_policy.LengthInBytes = sizeof (log_policy); + log_policy.PolicyFlags = 0; + + CLFS_INFORMATION log_info; + ULONG info_size = sizeof (log_info); + ULONGLONG desired_size; + ULONGLONG resulting_size; + + data->log_handle = CreateLogFile ( + helpers::towstring (data->log_name).c_str (), GENERIC_WRITE | GENERIC_READ, + FILE_SHARE_DELETE | FILE_SHARE_WRITE | FILE_SHARE_READ, 0, + OPEN_ALWAYS, FILE_ATTRIBUTE_ARCHIVE); + + if (data->log_handle == INVALID_HANDLE_VALUE) + { + loglog_win32_error (LOG4CPLUS_TEXT ("CreateLogFile()")); + goto error; + } + + if (! RegisterManageableLogClient (data->log_handle, 0)) + { + loglog_win32_error (LOG4CPLUS_TEXT ("RegisterManageableLogClient()")); + goto error; + } + + + if (! GetLogFileInformation (data->log_handle, &log_info, &info_size)) + { + loglog_win32_error (LOG4CPLUS_TEXT ("GetLogFileInformation()")); + goto error; + } + + if (log_info.TotalContainers == 0) + { + log_policy.PolicyType = ClfsMgmtPolicyNewContainerSize; + log_policy.PolicyParameters.NewContainerSize.SizeInBytes = logsize; + if (! InstallLogPolicy (data->log_handle, &log_policy)) + { + loglog_win32_error ( + LOG4CPLUS_TEXT ("InstallLogPolicy(ClfsMgmtPolicyNewContainerSize)")); + goto error; + } + } + + desired_size = 0; + resulting_size = 0; + if (! SetLogFileSizeWithPolicy (data->log_handle, &desired_size, + &resulting_size)) + { + loglog_win32_error (LOG4CPLUS_TEXT ("SetLogFileSizeWithPolicy()")); + goto error; + } + + log_policy.PolicyType = ClfsMgmtPolicyAutoGrow; + log_policy.PolicyParameters.AutoGrow.Enabled = true; + if (! InstallLogPolicy (data->log_handle, &log_policy)) + { + loglog_win32_error ( + LOG4CPLUS_TEXT ("InstallLogPolicy(ClfsMgmtPolicyAutoGrow)")); + goto error; + } + + log_policy.PolicyType = ClfsMgmtPolicyGrowthRate; + log_policy.PolicyParameters.GrowthRate.AbsoluteGrowthInContainers = 0; + log_policy.PolicyParameters.GrowthRate.RelativeGrowthPercentage = 10; + if (! InstallLogPolicy (data->log_handle, &log_policy)) + { + loglog_win32_error ( + LOG4CPLUS_TEXT ("InstallLogPolicy(ClfsMgmtPolicyGrowthRate)")); + goto error; + } + + // TODO: Get underlying media sector size using GetDiskFreeSpace(). + // TODO: What are reasonable values for cMaxWriteBuffers + // and cMaxReadBuffers? + if (! CreateLogMarshallingArea (data->log_handle, 0, 0, 0, + data->buffer_size, 8, 1, &data->buffer)) + { + loglog_win32_error (LOG4CPLUS_TEXT ("CreateLogMarshallingArea")); + goto error; + } + + return; + +error: + if (data->log_handle != INVALID_HANDLE_VALUE) + { + CloseHandle (data->log_handle); + data->log_handle = INVALID_HANDLE_VALUE; + } + + return; +} + + +void +CLFSAppender::close () +{ + if (data->log_handle != INVALID_HANDLE_VALUE) + { + CloseHandle (data->log_handle); + data->log_handle = INVALID_HANDLE_VALUE; + } +} + + +void +CLFSAppender::append (spi::InternalLoggingEvent const & ev) +{ + if (data->log_handle == INVALID_HANDLE_VALUE) + return; + + // TODO: Expose log4cplus' internal TLS to use here. + tostringstream oss; + layout->formatAndAppend(oss, ev); + + tstring str; + oss.str ().swap (str); + if ((str.size () + 1) * sizeof (tchar) > data->buffer_size) + str.resize (data->buffer_size / sizeof (tchar)); + + CLFS_WRITE_ENTRY clfs_write_entry; + clfs_write_entry.Buffer = const_cast<tchar *>(str.c_str ()); + clfs_write_entry.ByteLength + = static_cast<ULONG>((str.size () + 1) * sizeof (tchar)); + + if (! ReserveAndAppendLog (data->buffer, &clfs_write_entry, 1, 0, 0, 0, 0, + CLFS_FLAG_FORCE_APPEND, 0, 0)) + loglog_win32_error (LOG4CPLUS_TEXT ("ReserveAndAppendLog")); +} + + +void +CLFSAppender::registerAppender () +{ + log4cplus::spi::AppenderFactoryRegistry & reg + = log4cplus::spi::getAppenderFactoryRegistry (); + LOG4CPLUS_REG_APPENDER (reg, CLFSAppender); +} + + +} // namespace log4cplus + + +extern "C" +BOOL WINAPI DllMain(LOG4CPLUS_DLLMAIN_HINSTANCE, // handle to DLL module + DWORD fdwReason, // reason for calling function + LPVOID) // reserved +{ + // Perform actions based on the reason for calling. + switch( fdwReason ) + { + case DLL_PROCESS_ATTACH: + { + log4cplus::CLFSAppender::registerAppender (); + break; + } + + case DLL_THREAD_ATTACH: + break; + + case DLL_THREAD_DETACH: + break; + + case DLL_PROCESS_DETACH: + break; + } + + return TRUE; // Successful DLL_PROCESS_ATTACH. +} diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/clogger.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/clogger.cxx new file mode 100644 index 000000000..f8578ffad --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/clogger.cxx @@ -0,0 +1,190 @@ +// Module: Log4CPLUS +// File: clogger.cxx +// Created: 01/2011 +// Author: Jens Rehsack +// +// +// Copyright 2011 Jens Rehsack & Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/logger.h> +#include <log4cplus/clogger.h> +#include <log4cplus/appender.h> +#include <log4cplus/hierarchy.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/spi/loggerimpl.h> +#include <log4cplus/configurator.h> +#include <log4cplus/streams.h> +#include <log4cplus/helpers/snprintf.h> + +#include <cerrno> +#include <cstdio> +#include <cstdarg> +#include <cstring> + +#include <sstream> + +using namespace log4cplus; +using namespace log4cplus::helpers; + +LOG4CPLUS_EXPORT int +log4cplus_file_configure(const log4cplus_char_t *pathname) +{ + if( !pathname ) + return EINVAL; + + try + { + PropertyConfigurator::doConfigure( pathname ); + } + catch(std::exception const &) + { + return -1; + } + + return 0; +} + +LOG4CPLUS_EXPORT int +log4cplus_str_configure(const log4cplus_char_t *config) +{ + if( !config ) + return EINVAL; + + try + { + tstring s(config); + tistringstream iss(s); + PropertyConfigurator pc(iss); + pc.configure(); + } + catch(std::exception const &) + { + return -1; + } + + return 0; +} + +LOG4CPLUS_EXPORT int +log4cplus_basic_configure(void) +{ + try + { + BasicConfigurator::doConfigure(); + } + catch(std::exception const &) + { + return -1; + } + + return 0; +} + +LOG4CPLUS_EXPORT void +log4cplus_shutdown(void) +{ + Logger::shutdown(); +} + +LOG4CPLUS_EXPORT int +log4cplus_logger_exists(const log4cplus_char_t *name) +{ + int retval = false; + + try + { + retval = Logger::exists(name); + } + catch(std::exception const &) + { + // Fall through. + } + + return retval; +} + +LOG4CPLUS_EXPORT int +log4cplus_logger_is_enabled_for(const log4cplus_char_t *name, loglevel_t ll) +{ + int retval = false; + + try + { + Logger logger = name ? Logger::getInstance(name) : Logger::getRoot(); + retval = logger.isEnabledFor(ll); + } + catch(std::exception const &) + { + // Fall through. + } + + return retval; +} + +LOG4CPLUS_EXPORT int +log4cplus_logger_log(const log4cplus_char_t *name, loglevel_t ll, + const log4cplus_char_t *msgfmt, ...) +{ + int retval = -1; + + try + { + Logger logger = name ? Logger::getInstance(name) : Logger::getRoot(); + + if( logger.isEnabledFor(ll) ) + { + std::va_list ap; + va_start(ap, msgfmt); + snprintf_buf buf; + const tchar * msg = buf.print_va_list(msgfmt, ap); + va_end(ap); + logger.forcedLog(ll, msg); + } + + retval = 0; + } + catch(std::exception const &) + { + // Fall through. + } + + return retval; +} + +LOG4CPLUS_EXPORT int +log4cplus_logger_force_log(const log4cplus_char_t *name, loglevel_t ll, const log4cplus_char_t *msgfmt, ...) +{ + int retval = -1; + + try + { + Logger logger = name ? Logger::getInstance(name) : Logger::getRoot(); + + std::va_list ap; + va_start(ap, msgfmt); + snprintf_buf buf; + const tchar * msg = buf.print_va_list(msgfmt, ap); + va_end(ap); + logger.forcedLog(ll, msg); + + retval = 0; + } + catch(std::exception const &) + { + // Fall through. + } + + return retval; +} diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/configurator.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/configurator.cxx new file mode 100644 index 000000000..5fbab28f3 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/configurator.cxx @@ -0,0 +1,749 @@ +// Module: LOG4CPLUS +// File: configurator.cxx +// Created: 3/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/configurator.h> +#include <log4cplus/hierarchylocker.h> +#include <log4cplus/hierarchy.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/sleep.h> +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/helpers/timehelper.h> +#include <log4cplus/helpers/fileinfo.h> +#include <log4cplus/thread/threads.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <log4cplus/spi/factory.h> +#include <log4cplus/spi/loggerimpl.h> +#include <log4cplus/internal/env.h> + +#ifdef LOG4CPLUS_HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#ifdef LOG4CPLUS_HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif + +#ifdef LOG4CPLUS_HAVE_STDLIB_H +#include <stdlib.h> +#endif +#if defined (_WIN32) +#include <tchar.h> +#endif + +#include <algorithm> +#include <cstdlib> +#include <iterator> +#include <sstream> +#include <functional> + + +namespace log4cplus +{ + + +void initializeLog4cplus(); + + +namespace +{ + static tchar const DELIM_START[] = LOG4CPLUS_TEXT("${"); + static tchar const DELIM_STOP[] = LOG4CPLUS_TEXT("}"); + static std::size_t const DELIM_START_LEN = 2; + static std::size_t const DELIM_STOP_LEN = 1; + + + /** + * Perform variable substitution in string <code>val</code> from + * environment variables. + * + * <p>The variable substitution delimeters are <b>${</b> and <b>}</b>. + * + * <p>For example, if the System properties contains "key=value", then + * the call + * <pre> + * string s; + * substEnvironVars(s, "Value of key is ${key}."); + * </pre> + * + * will set the variable <code>s</code> to "Value of key is value.". + * + * <p>If no value could be found for the specified key, then + * substitution defaults to the empty string. + * + * <p>For example, if there is no environment variable "inexistentKey", + * then the call + * + * <pre> + * string s; + * substEnvironVars(s, "Value of inexistentKey is [${inexistentKey}]"); + * </pre> + * will set <code>s</code> to "Value of inexistentKey is []" + * + * @param val The string on which variable substitution is performed. + * @param dest The result. + */ + static + bool + substVars (tstring & dest, const tstring & val, + helpers::Properties const & props, helpers::LogLog& loglog, + unsigned flags) + { + tstring::size_type i = 0; + tstring::size_type var_start, var_end; + tstring pattern (val); + tstring key; + tstring replacement; + bool changed = false; + bool const empty_vars + = !! (flags & PropertyConfigurator::fAllowEmptyVars); + bool const shadow_env + = !! (flags & PropertyConfigurator::fShadowEnvironment); + bool const rec_exp + = !! (flags & PropertyConfigurator::fRecursiveExpansion); + + while (true) + { + // Find opening paren of variable substitution. + var_start = pattern.find(DELIM_START, i); + if (var_start == tstring::npos) + { + dest = pattern; + return changed; + } + + // Find closing paren of variable substitution. + var_end = pattern.find(DELIM_STOP, var_start); + if (var_end == tstring::npos) + { + tostringstream buffer; + buffer << '"' << pattern + << "\" has no closing brace. " + << "Opening brace at position " << var_start << "."; + loglog.error(buffer.str()); + dest = val; + return false; + } + + key.assign (pattern, var_start + DELIM_START_LEN, + var_end - (var_start + DELIM_START_LEN)); + replacement.clear (); + if (shadow_env) + replacement = props.getProperty (key); + if (! shadow_env || (! empty_vars && replacement.empty ())) + internal::get_env_var (replacement, key); + + if (empty_vars || ! replacement.empty ()) + { + // Substitute the variable with its value in place. + pattern.replace (var_start, var_end - var_start + DELIM_STOP_LEN, + replacement); + changed = true; + if (rec_exp) + // Retry expansion on the same spot. + continue; + else + // Move beyond the just substituted part. + i = var_start + replacement.size (); + } + else + // Nothing has been subtituted, just move beyond the + // unexpanded variable. + i = var_end + DELIM_STOP_LEN; + } // end while loop + + } // end substVars() + + + //! Translates encoding in ProtpertyConfigurator::PCFlags + //! to helpers::Properties::PFlags + static + unsigned + pcflag_to_pflags_encoding (unsigned pcflags) + { + switch (pcflags + & (PropertyConfigurator::fEncodingMask + << PropertyConfigurator::fEncodingShift)) + { +#if defined (LOG4CPLUS_HAVE_CODECVT_UTF8_FACET) && defined (UNICODE) + case PropertyConfigurator::fUTF8: + return helpers::Properties::fUTF8; +#endif + +#if (defined (LOG4CPLUS_HAVE_CODECVT_UTF16_FACET) || defined (WIN32)) \ + && defined (UNICODE) + case PropertyConfigurator::fUTF16: + return helpers::Properties::fUTF16; +#endif + +#if defined (LOG4CPLUS_HAVE_CODECVT_UTF32_FACET) && defined (UNICODE) + case PropertyConfigurator::fUTF32: + return helpers::Properties::fUTF32; +#endif + + case PropertyConfigurator::fUnspecEncoding:; + default: + return 0; + } + } + +} // namespace + + + +////////////////////////////////////////////////////////////////////////////// +// PropertyConfigurator ctor and dtor +////////////////////////////////////////////////////////////////////////////// + +PropertyConfigurator::PropertyConfigurator(const tstring& propertyFile, + Hierarchy& hier, unsigned f) + : h(hier) + , propertyFilename(propertyFile) + , properties(propertyFile, pcflag_to_pflags_encoding (f)) + , flags (f) +{ + init(); +} + + +PropertyConfigurator::PropertyConfigurator(const helpers::Properties& props, + Hierarchy& hier, unsigned f) + : h(hier) + , propertyFilename( LOG4CPLUS_TEXT("UNAVAILABLE") ) + , properties( props ) + , flags (f) +{ + init(); +} + + +PropertyConfigurator::PropertyConfigurator(tistream& propertyStream, + Hierarchy& hier, unsigned f) + : h(hier) + , propertyFilename( LOG4CPLUS_TEXT("UNAVAILABLE") ) + , properties(propertyStream) + , flags (f) +{ + init(); +} + + +void +PropertyConfigurator::init() +{ + replaceEnvironVariables(); + properties = properties.getPropertySubset( LOG4CPLUS_TEXT("log4cplus.") ); +} + + +PropertyConfigurator::~PropertyConfigurator() +{ +} + + + +////////////////////////////////////////////////////////////////////////////// +// PropertyConfigurator static methods +////////////////////////////////////////////////////////////////////////////// + +void +PropertyConfigurator::doConfigure(const tstring& file, Hierarchy& h, + unsigned flags) +{ + PropertyConfigurator tmp(file, h, flags); + tmp.configure(); +} + + + +////////////////////////////////////////////////////////////////////////////// +// PropertyConfigurator public methods +////////////////////////////////////////////////////////////////////////////// + +void +PropertyConfigurator::configure() +{ + // Configure log4cplus internals. + bool internal_debugging = false; + if (properties.getBool (internal_debugging, LOG4CPLUS_TEXT ("configDebug"))) + helpers::getLogLog ().setInternalDebugging (internal_debugging); + + bool quiet_mode = false; + if (properties.getBool (quiet_mode, LOG4CPLUS_TEXT ("quietMode"))) + helpers::getLogLog ().setQuietMode (quiet_mode); + + bool disable_override = false; + if (properties.getBool (disable_override, + LOG4CPLUS_TEXT ("disableOverride"))) + + initializeLog4cplus(); + configureAppenders(); + configureLoggers(); + configureAdditivity(); + + if (disable_override) + h.disable (Hierarchy::DISABLE_OVERRIDE); + + // Erase the appenders so that we are not artificially keeping them "alive". + appenders.clear (); +} + + +helpers::Properties const & +PropertyConfigurator::getProperties () const +{ + return properties; +} + + +log4cplus::tstring const & +PropertyConfigurator::getPropertyFilename () const +{ + return propertyFilename; +} + + +////////////////////////////////////////////////////////////////////////////// +// PropertyConfigurator protected methods +////////////////////////////////////////////////////////////////////////////// + +void +PropertyConfigurator::reconfigure() +{ + properties = helpers::Properties(propertyFilename); + init(); + configure(); +} + + +void +PropertyConfigurator::replaceEnvironVariables() +{ + tstring val, subKey, subVal; + std::vector<tstring> keys; + bool const rec_exp + = !! (flags & PropertyConfigurator::fRecursiveExpansion); + bool changed; + + do + { + changed = false; + properties.propertyNames().swap (keys); + for (std::vector<tstring>::const_iterator it = keys.begin(); + it != keys.end(); ++it) + { + tstring const & key = *it; + val = properties.getProperty(key); + + subKey.clear (); + if (substVars(subKey, key, properties, helpers::getLogLog(), flags)) + { + properties.removeProperty(key); + properties.setProperty(subKey, val); + changed = true; + } + + subVal.clear (); + if (substVars(subVal, val, properties, helpers::getLogLog(), flags)) + { + properties.setProperty(subKey, subVal); + changed = true; + } + } + } + while (changed && rec_exp); +} + + + +void +PropertyConfigurator::configureLoggers() +{ + if(properties.exists( LOG4CPLUS_TEXT("rootLogger") )) + { + Logger root = h.getRoot(); + configureLogger(root, + properties.getProperty(LOG4CPLUS_TEXT("rootLogger"))); + } + + helpers::Properties loggerProperties + = properties.getPropertySubset(LOG4CPLUS_TEXT("logger.")); + std::vector<tstring> loggers = loggerProperties.propertyNames(); + for(std::vector<tstring>::iterator it=loggers.begin(); it!=loggers.end(); + ++it) + { + Logger log = getLogger(*it); + configureLogger(log, loggerProperties.getProperty(*it)); + } +} + + + +void +PropertyConfigurator::configureLogger(Logger logger, const tstring& config) +{ + // Remove all spaces from config + tstring configString; + std::remove_copy_if(config.begin(), config.end(), + std::back_inserter (configString), + std::bind1st(std::equal_to<tchar>(), LOG4CPLUS_TEXT(' '))); + + // "Tokenize" configString + std::vector<tstring> tokens; + helpers::tokenize(configString, LOG4CPLUS_TEXT(','), + std::back_insert_iterator<std::vector<tstring> >(tokens)); + + if (tokens.empty ()) + { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("PropertyConfigurator::configureLogger()") + LOG4CPLUS_TEXT("- Invalid config string(Logger = ") + + logger.getName() + + LOG4CPLUS_TEXT("): \"") + + config + + LOG4CPLUS_TEXT("\"")); + return; + } + + // Set the loglevel + tstring const & loglevel = tokens[0]; + if (loglevel != LOG4CPLUS_TEXT("INHERITED")) + logger.setLogLevel( getLogLevelManager().fromString(loglevel) ); + else + logger.setLogLevel (NOT_SET_LOG_LEVEL); + + // Remove all existing appenders first so that we do not duplicate output. + logger.removeAllAppenders (); + + // Set the Appenders + for(std::vector<tstring>::size_type j=1; j<tokens.size(); ++j) + { + AppenderMap::iterator appenderIt = appenders.find(tokens[j]); + if (appenderIt == appenders.end()) + { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("PropertyConfigurator::configureLogger()") + LOG4CPLUS_TEXT("- Invalid appender: ") + + tokens[j]); + continue; + } + addAppender(logger, appenderIt->second); + } +} + + + +void +PropertyConfigurator::configureAppenders() +{ + helpers::Properties appenderProperties = + properties.getPropertySubset(LOG4CPLUS_TEXT("appender.")); + std::vector<tstring> appendersProps = appenderProperties.propertyNames(); + tstring factoryName; + for(std::vector<tstring>::iterator it=appendersProps.begin(); + it != appendersProps.end(); ++it) + { + if( it->find( LOG4CPLUS_TEXT('.') ) == tstring::npos ) + { + factoryName = appenderProperties.getProperty(*it); + spi::AppenderFactory* factory + = spi::getAppenderFactoryRegistry().get(factoryName); + if (! factory) + { + tstring err = + LOG4CPLUS_TEXT("PropertyConfigurator::configureAppenders()") + LOG4CPLUS_TEXT("- Cannot find AppenderFactory: "); + helpers::getLogLog().error(err + factoryName); + continue; + } + + helpers::Properties props_subset + = appenderProperties.getPropertySubset((*it) + + LOG4CPLUS_TEXT(".")); + try + { + SharedAppenderPtr appender + = factory->createObject(props_subset); + if (! appender) + { + tstring err = + LOG4CPLUS_TEXT("PropertyConfigurator::") + LOG4CPLUS_TEXT("configureAppenders()") + LOG4CPLUS_TEXT("- Failed to create appender: "); + helpers::getLogLog().error(err + *it); + } + else + { + appender->setName(*it); + appenders[*it] = appender; + } + } + catch(std::exception const & e) + { + tstring err = + LOG4CPLUS_TEXT("PropertyConfigurator::") + LOG4CPLUS_TEXT("configureAppenders()") + LOG4CPLUS_TEXT("- Error while creating Appender: "); + helpers::getLogLog().error(err + LOG4CPLUS_C_STR_TO_TSTRING(e.what())); + } + } + } // end for loop +} + + +void +PropertyConfigurator::configureAdditivity() +{ + helpers::Properties additivityProperties = + properties.getPropertySubset(LOG4CPLUS_TEXT("additivity.")); + std::vector<tstring> additivitysProps + = additivityProperties.propertyNames(); + + for(std::vector<tstring>::const_iterator it = additivitysProps.begin(); + it != additivitysProps.end(); ++it) + { + Logger logger = getLogger(*it); + bool additivity; + if (additivityProperties.getBool (additivity, *it)) + logger.setAdditivity (additivity); + } +} + + + +Logger +PropertyConfigurator::getLogger(const tstring& name) +{ + return h.getInstance(name); +} + + +void +PropertyConfigurator::addAppender(Logger &logger, SharedAppenderPtr& appender) +{ + logger.addAppender(appender); +} + + + +////////////////////////////////////////////////////////////////////////////// +// BasicConfigurator ctor and dtor +////////////////////////////////////////////////////////////////////////////// + +log4cplus::tstring DISABLE_OVERRIDE_KEY ( + LOG4CPLUS_TEXT ("log4cplus.disableOverride")); + +BasicConfigurator::BasicConfigurator(Hierarchy& hier, bool logToStdErr) + : PropertyConfigurator( LOG4CPLUS_TEXT(""), hier ) +{ + properties.setProperty(LOG4CPLUS_TEXT("rootLogger"), + LOG4CPLUS_TEXT("DEBUG, STDOUT")); + properties.setProperty(LOG4CPLUS_TEXT("appender.STDOUT"), + LOG4CPLUS_TEXT("log4cplus::ConsoleAppender")); + properties.setProperty(LOG4CPLUS_TEXT("appender.STDOUT.logToStdErr"), + logToStdErr ? LOG4CPLUS_TEXT("1") + : LOG4CPLUS_TEXT("0")); +} + + + + +BasicConfigurator::~BasicConfigurator() +{ +} + + +////////////////////////////////////////////////////////////////////////////// +// BasicConfigurator static methods +////////////////////////////////////////////////////////////////////////////// + +void +BasicConfigurator::doConfigure(Hierarchy& h, bool logToStdErr) +{ + BasicConfigurator tmp(h, logToStdErr); + tmp.configure(); +} + + +#if !defined(LOG4CPLUS_SINGLE_THREADED) + +////////////////////////////////////////////////////////////////////////////// +// ConfigurationWatchDogThread implementation +////////////////////////////////////////////////////////////////////////////// + +class ConfigurationWatchDogThread + : public thread::AbstractThread, + public PropertyConfigurator +{ +public: + ConfigurationWatchDogThread(const tstring& file, unsigned int millis) + : PropertyConfigurator(file) + , waitMillis(millis < 1000 ? 1000 : millis) + , shouldTerminate(false) + , lock(NULL) + { + lastFileInfo.mtime = helpers::Time::gettimeofday (); + lastFileInfo.size = 0; + lastFileInfo.is_link = false; + + updateLastModInfo(); + } + + virtual ~ConfigurationWatchDogThread () + { } + + void terminate () + { + shouldTerminate.signal (); + join (); + } + +protected: + virtual void run(); + virtual Logger getLogger(const tstring& name); + virtual void addAppender(Logger &logger, SharedAppenderPtr& appender); + + bool checkForFileModification(); + void updateLastModInfo(); + +private: + ConfigurationWatchDogThread (ConfigurationWatchDogThread const &); + ConfigurationWatchDogThread & operator = ( + ConfigurationWatchDogThread const &); + + unsigned int const waitMillis; + thread::ManualResetEvent shouldTerminate; + helpers::FileInfo lastFileInfo; + HierarchyLocker* lock; +}; + + +void +ConfigurationWatchDogThread::run() +{ + while (! shouldTerminate.timed_wait (waitMillis)) + { + bool modified = checkForFileModification(); + if(modified) { + // Lock the Hierarchy + HierarchyLocker theLock(h); + lock = &theLock; + + // reconfigure the Hierarchy + theLock.resetConfiguration(); + reconfigure(); + updateLastModInfo(); + + // release the lock + lock = NULL; + } + } +} + + +Logger +ConfigurationWatchDogThread::getLogger(const tstring& name) +{ + if(lock) + return lock->getInstance(name); + else + return PropertyConfigurator::getLogger(name); +} + + +void +ConfigurationWatchDogThread::addAppender(Logger& logger, + SharedAppenderPtr& appender) +{ + if(lock) + lock->addAppender(logger, appender); + else + PropertyConfigurator::addAppender(logger, appender); +} + + +bool +ConfigurationWatchDogThread::checkForFileModification() +{ + helpers::FileInfo fi; + + if (helpers::getFileInfo (&fi, propertyFilename) != 0) + return false; + + bool modified = fi.mtime > lastFileInfo.mtime + || fi.size != lastFileInfo.size; + +#if defined(LOG4CPLUS_HAVE_LSTAT) + if (!modified && fi.is_link) + { + struct stat fileStatus; + if (lstat(LOG4CPLUS_TSTRING_TO_STRING(propertyFilename).c_str(), + &fileStatus) == -1) + return false; + + helpers::Time linkModTime(fileStatus.st_mtime); + modified = (linkModTime > fi.mtime); + } +#endif + + return modified; +} + + + +void +ConfigurationWatchDogThread::updateLastModInfo() +{ + helpers::FileInfo fi; + + if (helpers::getFileInfo (&fi, propertyFilename) == 0) + lastFileInfo = fi; +} + + + +////////////////////////////////////////////////////////////////////////////// +// PropertyConfiguratorWatchDog ctor and dtor +////////////////////////////////////////////////////////////////////////////// + +ConfigureAndWatchThread::ConfigureAndWatchThread(const tstring& file, + unsigned int millis) + : watchDogThread(0) +{ + watchDogThread = new ConfigurationWatchDogThread(file, millis); + watchDogThread->addReference (); + watchDogThread->configure(); + watchDogThread->start(); +} + + +ConfigureAndWatchThread::~ConfigureAndWatchThread() +{ + if (watchDogThread) + { + watchDogThread->terminate(); + watchDogThread->removeReference (); + } +} + + +#endif + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/consoleappender.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/consoleappender.cxx new file mode 100644 index 000000000..021d3d984 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/consoleappender.cxx @@ -0,0 +1,113 @@ +// Module: Log4CPLUS +// File: consoleappender.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// +// Copyright 2001-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/layout.h> +#include <log4cplus/consoleappender.h> +#include <log4cplus/streams.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/spi/loggingevent.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <ostream> + + +namespace log4cplus +{ + + +namespace helpers +{ + +extern log4cplus::thread::Mutex const & getConsoleOutputMutex (); + +} // namespace helpers + + +log4cplus::thread::Mutex const & +ConsoleAppender::getOutputMutex () +{ + return helpers::getConsoleOutputMutex (); +} + + +////////////////////////////////////////////////////////////////////////////// +// ConsoleAppender ctors and dtor +////////////////////////////////////////////////////////////////////////////// + +ConsoleAppender::ConsoleAppender(bool logToStdErr_, + bool immediateFlush_) +: logToStdErr(logToStdErr_), + immediateFlush(immediateFlush_) +{ +} + + + +ConsoleAppender::ConsoleAppender(const helpers::Properties & properties) +: Appender(properties), + logToStdErr(false), + immediateFlush(false) +{ + properties.getBool (logToStdErr, LOG4CPLUS_TEXT("logToStdErr")); + properties.getBool (immediateFlush, LOG4CPLUS_TEXT("ImmediateFlush")); +} + + + +ConsoleAppender::~ConsoleAppender() +{ + destructorImpl(); +} + + + +////////////////////////////////////////////////////////////////////////////// +// ConsoleAppender public methods +////////////////////////////////////////////////////////////////////////////// + +void +ConsoleAppender::close() +{ + helpers::getLogLog().debug( + LOG4CPLUS_TEXT("Entering ConsoleAppender::close()..")); + closed = true; +} + + + +////////////////////////////////////////////////////////////////////////////// +// ConsoleAppender protected methods +////////////////////////////////////////////////////////////////////////////// + +void +ConsoleAppender::append(const spi::InternalLoggingEvent& event) +{ + thread::MutexGuard guard (getOutputMutex ()); + + tostream& output = (logToStdErr ? tcerr : tcout); + layout->formatAndAppend(output, event); + if(immediateFlush) { + output.flush(); + } +} + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/cygwin-win32.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/cygwin-win32.cxx new file mode 100644 index 000000000..0badce539 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/cygwin-win32.cxx @@ -0,0 +1,47 @@ +// Module: Log4CPLUS +// File: cygwin-win32.cxx +// Created: 7/2011 +// Author: Vaclav Zeman +// +// Copyright (C) 2011, Vaclav Zeman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#if defined (__CYGWIN__) +#include <log4cplus/internal/cygwin-win32.h> + +// This is intentionally included directly instead of through +// windowsh-inc.h. +#include <winsock2.h> + + +namespace log4cplus { namespace cygwin { + +unsigned long +get_current_win32_thread_id () +{ + return GetCurrentThreadId (); +} + +} } // namespace log4cplus { namespace cygwin { + +#endif // defined (__CYGWIN__) diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/env.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/env.cxx new file mode 100644 index 000000000..43186449c --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/env.cxx @@ -0,0 +1,101 @@ +// Copyright (C) 2010, Vaclav Haisman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <log4cplus/internal/env.h> +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/streams.h> + +#ifdef LOG4CPLUS_HAVE_STDLIB_H +#include <stdlib.h> +#endif + +#ifdef LOG4CPLUS_HAVE_WCHAR_H +#include <wchar.h> +#endif + + +#include <cassert> +#include <cstdlib> +#include <sstream> + + +namespace log4cplus { namespace internal { + + +bool +get_env_var (tstring & value, tstring const & name) +{ +#if defined (_WIN32) && defined (UNICODE) + tchar const * val = _wgetenv (name.c_str ()); + if (val) + value = val; + + return !! val; + +#else + char const * val + = std::getenv (LOG4CPLUS_TSTRING_TO_STRING (name).c_str ()); + if (val) + value = LOG4CPLUS_STRING_TO_TSTRING (val); + + return !! val; + +#endif +} + + +bool +parse_bool (bool & val, tstring const & str) +{ + log4cplus::tistringstream iss (str); + log4cplus::tstring word; + if (! (iss >> word)) + return false; + tchar ch; + if (iss >> ch) + return false; + word = helpers::toLower (word); + + bool result = true; + if (word == LOG4CPLUS_TEXT ("true")) + val = true; + else if (word == LOG4CPLUS_TEXT ("false")) + val = false; + else + { + iss.clear (); + iss.seekg (0); + assert (iss); + + long lval; + iss >> lval; + result = !! iss && ! (iss >> ch); + if (result) + val = !! lval; + } + + return result; +} + + +} } // namespace log4cplus { namespace internal { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/factory.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/factory.cxx new file mode 100644 index 000000000..dae83219a --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/factory.cxx @@ -0,0 +1,187 @@ +// Module: Log4CPLUS +// File: factory.cxx +// Created: 2/2002 +// Author: Tad E. Smith +// +// +// Copyright 2002-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/spi/factory.h> +#include <log4cplus/spi/loggerfactory.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/thread-config.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/asyncappender.h> +#include <log4cplus/consoleappender.h> +#include <log4cplus/fileappender.h> +#include <log4cplus/nteventlogappender.h> +#include <log4cplus/nullappender.h> +#include <log4cplus/socketappender.h> +#include <log4cplus/syslogappender.h> +#include <log4cplus/win32debugappender.h> +#include <log4cplus/win32consoleappender.h> +#include <log4cplus/log4judpappender.h> + + +/////////////////////////////////////////////////////////////////////////////// +// LOCAL file class definitions +/////////////////////////////////////////////////////////////////////////////// + +namespace log4cplus { + +namespace spi { + +BaseFactory::~BaseFactory() +{ } + + +AppenderFactory::AppenderFactory() +{ } + +AppenderFactory::~AppenderFactory() +{ } + + +LayoutFactory::LayoutFactory() +{ } + +LayoutFactory::~LayoutFactory() +{ } + + +FilterFactory::FilterFactory() +{ } + +FilterFactory::~FilterFactory() +{ } + + +LocaleFactory::LocaleFactory() +{ } + +LocaleFactory::~LocaleFactory() +{ } + + +LoggerFactory::~LoggerFactory() +{ } + + +namespace +{ + +class GlobalLocale + : public LocalFactoryBase<LocaleFactory> +{ +public: + GlobalLocale (tchar const * n) + : LocalFactoryBase<LocaleFactory> (n) + { } + + virtual + ProductPtr + createObject (const log4cplus::helpers::Properties &) + { + return std::locale (); + } +}; + + +class UserLocale + : public LocalFactoryBase<LocaleFactory> +{ +public: + UserLocale (tchar const * n) + : LocalFactoryBase<LocaleFactory> (n) + { } + + virtual + ProductPtr + createObject (const log4cplus::helpers::Properties &) + { + return std::locale (""); + } +}; + + +class ClassicLocale + : public LocalFactoryBase<LocaleFactory> +{ +public: + ClassicLocale (tchar const * n) + : LocalFactoryBase<LocaleFactory> (n) + { } + + virtual + ProductPtr + createObject (const log4cplus::helpers::Properties &) + { + return std::locale::classic (); + } +}; + + +} // namespace + + + + +} // namespace spi + + +void initializeFactoryRegistry() +{ + spi::AppenderFactoryRegistry& reg = spi::getAppenderFactoryRegistry(); + LOG4CPLUS_REG_APPENDER (reg, ConsoleAppender); + LOG4CPLUS_REG_APPENDER (reg, NullAppender); + LOG4CPLUS_REG_APPENDER (reg, FileAppender); + LOG4CPLUS_REG_APPENDER (reg, RollingFileAppender); + LOG4CPLUS_REG_APPENDER (reg, DailyRollingFileAppender); + LOG4CPLUS_REG_APPENDER (reg, SocketAppender); +#if defined(_WIN32) +# if defined(LOG4CPLUS_HAVE_NT_EVENT_LOG) + LOG4CPLUS_REG_APPENDER (reg, NTEventLogAppender); +# endif +# if defined(LOG4CPLUS_HAVE_WIN32_CONSOLE) + LOG4CPLUS_REG_APPENDER (reg, Win32ConsoleAppender); +# endif + LOG4CPLUS_REG_APPENDER (reg, Win32DebugAppender); +#endif + LOG4CPLUS_REG_APPENDER (reg, SysLogAppender); +#ifndef LOG4CPLUS_SINGLE_THREADED + LOG4CPLUS_REG_APPENDER (reg, AsyncAppender); +#endif + LOG4CPLUS_REG_APPENDER (reg, Log4jUdpAppender); + + spi::LayoutFactoryRegistry& reg2 = spi::getLayoutFactoryRegistry(); + LOG4CPLUS_REG_LAYOUT (reg2, SimpleLayout); + LOG4CPLUS_REG_LAYOUT (reg2, TTCCLayout); + LOG4CPLUS_REG_LAYOUT (reg2, PatternLayout); + + spi::FilterFactoryRegistry& reg3 = spi::getFilterFactoryRegistry(); + LOG4CPLUS_REG_FILTER (reg3, DenyAllFilter); + LOG4CPLUS_REG_FILTER (reg3, LogLevelMatchFilter); + LOG4CPLUS_REG_FILTER (reg3, LogLevelRangeFilter); + LOG4CPLUS_REG_FILTER (reg3, StringMatchFilter); + + spi::LocaleFactoryRegistry& reg4 = spi::getLocaleFactoryRegistry(); + LOG4CPLUS_REG_LOCALE (reg4, LOG4CPLUS_TEXT("GLOBAL"), spi::GlobalLocale); + LOG4CPLUS_REG_LOCALE (reg4, LOG4CPLUS_TEXT("DEFAULT"), spi::GlobalLocale); + LOG4CPLUS_REG_LOCALE (reg4, LOG4CPLUS_TEXT("USER"), spi::UserLocale); + LOG4CPLUS_REG_LOCALE (reg4, LOG4CPLUS_TEXT("CLASSIC"), spi::ClassicLocale); +} + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/fileappender.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/fileappender.cxx new file mode 100644 index 000000000..b681dd008 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/fileappender.cxx @@ -0,0 +1,892 @@ +// Module: Log4CPLUS +// File: fileappender.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// +// Copyright 2001-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/fileappender.h> +#include <log4cplus/layout.h> +#include <log4cplus/streams.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/helpers/timehelper.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/helpers/fileinfo.h> +#include <log4cplus/spi/loggingevent.h> +#include <log4cplus/spi/factory.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <log4cplus/internal/internal.h> +#include <algorithm> +#include <sstream> +#include <cstdio> +#include <stdexcept> + +#if defined (__BORLANDC__) +// For _wrename() and _wremove() on Windows. +# include <stdio.h> +#endif +#include <cerrno> +#ifdef LOG4CPLUS_HAVE_ERRNO_H +#include <errno.h> +#endif + +namespace log4cplus +{ + +using helpers::Properties; +using helpers::Time; + + +const long DEFAULT_ROLLING_LOG_SIZE = 10 * 1024 * 1024L; +const long MINIMUM_ROLLING_LOG_SIZE = 200*1024L; + + +/////////////////////////////////////////////////////////////////////////////// +// File LOCAL definitions +/////////////////////////////////////////////////////////////////////////////// + +namespace +{ + +long const LOG4CPLUS_FILE_NOT_FOUND = ENOENT; + + +static +long +file_rename (tstring const & src, tstring const & target) +{ +#if defined (UNICODE) && defined (_WIN32) + if (_wrename (src.c_str (), target.c_str ()) == 0) + return 0; + else + return errno; + +#else + if (std::rename (LOG4CPLUS_TSTRING_TO_STRING (src).c_str (), + LOG4CPLUS_TSTRING_TO_STRING (target).c_str ()) == 0) + return 0; + else + return errno; + +#endif +} + + +static +long +file_remove (tstring const & src) +{ +#if defined (UNICODE) && defined (_WIN32) + if (_wremove (src.c_str ()) == 0) + return 0; + else + return errno; + +#else + if (std::remove (LOG4CPLUS_TSTRING_TO_STRING (src).c_str ()) == 0) + return 0; + else + return errno; + +#endif +} + + +static +void +loglog_renaming_result (helpers::LogLog & loglog, tstring const & src, + tstring const & target, long ret) +{ + if (ret == 0) + { + loglog.debug ( + LOG4CPLUS_TEXT("Renamed file ") + + src + + LOG4CPLUS_TEXT(" to ") + + target); + } + else if (ret != LOG4CPLUS_FILE_NOT_FOUND) + { + tostringstream oss; + oss << LOG4CPLUS_TEXT("Failed to rename file from ") + << src + << LOG4CPLUS_TEXT(" to ") + << target + << LOG4CPLUS_TEXT("; error ") + << ret; + loglog.error (oss.str ()); + } +} + + +static +void +loglog_opening_result (helpers::LogLog & loglog, + log4cplus::tostream const & os, tstring const & filename) +{ + if (! os) + { + loglog.error ( + LOG4CPLUS_TEXT("Failed to open file ") + + filename); + } +} + + +static +void +rolloverFiles(const tstring& filename, unsigned int maxBackupIndex) +{ + helpers::LogLog * loglog = helpers::LogLog::getLogLog(); + + // Delete the oldest file + tostringstream buffer; + buffer << filename << LOG4CPLUS_TEXT(".") << maxBackupIndex; + long ret = file_remove (buffer.str ()); + + tostringstream source_oss; + tostringstream target_oss; + + // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2} + for (int i = maxBackupIndex - 1; i >= 1; --i) + { + source_oss.str(LOG4CPLUS_TEXT("")); + target_oss.str(LOG4CPLUS_TEXT("")); + + source_oss << filename << LOG4CPLUS_TEXT(".") << i; + target_oss << filename << LOG4CPLUS_TEXT(".") << (i+1); + + tstring const source (source_oss.str ()); + tstring const target (target_oss.str ()); + +#if defined (_WIN32) + // Try to remove the target first. It seems it is not + // possible to rename over existing file. + ret = file_remove (target); +#endif + + ret = file_rename (source, target); + loglog_renaming_result (*loglog, source, target, ret); + } +} // end rolloverFiles() + + +static +std::locale +get_locale_by_name (tstring const & locale_name) try +{ + spi::LocaleFactoryRegistry & reg = spi::getLocaleFactoryRegistry (); + spi::LocaleFactory * fact = reg.get (locale_name); + if (fact) + { + helpers::Properties props; + props.setProperty (LOG4CPLUS_TEXT ("Locale"), locale_name); + return fact->createObject (props); + } + else + return std::locale (LOG4CPLUS_TSTRING_TO_STRING (locale_name).c_str ()); +} +catch (std::runtime_error const &) +{ + helpers::getLogLog ().error ( + LOG4CPLUS_TEXT ("Failed to create locale " + locale_name)); + return std::locale (); +} + +} // namespace + + +/////////////////////////////////////////////////////////////////////////////// +// FileAppender ctors and dtor +/////////////////////////////////////////////////////////////////////////////// + +FileAppender::FileAppender(const tstring& filename_, + std::ios_base::openmode mode_, bool immediateFlush_) + : immediateFlush(immediateFlush_) + , reopenDelay(1) + , bufferSize (0) + , buffer (0) + , localeName (LOG4CPLUS_TEXT ("DEFAULT")) +{ + init(filename_, mode_, internal::empty_str); +} + + +FileAppender::FileAppender(const Properties& props, + std::ios_base::openmode mode_) + : Appender(props) + , immediateFlush(true) + , reopenDelay(1) + , bufferSize (0) + , buffer (0) +{ + bool app = (mode_ == std::ios::app); + tstring const & fn = props.getProperty( LOG4CPLUS_TEXT("File") ); + if (fn.empty()) + { + getErrorHandler()->error( LOG4CPLUS_TEXT("Invalid filename") ); + return; + } + + props.getBool (immediateFlush, LOG4CPLUS_TEXT("ImmediateFlush")); + props.getBool (app, LOG4CPLUS_TEXT("Append")); + props.getInt (reopenDelay, LOG4CPLUS_TEXT("ReopenDelay")); + props.getULong (bufferSize, LOG4CPLUS_TEXT("BufferSize")); + + tstring lockFileName = props.getProperty (LOG4CPLUS_TEXT ("LockFile")); + if (useLockFile && lockFileName.empty ()) + { + lockFileName = fn; + lockFileName += LOG4CPLUS_TEXT(".lock"); + } + + localeName = props.getProperty (LOG4CPLUS_TEXT ("Locale"), + LOG4CPLUS_TEXT ("DEFAULT")); + + init(fn, (app ? std::ios::app : std::ios::trunc), lockFileName); +} + + + +void +FileAppender::init(const tstring& filename_, + std::ios_base::openmode mode_, + const log4cplus::tstring& lockFileName_) +{ + filename = filename_; + + if (bufferSize != 0) + { + delete[] buffer; + buffer = new tchar[bufferSize]; + out.rdbuf ()->pubsetbuf (buffer, bufferSize); + } + + helpers::LockFileGuard guard; + if (useLockFile && ! lockFile.get ()) + { + try + { + lockFile.reset (new helpers::LockFile (lockFileName_)); + guard.attach_and_lock (*lockFile); + } + catch (std::runtime_error const &) + { + // We do not need to do any logging here as the internals + // of LockFile already use LogLog to report the failure. + return; + } + } + + open(mode_); + imbue (get_locale_by_name (localeName)); + + if(!out.good()) { + getErrorHandler()->error( LOG4CPLUS_TEXT("Unable to open file: ") + + filename); + return; + } + helpers::getLogLog().debug(LOG4CPLUS_TEXT("Just opened file: ") + filename); +} + + + +FileAppender::~FileAppender() +{ + destructorImpl(); +} + + + +/////////////////////////////////////////////////////////////////////////////// +// FileAppender public methods +/////////////////////////////////////////////////////////////////////////////// + +void +FileAppender::close() +{ + thread::MutexGuard guard (access_mutex); + + out.close(); + delete[] buffer; + buffer = 0; + closed = true; +} + + +std::locale +FileAppender::imbue(std::locale const& loc) +{ + return out.imbue (loc); +} + + +std::locale +FileAppender::getloc () const +{ + return out.getloc (); +} + + +/////////////////////////////////////////////////////////////////////////////// +// FileAppender protected methods +/////////////////////////////////////////////////////////////////////////////// + +// This method does not need to be locked since it is called by +// doAppend() which performs the locking +void +FileAppender::append(const spi::InternalLoggingEvent& event) +{ + if(!out.good()) { + if(!reopen()) { + getErrorHandler()->error( LOG4CPLUS_TEXT("file is not open: ") + + filename); + return; + } + // Resets the error handler to make it + // ready to handle a future append error. + else + getErrorHandler()->reset(); + } + + if (useLockFile) + out.seekp (0, std::ios_base::end); + + layout->formatAndAppend(out, event); + + if(immediateFlush || useLockFile) + out.flush(); +} + +void +FileAppender::open(std::ios::openmode mode) +{ + out.open(LOG4CPLUS_FSTREAM_PREFERED_FILE_NAME(filename).c_str(), mode); +} + +bool +FileAppender::reopen() +{ + // When append never failed and the file re-open attempt must + // be delayed, set the time when reopen should take place. + if (reopen_time == log4cplus::helpers::Time () && reopenDelay != 0) + reopen_time = log4cplus::helpers::Time::gettimeofday() + + log4cplus::helpers::Time(reopenDelay); + else + { + // Otherwise, check for end of the delay (or absence of delay) + // to re-open the file. + if (reopen_time <= log4cplus::helpers::Time::gettimeofday() + || reopenDelay == 0) + { + // Close the current file + out.close(); + out.clear(); // reset flags since the C++ standard specified that all the + // flags should remain unchanged on a close + + // Re-open the file. + open(std::ios_base::out | std::ios_base::ate); + + // Reset last fail time. + reopen_time = log4cplus::helpers::Time (); + + // Succeed if no errors are found. + if(out.good()) + return true; + } + } + return false; +} + +/////////////////////////////////////////////////////////////////////////////// +// RollingFileAppender ctors and dtor +/////////////////////////////////////////////////////////////////////////////// + +RollingFileAppender::RollingFileAppender(const tstring& filename_, + long maxFileSize_, int maxBackupIndex_, bool immediateFlush_) + : FileAppender(filename_, std::ios::app, immediateFlush_) +{ + init(maxFileSize_, maxBackupIndex_); +} + + +RollingFileAppender::RollingFileAppender(const Properties& properties) + : FileAppender(properties, std::ios::app) +{ + long tmpMaxFileSize = DEFAULT_ROLLING_LOG_SIZE; + int tmpMaxBackupIndex = 1; + tstring tmp ( + helpers::toUpper ( + properties.getProperty (LOG4CPLUS_TEXT ("MaxFileSize")))); + if (! tmp.empty ()) + { + tmpMaxFileSize = std::atoi(LOG4CPLUS_TSTRING_TO_STRING(tmp).c_str()); + if (tmpMaxFileSize != 0) + { + tstring::size_type const len = tmp.length(); + if (len > 2 + && tmp.compare (len - 2, 2, LOG4CPLUS_TEXT("MB")) == 0) + tmpMaxFileSize *= (1024 * 1024); // convert to megabytes + else if (len > 2 + && tmp.compare (len - 2, 2, LOG4CPLUS_TEXT("KB")) == 0) + tmpMaxFileSize *= 1024; // convert to kilobytes + } + tmpMaxFileSize = (std::max)(tmpMaxFileSize, MINIMUM_ROLLING_LOG_SIZE); + } + + properties.getInt (tmpMaxBackupIndex, LOG4CPLUS_TEXT("MaxBackupIndex")); + + init(tmpMaxFileSize, tmpMaxBackupIndex); +} + + +void +RollingFileAppender::init(long maxFileSize_, int maxBackupIndex_) +{ + if (maxFileSize_ < MINIMUM_ROLLING_LOG_SIZE) + { + tostringstream oss; + oss << LOG4CPLUS_TEXT ("RollingFileAppender: MaxFileSize property") + LOG4CPLUS_TEXT (" value is too small. Resetting to ") + << MINIMUM_ROLLING_LOG_SIZE << "."; + helpers::getLogLog ().warn (oss.str ()); + maxFileSize_ = MINIMUM_ROLLING_LOG_SIZE; + } + + maxFileSize = maxFileSize_; + maxBackupIndex = (std::max)(maxBackupIndex_, 1); +} + + +RollingFileAppender::~RollingFileAppender() +{ + destructorImpl(); +} + + +/////////////////////////////////////////////////////////////////////////////// +// RollingFileAppender protected methods +/////////////////////////////////////////////////////////////////////////////// + +// This method does not need to be locked since it is called by +// doAppend() which performs the locking +void +RollingFileAppender::append(const spi::InternalLoggingEvent& event) +{ + FileAppender::append(event); + + if(out.tellp() > maxFileSize) { + rollover(true); + } +} + + +void +RollingFileAppender::rollover(bool alreadyLocked) +{ + helpers::LogLog & loglog = helpers::getLogLog(); + helpers::LockFileGuard guard; + + // Close the current file + out.close(); + // Reset flags since the C++ standard specified that all the flags + // should remain unchanged on a close. + out.clear(); + + if (useLockFile) + { + if (! alreadyLocked) + { + try + { + guard.attach_and_lock (*lockFile); + } + catch (std::runtime_error const &) + { + return; + } + } + + // Recheck the condition as there is a window where another + // process can rollover the file before us. + + helpers::FileInfo fi; + if (getFileInfo (&fi, filename) == -1 + || fi.size < maxFileSize) + { + // The file has already been rolled by another + // process. Just reopen with the new file. + + // Open it up again. + open (std::ios::out | std::ios::ate); + loglog_opening_result (loglog, out, filename); + + return; + } + } + + // If maxBackups <= 0, then there is no file renaming to be done. + if (maxBackupIndex > 0) + { + rolloverFiles(filename, maxBackupIndex); + + // Rename fileName to fileName.1 + tstring target = filename + LOG4CPLUS_TEXT(".1"); + + long ret; + +#if defined (_WIN32) + // Try to remove the target first. It seems it is not + // possible to rename over existing file. + ret = file_remove (target); +#endif + + loglog.debug ( + LOG4CPLUS_TEXT("Renaming file ") + + filename + + LOG4CPLUS_TEXT(" to ") + + target); + ret = file_rename (filename, target); + loglog_renaming_result (loglog, filename, target, ret); + } + else + { + loglog.debug (filename + LOG4CPLUS_TEXT(" has no backups specified")); + } + + // Open it up again in truncation mode + open(std::ios::out | std::ios::trunc); + loglog_opening_result (loglog, out, filename); +} + + +/////////////////////////////////////////////////////////////////////////////// +// DailyRollingFileAppender ctors and dtor +/////////////////////////////////////////////////////////////////////////////// + +DailyRollingFileAppender::DailyRollingFileAppender( + const tstring& filename_, DailyRollingFileSchedule schedule_, + bool immediateFlush_, int maxBackupIndex_) + : FileAppender(filename_, std::ios::app, immediateFlush_) + , maxBackupIndex(maxBackupIndex_) +{ + init(schedule_); +} + + + +DailyRollingFileAppender::DailyRollingFileAppender( + const Properties& properties) + : FileAppender(properties, std::ios::app) + , maxBackupIndex(10) +{ + DailyRollingFileSchedule theSchedule = DAILY; + tstring scheduleStr (helpers::toUpper ( + properties.getProperty (LOG4CPLUS_TEXT ("Schedule")))); + + if(scheduleStr == LOG4CPLUS_TEXT("MONTHLY")) + theSchedule = MONTHLY; + else if(scheduleStr == LOG4CPLUS_TEXT("WEEKLY")) + theSchedule = WEEKLY; + else if(scheduleStr == LOG4CPLUS_TEXT("DAILY")) + theSchedule = DAILY; + else if(scheduleStr == LOG4CPLUS_TEXT("TWICE_DAILY")) + theSchedule = TWICE_DAILY; + else if(scheduleStr == LOG4CPLUS_TEXT("HOURLY")) + theSchedule = HOURLY; + else if(scheduleStr == LOG4CPLUS_TEXT("MINUTELY")) + theSchedule = MINUTELY; + else { + helpers::getLogLog().warn( + LOG4CPLUS_TEXT("DailyRollingFileAppender::ctor()") + LOG4CPLUS_TEXT("- \"Schedule\" not valid: ") + + properties.getProperty(LOG4CPLUS_TEXT("Schedule"))); + theSchedule = DAILY; + } + + properties.getInt (maxBackupIndex, LOG4CPLUS_TEXT("MaxBackupIndex")); + + init(theSchedule); +} + + + +void +DailyRollingFileAppender::init(DailyRollingFileSchedule sch) +{ + this->schedule = sch; + + Time now = Time::gettimeofday(); + now.usec(0); + struct tm time; + now.localtime(&time); + + time.tm_sec = 0; + switch (schedule) + { + case MONTHLY: + time.tm_mday = 1; + time.tm_hour = 0; + time.tm_min = 0; + break; + + case WEEKLY: + time.tm_mday -= (time.tm_wday % 7); + time.tm_hour = 0; + time.tm_min = 0; + break; + + case DAILY: + time.tm_hour = 0; + time.tm_min = 0; + break; + + case TWICE_DAILY: + if(time.tm_hour >= 12) { + time.tm_hour = 12; + } + else { + time.tm_hour = 0; + } + time.tm_min = 0; + break; + + case HOURLY: + time.tm_min = 0; + break; + + case MINUTELY: + break; + }; + now.setTime(&time); + + scheduledFilename = getFilename(now); + nextRolloverTime = calculateNextRolloverTime(now); +} + + + +DailyRollingFileAppender::~DailyRollingFileAppender() +{ + destructorImpl(); +} + + + + +/////////////////////////////////////////////////////////////////////////////// +// DailyRollingFileAppender public methods +/////////////////////////////////////////////////////////////////////////////// + +void +DailyRollingFileAppender::close() +{ + rollover(); + FileAppender::close(); +} + + + +/////////////////////////////////////////////////////////////////////////////// +// DailyRollingFileAppender protected methods +/////////////////////////////////////////////////////////////////////////////// + +// This method does not need to be locked since it is called by +// doAppend() which performs the locking +void +DailyRollingFileAppender::append(const spi::InternalLoggingEvent& event) +{ + if(event.getTimestamp() >= nextRolloverTime) { + rollover(true); + } + + FileAppender::append(event); +} + + + +void +DailyRollingFileAppender::rollover(bool alreadyLocked) +{ + helpers::LockFileGuard guard; + + if (useLockFile && ! alreadyLocked) + { + try + { + guard.attach_and_lock (*lockFile); + } + catch (std::runtime_error const &) + { + return; + } + } + + // Close the current file + out.close(); + out.clear(); // reset flags since the C++ standard specified that all the + // flags should remain unchanged on a close + + // If we've already rolled over this time period, we'll make sure that we + // don't overwrite any of those previous files. + // E.g. if "log.2009-11-07.1" already exists we rename it + // to "log.2009-11-07.2", etc. + rolloverFiles(scheduledFilename, maxBackupIndex); + + // Do not overwriet the newest file either, e.g. if "log.2009-11-07" + // already exists rename it to "log.2009-11-07.1" + tostringstream backup_target_oss; + backup_target_oss << scheduledFilename << LOG4CPLUS_TEXT(".") << 1; + tstring backupTarget = backup_target_oss.str(); + + helpers::LogLog & loglog = helpers::getLogLog(); + long ret; + +#if defined (_WIN32) + // Try to remove the target first. It seems it is not + // possible to rename over existing file, e.g. "log.2009-11-07.1". + ret = file_remove (backupTarget); +#endif + + // Rename e.g. "log.2009-11-07" to "log.2009-11-07.1". + ret = file_rename (scheduledFilename, backupTarget); + loglog_renaming_result (loglog, scheduledFilename, backupTarget, ret); + +#if defined (_WIN32) + // Try to remove the target first. It seems it is not + // possible to rename over existing file, e.g. "log.2009-11-07". + ret = file_remove (scheduledFilename); +#endif + + // Rename filename to scheduledFilename, + // e.g. rename "log" to "log.2009-11-07". + loglog.debug( + LOG4CPLUS_TEXT("Renaming file ") + + filename + + LOG4CPLUS_TEXT(" to ") + + scheduledFilename); + ret = file_rename (filename, scheduledFilename); + loglog_renaming_result (loglog, filename, scheduledFilename, ret); + + // Open a new file, e.g. "log". + open(std::ios::out | std::ios::trunc); + loglog_opening_result (loglog, out, filename); + + // Calculate the next rollover time + log4cplus::helpers::Time now = Time::gettimeofday(); + if (now >= nextRolloverTime) + { + scheduledFilename = getFilename(now); + nextRolloverTime = calculateNextRolloverTime(now); + } +} + + + +Time +DailyRollingFileAppender::calculateNextRolloverTime(const Time& t) const +{ + switch(schedule) + { + case MONTHLY: + { + struct tm nextMonthTime; + t.localtime(&nextMonthTime); + nextMonthTime.tm_mon += 1; + nextMonthTime.tm_isdst = 0; + + Time ret; + if(ret.setTime(&nextMonthTime) == -1) { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("DailyRollingFileAppender::calculateNextRolloverTime()-") + LOG4CPLUS_TEXT(" setTime() returned error")); + // Set next rollover to 31 days in future. + ret = (t + Time(2678400)); + } + + return ret; + } + + case WEEKLY: + return (t + Time(7 * 24 * 60 * 60)); + + default: + helpers::getLogLog ().error ( + LOG4CPLUS_TEXT ("DailyRollingFileAppender::calculateNextRolloverTime()-") + LOG4CPLUS_TEXT (" invalid schedule value")); + // Fall through. + + case DAILY: + return (t + Time(24 * 60 * 60)); + + case TWICE_DAILY: + return (t + Time(12 * 60 * 60)); + + case HOURLY: + return (t + Time(60 * 60)); + + case MINUTELY: + return (t + Time(60)); + }; +} + + + +tstring +DailyRollingFileAppender::getFilename(const Time& t) const +{ + tchar const * pattern = 0; + switch (schedule) + { + case MONTHLY: + pattern = LOG4CPLUS_TEXT("%Y-%m"); + break; + + case WEEKLY: + pattern = LOG4CPLUS_TEXT("%Y-%W"); + break; + + default: + helpers::getLogLog ().error ( + LOG4CPLUS_TEXT ("DailyRollingFileAppender::getFilename()-") + LOG4CPLUS_TEXT (" invalid schedule value")); + // Fall through. + + case DAILY: + pattern = LOG4CPLUS_TEXT("%Y-%m-%d"); + break; + + case TWICE_DAILY: + pattern = LOG4CPLUS_TEXT("%Y-%m-%d-%p"); + break; + + case HOURLY: + pattern = LOG4CPLUS_TEXT("%Y-%m-%d-%H"); + break; + + case MINUTELY: + pattern = LOG4CPLUS_TEXT("%Y-%m-%d-%H-%M"); + break; + }; + + tstring result (filename); + result += LOG4CPLUS_TEXT("."); + result += t.getFormattedTime(pattern, false); + return result; +} + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/fileinfo.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/fileinfo.cxx new file mode 100644 index 000000000..5b0405ba8 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/fileinfo.cxx @@ -0,0 +1,72 @@ +// -*- C++ -*- +// +// Copyright (C) 2012, Vaclav Zeman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <log4cplus/config.hxx> +#include <log4cplus/helpers/fileinfo.h> + +#ifdef LOG4CPLUS_HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#ifdef LOG4CPLUS_HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif + +#if defined (_WIN32) +#include <tchar.h> +#include <log4cplus/config/windowsh-inc.h> +#endif + + +namespace log4cplus { namespace helpers { + + +int +getFileInfo (FileInfo * fi, tstring const & name) +{ +#if defined (_WIN32) + struct _stat fileStatus; + if (_tstat (name.c_str (), &fileStatus) == -1) + return -1; + + fi->mtime = helpers::Time (fileStatus.st_mtime); + fi->is_link = false; + fi->size = fileStatus.st_size; + +#else + struct stat fileStatus; + if (stat (LOG4CPLUS_TSTRING_TO_STRING (name).c_str (), + &fileStatus) == -1) + return -1; + + fi->mtime = helpers::Time (fileStatus.st_mtime); + fi->is_link = S_ISLNK (fileStatus.st_mode); + fi->size = fileStatus.st_size; + +#endif + + return 0; +} + +} } // namespace log4cplus { namespace helpers { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/filter.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/filter.cxx new file mode 100644 index 000000000..a2c23878f --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/filter.cxx @@ -0,0 +1,258 @@ +// Module: Log4CPLUS +// File: filter.cxx +// Created: 5/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/spi/filter.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/spi/loggingevent.h> +#include <log4cplus/thread/syncprims-pub-impl.h> + + +namespace log4cplus { namespace spi { + +/////////////////////////////////////////////////////////////////////////////// +// global methods +/////////////////////////////////////////////////////////////////////////////// + +FilterResult +checkFilter(const Filter* filter, const InternalLoggingEvent& event) +{ + const Filter* currentFilter = filter; + while(currentFilter) { + FilterResult result = currentFilter->decide(event); + if(result != NEUTRAL) { + return result; + } + + currentFilter = currentFilter->next.get(); + } + + return ACCEPT; +} + + + +/////////////////////////////////////////////////////////////////////////////// +// Filter implementation +/////////////////////////////////////////////////////////////////////////////// + +Filter::Filter() +{ +} + + +Filter::~Filter() +{ +} + + +void +Filter::appendFilter(FilterPtr filter) +{ + if (! next) + next = filter; + else + next->appendFilter(filter); +} + + + +/////////////////////////////////////////////////////////////////////////////// +// DenyAllFilter implementation +/////////////////////////////////////////////////////////////////////////////// + +DenyAllFilter::DenyAllFilter () +{ } + + +DenyAllFilter::DenyAllFilter (const helpers::Properties&) +{ } + + +FilterResult +DenyAllFilter::decide(const InternalLoggingEvent&) const +{ + return DENY; +} + + + +/////////////////////////////////////////////////////////////////////////////// +// LogLevelMatchFilter implementation +/////////////////////////////////////////////////////////////////////////////// + +LogLevelMatchFilter::LogLevelMatchFilter() +{ + init(); +} + + + +LogLevelMatchFilter::LogLevelMatchFilter(const helpers::Properties& properties) +{ + init(); + + properties.getBool (acceptOnMatch = false, + LOG4CPLUS_TEXT("AcceptOnMatch")); + + tstring const & log_level_to_match + = properties.getProperty( LOG4CPLUS_TEXT("LogLevelToMatch") ); + logLevelToMatch = getLogLevelManager().fromString(log_level_to_match); +} + + +void +LogLevelMatchFilter::init() +{ + acceptOnMatch = true; + logLevelToMatch = NOT_SET_LOG_LEVEL; +} + + +FilterResult +LogLevelMatchFilter::decide(const InternalLoggingEvent& event) const +{ + if(logLevelToMatch == NOT_SET_LOG_LEVEL) { + return NEUTRAL; + } + + bool matchOccured = (logLevelToMatch == event.getLogLevel()); + + if(matchOccured) { + return (acceptOnMatch ? ACCEPT : DENY); + } + else { + return NEUTRAL; + } +} + + + +/////////////////////////////////////////////////////////////////////////////// +// LogLevelRangeFilter implementation +/////////////////////////////////////////////////////////////////////////////// + +LogLevelRangeFilter::LogLevelRangeFilter() +{ + init(); +} + + + +LogLevelRangeFilter::LogLevelRangeFilter(const helpers::Properties& properties) +{ + init(); + + properties.getBool (acceptOnMatch = false, + LOG4CPLUS_TEXT("AcceptOnMatch")); + + tstring const & log_level_min + = properties.getProperty( LOG4CPLUS_TEXT("LogLevelMin") ); + logLevelMin = getLogLevelManager().fromString(log_level_min); + + tstring const & log_level_max + = properties.getProperty( LOG4CPLUS_TEXT("LogLevelMax") ); + logLevelMax = getLogLevelManager().fromString(log_level_max); +} + + +void +LogLevelRangeFilter::init() +{ + acceptOnMatch = true; + logLevelMin = NOT_SET_LOG_LEVEL; + logLevelMax = NOT_SET_LOG_LEVEL; +} + + +FilterResult +LogLevelRangeFilter::decide(const InternalLoggingEvent& event) const +{ + if((logLevelMin != NOT_SET_LOG_LEVEL) && (event.getLogLevel() < logLevelMin)) { + // priority of event is less than minimum + return DENY; + } + + if((logLevelMax != NOT_SET_LOG_LEVEL) && (event.getLogLevel() > logLevelMax)) { + // priority of event is greater than maximum + return DENY; + } + + if(acceptOnMatch) { + // this filter set up to bypass later filters and always return + // accept if priority in range + return ACCEPT; + } + else { + // event is ok for this filter; allow later filters to have a look... + return NEUTRAL; + } +} + + + +/////////////////////////////////////////////////////////////////////////////// +// StringMatchFilter implementation +/////////////////////////////////////////////////////////////////////////////// + +StringMatchFilter::StringMatchFilter() +{ + init(); +} + + + +StringMatchFilter::StringMatchFilter(const helpers::Properties& properties) +{ + init(); + + properties.getBool (acceptOnMatch = false, + LOG4CPLUS_TEXT("AcceptOnMatch")); + stringToMatch = properties.getProperty( LOG4CPLUS_TEXT("StringToMatch") ); +} + + +void +StringMatchFilter::init() +{ + acceptOnMatch = true; +} + + +FilterResult +StringMatchFilter::decide(const InternalLoggingEvent& event) const +{ + const tstring& message = event.getMessage(); + + if(stringToMatch.empty () || message.empty ()) { + return NEUTRAL; + } + + if(message.find(stringToMatch) == tstring::npos) { + return NEUTRAL; + } + else { // we've got a match + return (acceptOnMatch ? ACCEPT : DENY); + } +} + + +} } // namespace log4cplus { namespace spi { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/global-init.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/global-init.cxx new file mode 100644 index 000000000..10726b6a6 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/global-init.cxx @@ -0,0 +1,466 @@ +// Module: Log4CPLUS +// File: global-init.cxx +// Created: 5/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/config.hxx> +#include <log4cplus/config/windowsh-inc.h> +#include <log4cplus/logger.h> +#include <log4cplus/ndc.h> +#include <log4cplus/mdc.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/internal/internal.h> +#include <log4cplus/thread/impl/tls.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/spi/factory.h> +#include <log4cplus/hierarchy.h> +#include <cstdio> +#include <iostream> +#include <stdexcept> + + +// Forward Declarations +namespace log4cplus +{ + +#ifdef UNICODE +LOG4CPLUS_EXPORT tostream & tcout = std::wcout; +LOG4CPLUS_EXPORT tostream & tcerr = std::wcerr; + +#else +LOG4CPLUS_EXPORT tostream & tcout = std::cout; +LOG4CPLUS_EXPORT tostream & tcerr = std::cerr; + +#endif // UNICODE + + +namespace +{ + + +//! Default context. +struct DefaultContext +{ + log4cplus::thread::Mutex console_mutex; + helpers::LogLog loglog; + LogLevelManager log_level_manager; + helpers::Time TTCCLayout_time_base; + NDC ndc; + MDC mdc; + Hierarchy hierarchy; + spi::AppenderFactoryRegistry appender_factory_registry; + spi::LayoutFactoryRegistry layout_factory_registry; + spi::FilterFactoryRegistry filter_factory_registry; + spi::LocaleFactoryRegistry locale_factory_registry; +}; + + +enum DCState +{ + DC_UNINITIALIZED, + DC_INITIALIZED, + DC_DESTROYED +}; + + +static DCState default_context_state; +static DefaultContext * default_context; + + +struct destroy_default_context +{ + ~destroy_default_context () + { + delete default_context; + default_context = 0; + default_context_state = DC_DESTROYED; + } +} static destroy_default_context_; + + +static +void +alloc_dc () +{ + assert (! default_context); + assert (default_context_state == DC_UNINITIALIZED); + + if (default_context) + throw std::logic_error ( + "alloc_dc() called with non-NULL default_context."); + + if (default_context_state == DC_INITIALIZED) + throw std::logic_error ("alloc_dc() called in DC_INITIALIZED state."); + + default_context = new DefaultContext; + + if (default_context_state == DC_DESTROYED) + default_context->loglog.error ( + LOG4CPLUS_TEXT ("Re-initializing default context after it has") + LOG4CPLUS_TEXT (" already been destroyed.\n") + LOG4CPLUS_TEXT ("The memory will be leaked.")); + + default_context_state = DC_INITIALIZED; +} + + +static +DefaultContext * +get_dc (bool alloc = true) +{ + if (LOG4CPLUS_UNLIKELY (! default_context && alloc)) + alloc_dc (); + return default_context; +} + + +} // namespace + + +namespace helpers +{ + + +log4cplus::thread::Mutex const & +getConsoleOutputMutex () +{ + return get_dc ()->console_mutex; +} + + +LogLog & +getLogLog () +{ + return get_dc ()->loglog; +} + + +} // namespace helpers + + +helpers::Time const & +getTTCCLayoutTimeBase () +{ + return get_dc ()->TTCCLayout_time_base; +} + + +LogLevelManager & +getLogLevelManager () +{ + return get_dc ()->log_level_manager; +} + + +Hierarchy & +getDefaultHierarchy () +{ + return get_dc ()->hierarchy; +} + + +NDC & +getNDC () +{ + return get_dc ()->ndc; +} + + +MDC & +getMDC () +{ + return get_dc ()->mdc; +} + + +namespace spi +{ + + +AppenderFactoryRegistry & +getAppenderFactoryRegistry () +{ + return get_dc ()->appender_factory_registry; +} + + +LayoutFactoryRegistry & +getLayoutFactoryRegistry () +{ + return get_dc ()->layout_factory_registry; +} + + +FilterFactoryRegistry & +getFilterFactoryRegistry () +{ + return get_dc ()->filter_factory_registry; +} + + +LocaleFactoryRegistry & +getLocaleFactoryRegistry() +{ + return get_dc ()->locale_factory_registry; +} + + +} // namespace spi + + +namespace internal +{ + + +gft_scratch_pad::gft_scratch_pad () + : uc_q_str_valid (false) + , q_str_valid (false) + , s_str_valid (false) +{ } + + +gft_scratch_pad::~gft_scratch_pad () +{ } + + +appender_sratch_pad::appender_sratch_pad () +{ } + + +appender_sratch_pad::~appender_sratch_pad () +{ } + + +per_thread_data::per_thread_data () + : fnull (0) +{ } + + +per_thread_data::~per_thread_data () +{ + if (fnull) + std::fclose (fnull); +} + + +log4cplus::thread::impl::tls_key_type tls_storage_key; + + +#if ! defined (LOG4CPLUS_SINGLE_THREADED) \ + && defined (LOG4CPLUS_THREAD_LOCAL_VAR) + +LOG4CPLUS_THREAD_LOCAL_VAR per_thread_data * ptd = 0; + + +per_thread_data * +alloc_ptd () +{ + per_thread_data * tmp = new per_thread_data; + set_ptd (tmp); + // This is a special hack. We set the keys' value to non-NULL to + // get the ptd_cleanup_func to execute when this thread ends. The + // cast is safe; the associated value will never be used if read + // again using the key. + thread::impl::tls_set_value (tls_storage_key, + reinterpret_cast<void *>(1)); + + return tmp; +} + +# else + +per_thread_data * +alloc_ptd () +{ + per_thread_data * tmp = new per_thread_data; + set_ptd (tmp); + return tmp; +} + +# endif + + +} // namespace internal + + +void initializeFactoryRegistry(); + + +//! Thread local storage clean up function for POSIX threads. +static +void +ptd_cleanup_func (void * arg) +{ + internal::per_thread_data * const arg_ptd + = static_cast<internal::per_thread_data *>(arg); + internal::per_thread_data * const ptd = internal::get_ptd (false); + (void) ptd; + + // Either it is a dummy value or it should be the per thread data + // pointer we get from internal::get_ptd(). + assert (arg == reinterpret_cast<void *>(1) + || arg_ptd == ptd + || (! ptd && arg_ptd)); + + if (arg == reinterpret_cast<void *>(1)) + // Setting the value through the key here is necessary in case + // we are using TLS using __thread or __declspec(thread) or + // similar constructs with POSIX threads. Otherwise POSIX + // calls this cleanup routine more than once if the value + // stays non-NULL after it returns. + thread::impl::tls_set_value (internal::tls_storage_key, 0); + else if (arg) + { + // Instead of using internal::get_ptd(false) here we are using + // the value passed to this function directly. This is + // necessary because of the following (from SUSv4): + // + // A call to pthread_getspecific() for the thread-specific + // data key being destroyed shall return the value NULL, + // unless the value is changed (after the destructor starts) + // by a call to pthread_setspecific(). + delete arg_ptd; + thread::impl::tls_set_value (internal::tls_storage_key, 0); + } + else + { + // In this case we fall through to threadCleanup() and it does + // all the necessary work itself. + ; + } + + threadCleanup (); +} + + +static +void +threadSetup () +{ + internal::get_ptd (true); +} + + +void initializeLog4cplus() +{ + static bool initialized = false; + if (initialized) + return; + + internal::tls_storage_key = thread::impl::tls_init (ptd_cleanup_func); + threadSetup (); + + DefaultContext * dc = get_dc (true); + dc->TTCCLayout_time_base = helpers::Time::gettimeofday (); + Logger::getRoot(); + initializeFactoryRegistry(); + + initialized = true; +} + + +void +threadCleanup () +{ + // Do thread-specific cleanup. + internal::per_thread_data * ptd = internal::get_ptd (false); + delete ptd; + internal::set_ptd (0); +} + + +} // namespace log4cplus + + +#if defined (_WIN32) && defined (LOG4CPLUS_BUILD_DLL) + +extern "C" +BOOL +WINAPI +DllMain (LOG4CPLUS_DLLMAIN_HINSTANCE /*hinstDLL*/, DWORD fdwReason, + LPVOID /*lpReserved*/) +{ + // Perform actions based on the reason for calling. + switch( fdwReason ) + { + case DLL_PROCESS_ATTACH: + { + log4cplus::initializeLog4cplus(); + + // Do thread-specific initialization for the main thread. + log4cplus::threadSetup (); + + break; + } + + case DLL_THREAD_ATTACH: + { + // Do thread-specific initialization. + log4cplus::threadSetup (); + + break; + } + + case DLL_THREAD_DETACH: + { + // Do thread-specific cleanup. + log4cplus::threadCleanup (); + + break; + } + + case DLL_PROCESS_DETACH: + { + // Perform any necessary cleanup. + + // Do thread-specific cleanup. + log4cplus::threadCleanup (); +#if ! defined (LOG4CPLUS_THREAD_LOCAL_VAR) + log4cplus::thread::impl::tls_cleanup ( + log4cplus::internal::tls_storage_key); +#endif + break; + } + + } + + return TRUE; // Successful DLL_PROCESS_ATTACH. +} + +#else + +namespace { + + struct _static_log4cplus_initializer + { + _static_log4cplus_initializer () + { + log4cplus::initializeLog4cplus(); + } + + ~_static_log4cplus_initializer () + { + // Last thread cleanup. + log4cplus::threadCleanup (); + } + } static initializer; +} + + +#endif diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/hierarchy.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/hierarchy.cxx new file mode 100644 index 000000000..07020ef73 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/hierarchy.cxx @@ -0,0 +1,373 @@ +// Module: Log4CPLUS +// File: hierarchy.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// +// Copyright 2001-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/hierarchy.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/spi/loggerimpl.h> +#include <log4cplus/spi/rootlogger.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <utility> + + +namespace log4cplus +{ + + +////////////////////////////////////////////////////////////////////////////// +// File "Local" methods +////////////////////////////////////////////////////////////////////////////// + +namespace +{ + +static +bool startsWith(tstring const & teststr, tstring const & substr) +{ + bool val = false; + tstring::size_type const len = substr.length(); + if (teststr.length() > len) + val = teststr.compare (0, len, substr) == 0; + + return val; +} + +} + + +////////////////////////////////////////////////////////////////////////////// +// Hierarchy static declarations +////////////////////////////////////////////////////////////////////////////// + +const LogLevel Hierarchy::DISABLE_OFF = -1; +const LogLevel Hierarchy::DISABLE_OVERRIDE = -2; + + + +////////////////////////////////////////////////////////////////////////////// +// Hierarchy ctor and dtor +////////////////////////////////////////////////////////////////////////////// + +Hierarchy::Hierarchy() + : defaultFactory(new DefaultLoggerFactory()) + , root(NULL) + // Don't disable any LogLevel level by default. + , disableValue(DISABLE_OFF) + , emittedNoAppenderWarning(false) +{ + root = Logger( new spi::RootLogger(*this, DEBUG_LOG_LEVEL) ); +} + + +Hierarchy::~Hierarchy() +{ + shutdown(); +} + + + +////////////////////////////////////////////////////////////////////////////// +// Hierarchy public methods +////////////////////////////////////////////////////////////////////////////// + +void +Hierarchy::clear() +{ + thread::MutexGuard guard (hashtable_mutex); + + provisionNodes.erase(provisionNodes.begin(), provisionNodes.end()); + loggerPtrs.erase(loggerPtrs.begin(), loggerPtrs.end()); +} + + +bool +Hierarchy::exists(const tstring& name) +{ + thread::MutexGuard guard (hashtable_mutex); + + LoggerMap::iterator it = loggerPtrs.find(name); + return it != loggerPtrs.end(); +} + + +void +Hierarchy::disable(const tstring& loglevelStr) +{ + if(disableValue != DISABLE_OVERRIDE) { + disableValue = getLogLevelManager().fromString(loglevelStr); + } +} + + +void +Hierarchy::disable(LogLevel ll) +{ + if(disableValue != DISABLE_OVERRIDE) { + disableValue = ll; + } +} + + +void +Hierarchy::disableAll() +{ + disable(FATAL_LOG_LEVEL); +} + + +void +Hierarchy::disableDebug() +{ + disable(DEBUG_LOG_LEVEL); +} + + +void +Hierarchy::disableInfo() +{ + disable(INFO_LOG_LEVEL); +} + + +void +Hierarchy::enableAll() +{ + disableValue = DISABLE_OFF; +} + + +Logger +Hierarchy::getInstance(const tstring& name) +{ + return getInstance(name, *defaultFactory); +} + + +Logger +Hierarchy::getInstance(const tstring& name, spi::LoggerFactory& factory) +{ + thread::MutexGuard guard (hashtable_mutex); + + return getInstanceImpl(name, factory); +} + + +LoggerList +Hierarchy::getCurrentLoggers() +{ + LoggerList ret; + + { + thread::MutexGuard guard (hashtable_mutex); + initializeLoggerList(ret); + } + + return ret; +} + + +bool +Hierarchy::isDisabled(LogLevel level) +{ + return disableValue >= level; +} + + +Logger +Hierarchy::getRoot() const +{ + return root; +} + + +void +Hierarchy::resetConfiguration() +{ + getRoot().setLogLevel(DEBUG_LOG_LEVEL); + disableValue = DISABLE_OFF; + + shutdown(); + + LoggerList loggers = getCurrentLoggers(); + for (LoggerList::iterator it = loggers.begin (); it != loggers.end(); ++it) + { + Logger & logger = *it; + logger.setLogLevel(NOT_SET_LOG_LEVEL); + logger.setAdditivity(true); + } + +} + + +void +Hierarchy::setLoggerFactory(std::auto_ptr<spi::LoggerFactory> factory) +{ + defaultFactory = factory; +} + + +spi::LoggerFactory * +Hierarchy::getLoggerFactory() +{ + return defaultFactory.get(); +} + + +void +Hierarchy::shutdown() +{ + LoggerList loggers = getCurrentLoggers(); + + // begin by closing nested appenders + // then, remove all appenders + root.closeNestedAppenders(); + root.removeAllAppenders(); + + // repeat + for (LoggerList::iterator it = loggers.begin(); it != loggers.end(); ++it) + { + Logger & logger = *it; + logger.closeNestedAppenders(); + logger.removeAllAppenders(); + } +} + + + +////////////////////////////////////////////////////////////////////////////// +// Hierarchy private methods +////////////////////////////////////////////////////////////////////////////// + +Logger +Hierarchy::getInstanceImpl(const tstring& name, spi::LoggerFactory& factory) +{ + Logger logger; + LoggerMap::iterator lm_it; + + if (name.empty ()) + logger = root; + else if ((lm_it = loggerPtrs.find(name)) != loggerPtrs.end()) + logger = lm_it->second; + else + { + // Need to create a new logger + logger = factory.makeNewLoggerInstance(name, *this); + bool inserted = loggerPtrs.insert(std::make_pair(name, logger)).second; + if (! inserted) + { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("Hierarchy::getInstanceImpl()- Insert failed"), + true); + } + + ProvisionNodeMap::iterator pnm_it = provisionNodes.find(name); + if (pnm_it != provisionNodes.end()) + { + updateChildren(pnm_it->second, logger); + bool deleted = (provisionNodes.erase(name) > 0); + if (! deleted) + { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("Hierarchy::getInstanceImpl()- Delete failed"), + true); + } + } + updateParents(logger); + } + + return logger; +} + + +void +Hierarchy::initializeLoggerList(LoggerList& list) const +{ + for(LoggerMap::const_iterator it=loggerPtrs.begin(); + it!= loggerPtrs.end(); + ++it) + { + list.push_back((*it).second); + } +} + + +void +Hierarchy::updateParents(Logger const & logger) +{ + tstring const & name = logger.getName(); + std::size_t const length = name.length(); + bool parentFound = false; + tstring substr; + + // if name = "w.x.y.z", loop thourgh "w.x.y", "w.x" and "w", but not "w.x.y.z" + for(std::size_t i=name.find_last_of(LOG4CPLUS_TEXT('.'), length-1); + i != tstring::npos && i > 0; + i = name.find_last_of(LOG4CPLUS_TEXT('.'), i-1)) + { + substr.assign (name, 0, i); + + LoggerMap::iterator it = loggerPtrs.find(substr); + if(it != loggerPtrs.end()) { + parentFound = true; + logger.value->parent = it->second.value; + break; // no need to update the ancestors of the closest ancestor + } + else { + ProvisionNodeMap::iterator it2 = provisionNodes.find(substr); + if(it2 != provisionNodes.end()) { + it2->second.push_back(logger); + } + else { + ProvisionNode node; + node.push_back(logger); + std::pair<ProvisionNodeMap::iterator, bool> tmp = + provisionNodes.insert(std::make_pair(substr, node)); + //bool inserted = provisionNodes.insert(std::make_pair(substr, node)).second; + if(!tmp.second) { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("Hierarchy::updateParents()- Insert failed"), + true); + } + } + } // end if Logger found + } // end for loop + + if(!parentFound) { + logger.value->parent = root.value; + } +} + + +void +Hierarchy::updateChildren(ProvisionNode& pn, Logger const & logger) +{ + + for(ProvisionNode::iterator it=pn.begin(); it!=pn.end(); ++it) { + Logger& c = *it; + // Unless this child already points to a correct (lower) parent, + // make logger.parent point to c.parent and c.parent to logger. + if( !startsWith(c.value->parent->getName(), logger.getName()) ) { + logger.value->parent = c.value->parent; + c.value->parent = logger.value; + } + } +} + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/hierarchylocker.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/hierarchylocker.cxx new file mode 100644 index 000000000..df31794ce --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/hierarchylocker.cxx @@ -0,0 +1,134 @@ +// Module: Log4CPLUS +// File: hierarchylocker.cxx +// Created: 8/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/hierarchylocker.h> +#include <log4cplus/hierarchy.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/spi/loggerimpl.h> +#include <log4cplus/thread/syncprims-pub-impl.h> + + +namespace log4cplus +{ + + +////////////////////////////////////////////////////////////////////////////// +// HierarchyLocker ctor and dtor +////////////////////////////////////////////////////////////////////////////// + +HierarchyLocker::HierarchyLocker(Hierarchy& _h) +: h(_h), + hierarchyLocker(h.hashtable_mutex), + loggerList() +{ + // Get a copy of all of the Hierarchy's Loggers (except the Root Logger) + h.initializeLoggerList(loggerList); + + // Lock all of the Hierarchy's Loggers' mutexs + LoggerList::iterator it; + try + { + for (it = loggerList.begin(); it != loggerList.end(); ++it) + it->value->appender_list_mutex.lock (); + } + catch (...) + { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("HierarchyLocker::ctor()") + LOG4CPLUS_TEXT("- An error occurred while locking")); + LoggerList::iterator range_end = it; + for (it = loggerList.begin (); it != range_end; ++it) + it->value->appender_list_mutex.unlock (); + throw; + } +} + + +HierarchyLocker::~HierarchyLocker() +{ + try { + for(LoggerList::iterator it=loggerList.begin(); it!=loggerList.end(); ++it) { + it->value->appender_list_mutex.unlock (); + } + } + catch(...) { + helpers::getLogLog().error(LOG4CPLUS_TEXT("HierarchyLocker::dtor()- An error occurred while unlocking")); + throw; + } +} + +void +HierarchyLocker::resetConfiguration() +{ + Logger root = h.getRoot(); + h.disable(Hierarchy::DISABLE_OFF); + + // begin by closing nested appenders + // then, remove all appenders + root.setLogLevel(DEBUG_LOG_LEVEL); + root.closeNestedAppenders(); + root.removeAllAppenders(); + + // repeat + for(LoggerList::iterator it=loggerList.begin(); it!=loggerList.end(); ++it) + { + Logger & logger = *it; + + logger.closeNestedAppenders(); + logger.removeAllAppenders(); + + logger.setLogLevel(NOT_SET_LOG_LEVEL); + logger.setAdditivity(true); + } +} + + +Logger +HierarchyLocker::getInstance(const tstring& name) +{ + return h.getInstanceImpl(name, *h.getLoggerFactory()); +} + + +Logger +HierarchyLocker::getInstance(const tstring& name, spi::LoggerFactory& factory) +{ + return h.getInstanceImpl(name, factory); +} + + +void +HierarchyLocker::addAppender(Logger& logger, SharedAppenderPtr& appender) +{ + for(LoggerList::iterator it=loggerList.begin(); it!=loggerList.end(); ++it) { + if((*it).value == logger.value) { + logger.value->appender_list_mutex.unlock (); + logger.addAppender(appender); + logger.value->appender_list_mutex.lock (); + return; + } + } + + // I don't have this Logger locked + logger.addAppender(appender); +} + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/layout.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/layout.cxx new file mode 100644 index 000000000..61331e1b2 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/layout.cxx @@ -0,0 +1,152 @@ +// Module: Log4CPLUS +// File: layout.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// +// Copyright 2001-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/layout.h> +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/helpers/timehelper.h> +#include <log4cplus/spi/loggingevent.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/internal/internal.h> +#include <ostream> +#include <iomanip> + + +namespace log4cplus +{ + +void +formatRelativeTimestamp (log4cplus::tostream & output, + log4cplus::spi::InternalLoggingEvent const & event) +{ + helpers::Time const rel_time + = event.getTimestamp () - getTTCCLayoutTimeBase (); + tchar const old_fill = output.fill (); + helpers::time_t const sec = rel_time.sec (); + + if (sec != 0) + output << sec << std::setfill (LOG4CPLUS_TEXT ('0')) << std::setw (3); + + output << rel_time.usec () / 1000; + output.fill (old_fill); +} + +// +// +// + + +Layout::Layout () + : llmCache(getLogLevelManager()) +{ } + + +Layout::Layout (const log4cplus::helpers::Properties&) + : llmCache(getLogLevelManager()) +{ } + + +Layout::~Layout() +{ } + + +/////////////////////////////////////////////////////////////////////////////// +// log4cplus::SimpleLayout public methods +/////////////////////////////////////////////////////////////////////////////// + +SimpleLayout::SimpleLayout () +{ } + + +SimpleLayout::SimpleLayout (const helpers::Properties& properties) + : Layout (properties) +{ } + + +SimpleLayout::~SimpleLayout() +{ } + + +void +SimpleLayout::formatAndAppend(log4cplus::tostream& output, + const log4cplus::spi::InternalLoggingEvent& event) +{ + output << llmCache.toString(event.getLogLevel()) + << LOG4CPLUS_TEXT(" - ") + << event.getMessage() + << LOG4CPLUS_TEXT("\n"); +} + + + +/////////////////////////////////////////////////////////////////////////////// +// log4cplus::TTCCLayout ctors and dtor +/////////////////////////////////////////////////////////////////////////////// + +TTCCLayout::TTCCLayout(bool use_gmtime_) + : dateFormat() + , use_gmtime(use_gmtime_) +{ +} + + +TTCCLayout::TTCCLayout(const log4cplus::helpers::Properties& properties) + : Layout(properties) + , dateFormat(properties.getProperty (LOG4CPLUS_TEXT("DateFormat"), + internal::empty_str)) + , use_gmtime(false) +{ + properties.getBool (use_gmtime, LOG4CPLUS_TEXT("Use_gmtime")); +} + + +TTCCLayout::~TTCCLayout() +{ } + + + +/////////////////////////////////////////////////////////////////////////////// +// log4cplus::TTCCLayout public methods +/////////////////////////////////////////////////////////////////////////////// + +void +TTCCLayout::formatAndAppend(log4cplus::tostream& output, + const log4cplus::spi::InternalLoggingEvent& event) +{ + if (dateFormat.empty ()) + formatRelativeTimestamp (output, event); + else + output << event.getTimestamp().getFormattedTime(dateFormat, + use_gmtime); + + output << LOG4CPLUS_TEXT(" [") + << event.getThread() + << LOG4CPLUS_TEXT("] ") + << llmCache.toString(event.getLogLevel()) + << LOG4CPLUS_TEXT(" ") + << event.getLoggerName() + << LOG4CPLUS_TEXT(" <") + << event.getNDC() + << LOG4CPLUS_TEXT("> - ") + << event.getMessage() + << LOG4CPLUS_TEXT("\n"); +} + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/lockfile.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/lockfile.cxx new file mode 100644 index 000000000..5d597868e --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/lockfile.cxx @@ -0,0 +1,336 @@ +// -*- C++ -*- +// +// Copyright (C) 2012, Vaclav Zeman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <log4cplus/config.hxx> + +#if defined (LOG4CPLUS_HAVE_SYS_TYPES_H) +#include <sys/types.h> +#endif +#if defined (LOG4CPLUS_HAVE_SYS_STAT_H) +#include <sys/stat.h> +#endif +#if defined (LOG4CPLUS_HAVE_SYS_FILE_H) +#include <sys/file.h> +#endif +#if defined (LOG4CPLUS_HAVE_SYS_LOCKING_H) +#include <sys/locking.h> +#endif +#if defined (LOG4CPLUS_HAVE_UNISTD_H) +#include <unistd.h> +#endif +#if defined (LOG4CPLUS_HAVE_FCNTL_H) +#include <fcntl.h> +#endif +#if defined (LOG4CPLUS_HAVE_IO_H) +#include <io.h> +#endif +#if defined (_WIN32) +#include <tchar.h> +#include <share.h> +#endif +#include <log4cplus/config/windowsh-inc.h> + +#include <stdexcept> +#include <cerrno> +#include <limits> +#include <cstring> + +#include <log4cplus/helpers/lockfile.h> +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/helpers/loglog.h> + +#if defined (_WIN32) +# if _WIN32_WINNT < 0x0501 +# define LOG4CPLUS_USE_WIN32_LOCKING +# else +# define LOG4CPLUS_USE_WIN32_LOCKFILEEX +# endif +#else +# if defined (O_EXLOCK) +# define LOG4CPLUS_USE_O_EXLOCK +# elif defined (LOG4CPLUS_HAVE_FCNTL) && defined (F_SETLKW) +# define LOG4CPLUS_USE_SETLKW +# elif defined (LOG4CPLUS_HAVE_LOCKF) +# define LOG4CPLUS_USE_LOCKF +# elif defined (LOG4CPLUS_HAVE_FLOCK) +# define LOG4CPLUS_USE_FLOCK +# endif +# if defined (LOG4CPLUS_USE_O_EXLOCK) || defined (LOG4CPLUS_USE_SETLKW) \ + || defined (LOG4CPLUS_USE_LOCKF) || defined (LOG4CPLUS_USE_FLOCK) +# define LOG4CPLUS_USE_POSIX_LOCKING +# endif +#endif + +#if ! defined (LOG4CPLUS_USE_POSIX_LOCKING) && ! defined (_WIN32) +#error "no usable file locking" +#endif + +namespace log4cplus { namespace helpers { + + +#if defined (_WIN32) +int const OPEN_FLAGS = _O_RDWR | _O_CREAT /*| _O_TEMPORARY*/ | _O_NOINHERIT; +int const OPEN_SHFLAGS = _SH_DENYNO; +int const OPEN_MODE = _S_IREAD | _S_IWRITE; + +namespace +{ + +static +HANDLE +get_os_HANDLE (int fd, helpers::LogLog & loglog) +{ + HANDLE fh = reinterpret_cast<HANDLE>(_get_osfhandle (fd)); + if (fh == INVALID_HANDLE_VALUE) + loglog.error (tstring (LOG4CPLUS_TEXT ("_get_osfhandle() failed: ")) + + convertIntegerToString (errno), true); + + return fh; +} + +} // namespace + +#elif defined (LOG4CPLUS_USE_POSIX_LOCKING) +int const OPEN_FLAGS = O_RDWR | O_CREAT +#if defined (O_CLOEXEC) + | O_CLOEXEC +#endif + ; + +mode_t const OPEN_MODE = (S_IRWXU ^ S_IXUSR) + | (S_IRWXG ^ S_IXGRP) + | (S_IRWXO ^ S_IXOTH); + +#endif + +struct LockFile::Impl +{ +#if defined (LOG4CPLUS_USE_POSIX_LOCKING) \ + || defined (_WIN32) + int fd; + +#endif +}; + + +// +// +// + +LockFile::LockFile (tstring const & lf) + : lock_file_name (lf) + , data (new LockFile::Impl) +{ +#if defined (LOG4CPLUS_USE_O_EXLOCK) + data->fd = -1; + +#else + open (OPEN_FLAGS); + +#endif +} + + +LockFile::~LockFile () +{ + close (); + delete data; +} + + +void +LockFile::open (int open_flags) const +{ + LogLog & loglog = getLogLog (); + +#if defined (_WIN32) + errno_t eno = _tsopen_s (&data->fd, lock_file_name.c_str (), open_flags, + OPEN_SHFLAGS, OPEN_MODE); + if (eno != 0) + loglog.error (tstring (LOG4CPLUS_TEXT("could not open or create file ")) + + lock_file_name, true); + +#elif defined (LOG4CPLUS_USE_POSIX_LOCKING) + data->fd = ::open (LOG4CPLUS_TSTRING_TO_STRING (lock_file_name).c_str (), + open_flags, OPEN_MODE); + if (data->fd == -1) + loglog.error ( + tstring (LOG4CPLUS_TEXT ("could not open or create file ")) + + lock_file_name, true); + +#if ! defined (O_CLOEXEC) && defined (FD_CLOEXEC) + int ret = fcntl (data->fd, F_SETFD, FD_CLOEXEC); + if (ret == -1) + loglog.warn ( + tstring (LOG4CPLUS_TEXT("could not set FD_CLOEXEC on file ")) + + lock_file_name); + +#endif +#endif +} + + +void +LockFile::close () const +{ +#if defined (_WIN32) + if (data->fd >= 0) + _close (data->fd); + + data->fd = -1; + +#elif defined (LOG4CPLUS_USE_POSIX_LOCKING) + if (data->fd >= 0) + ::close (data->fd); + + data->fd = -1; + +#endif +} + + +void +LockFile::lock () const +{ + LogLog & loglog = getLogLog (); + int ret = 0; + (void) loglog; + (void) ret; + +#if defined (LOG4CPLUS_USE_WIN32_LOCKFILEEX) + HANDLE fh = get_os_HANDLE (data->fd, loglog); + + OVERLAPPED overlapped; + std::memset (&overlapped, 0, sizeof (overlapped)); + overlapped.hEvent = 0; + + ret = LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK, 0, + (std::numeric_limits<DWORD>::max) (), + (std::numeric_limits<DWORD>::max) (), &overlapped); + if (! ret) + loglog.error (tstring (LOG4CPLUS_TEXT ("LockFileEx() failed: ")) + + convertIntegerToString (GetLastError ()), true); + +#elif defined (LOG4CPLUS_USE_WIN32_LOCKING) + ret = _locking (data->fd, _LK_LOCK, (std::numeric_limits<long>::max) ()); + if (ret != 0) + loglog.error (tstring (LOG4CPLUS_TEXT ("_locking() failed: ")) + + convertIntegerToString (errno), true); + +#elif defined (LOG4CPLUS_USE_O_EXLOCK) + open (OPEN_FLAGS | O_EXLOCK); + +#elif defined (LOG4CPLUS_USE_SETLKW) + do + { + struct flock fl; + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + ret = fcntl (data->fd, F_SETLKW, &fl); + if (ret == -1 && errno != EINTR) + loglog.error (tstring (LOG4CPLUS_TEXT("fcntl(F_SETLKW) failed: ")) + + convertIntegerToString (errno), true); + } + while (ret == -1); + +#elif defined (LOG4CPLUS_USE_LOCKF) + do + { + ret = lockf (data->fd, F_LOCK, 0); + if (ret == -1 && errno != EINTR) + loglog.error (tstring (LOG4CPLUS_TEXT("lockf() failed: ")) + + convertIntegerToString (errno), true); + } + while (ret == -1); + +#elif defined (LOG4CPLUS_USE_FLOCK) + do + { + ret = flock (data->fd, LOCK_EX); + if (ret == -1 && errno != EINTR) + loglog.error (tstring (LOG4CPLUS_TEXT("flock() failed: ")) + + convertIntegerToString (errno), true); + } + while (ret == -1); + +#endif +} + + +void LockFile::unlock () const +{ + LogLog & loglog = getLogLog (); + int ret = 0; + +#if defined (LOG4CPLUS_USE_WIN32_LOCKFILEEX) + HANDLE fh = get_os_HANDLE (data->fd, loglog); + + ret = UnlockFile(fh, 0, 0, (std::numeric_limits<DWORD>::max) (), + (std::numeric_limits<DWORD>::max) ()); + if (! ret) + loglog.error (tstring (LOG4CPLUS_TEXT ("UnlockFile() failed: ")) + + convertIntegerToString (GetLastError ()), true); + +#elif defined (LOG4CPLUS_USE_WIN32_LOCKING) + ret = _locking (data->fd, _LK_UNLCK, (std::numeric_limits<long>::max) ()); + if (ret != 0) + loglog.error (tstring (LOG4CPLUS_TEXT ("_locking() failed: ")) + + convertIntegerToString (errno), true); + +#elif defined (LOG4CPLUS_USE_O_EXLOCK) + close (); + +#elif defined (LOG4CPLUS_USE_SETLKW) + struct flock fl; + fl.l_type = F_UNLCK; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + ret = fcntl (data->fd, F_SETLKW, &fl); + if (ret != 0) + loglog.error (tstring (LOG4CPLUS_TEXT("fcntl(F_SETLKW) failed: ")) + + convertIntegerToString (errno), true); + +#elif defined (LOG4CPLUS_USE_LOCKF) + ret = lockf (data->fd, F_ULOCK, 0); + if (ret != 0) + loglog.error (tstring (LOG4CPLUS_TEXT("lockf() failed: ")) + + convertIntegerToString (errno), true); + +#elif defined (LOG4CPLUS_USE_FLOCK) + ret = flock (data->fd, LOCK_UN); + if (ret != 0) + loglog.error (tstring (LOG4CPLUS_TEXT("flock() failed: ")) + + convertIntegerToString (errno), true); + +#endif + +} + + + +} } // namespace log4cplus { namespace helpers { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/log4judpappender.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/log4judpappender.cxx new file mode 100644 index 000000000..f33a04b34 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/log4judpappender.cxx @@ -0,0 +1,254 @@ +// Module: Log4CPLUS +// File: log4judpappender.cxx +// Created: 7/2012 +// Author: Siva Chandran P +// +// +// Copyright 2012 Siva Chandran P +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/log4judpappender.h> +#include <log4cplus/layout.h> +#include <log4cplus/streams.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/spi/loggingevent.h> +#include <log4cplus/internal/internal.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <iomanip> +#include <cstring> +#if defined (UNICODE) +#include <cwctype> +#else +#include <cctype> +#endif + + +namespace log4cplus +{ + +namespace +{ + + +static inline bool +is_control (tchar ch) +{ +#if defined (UNICODE) + return !! std::iswcntrl (std::char_traits<tchar>::to_int_type (ch)); +#else + return !! std::iscntrl (std::char_traits<tchar>::to_int_type (ch)); +#endif +} + + +//! Outputs str with reserved XML characters escaped. +static +void +output_xml_escaped (tostream & os, tstring const & str) +{ + for (tstring::const_iterator it = str.begin (); it != str.end (); ++it) + { + tchar const & ch = *it; + switch (ch) + { + case LOG4CPLUS_TEXT ('<'): + os << LOG4CPLUS_TEXT ("<"); + break; + + case LOG4CPLUS_TEXT ('>'): + os << LOG4CPLUS_TEXT (">"); + break; + + case LOG4CPLUS_TEXT ('&'): + os << LOG4CPLUS_TEXT ("&"); + break; + + case LOG4CPLUS_TEXT ('\''): + os << LOG4CPLUS_TEXT ("'"); + break; + + case LOG4CPLUS_TEXT ('"'): + os << LOG4CPLUS_TEXT ("""); + break; + + default: + if (is_control (ch)) + { + tchar const prev_fill = os.fill (); + std::ios_base::fmtflags const prev_flags = os.flags (); + os.flags (std::ios_base::hex | std::ios_base::right); + os.fill (LOG4CPLUS_TEXT ('0')); + + os << std::setw (0) << LOG4CPLUS_TEXT ("&#x") + << std::setw (2) << std::char_traits<tchar>::to_int_type (ch) + << std::setw (0) << LOG4CPLUS_TEXT (";"); + + os.fill (prev_fill); + os.flags (prev_flags); + } + else + os.put (ch); + } + } +} + + +//! Helper manipulator like class for escaped XML output. +struct outputXMLEscaped +{ + outputXMLEscaped (tstring const & s) + : str (s) + { } + + tstring const & str; +}; + + +//! Overload stream insertion for outputXMLEscaped. +static +tostream & +operator << (tostream & os, outputXMLEscaped const & x) +{ + output_xml_escaped (os, x.str); + return os; +} + + +} // namespace + + +////////////////////////////////////////////////////////////////////////////// +// Log4jUdpAppender ctors and dtor +////////////////////////////////////////////////////////////////////////////// + +Log4jUdpAppender::Log4jUdpAppender(const tstring& host_, int port_) + : host(host_) + , port(port_) +{ + layout.reset (new PatternLayout (LOG4CPLUS_TEXT ("%m"))); + openSocket(); +} + + + +Log4jUdpAppender::Log4jUdpAppender(const helpers::Properties & properties) + : Appender(properties) + , port(5000) +{ + host = properties.getProperty( LOG4CPLUS_TEXT("host"), + LOG4CPLUS_TEXT ("localhost") ); + properties.getInt (port, LOG4CPLUS_TEXT ("port")); + + openSocket(); +} + + + +Log4jUdpAppender::~Log4jUdpAppender() +{ + destructorImpl(); +} + + + +////////////////////////////////////////////////////////////////////////////// +// Log4jUdpAppender public methods +////////////////////////////////////////////////////////////////////////////// + +void +Log4jUdpAppender::close() +{ + helpers::getLogLog().debug( + LOG4CPLUS_TEXT("Entering Log4jUdpAppender::close()...")); + + socket.close(); + closed = true; +} + + + +////////////////////////////////////////////////////////////////////////////// +// Log4jUdpAppender protected methods +////////////////////////////////////////////////////////////////////////////// + +void +Log4jUdpAppender::openSocket() +{ + if(!socket.isOpen()) { + socket = helpers::Socket(host, port, true); + } +} + +void +Log4jUdpAppender::append(const spi::InternalLoggingEvent& event) +{ + if(!socket.isOpen()) { + openSocket(); + if(!socket.isOpen()) { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("Log4jUdpAppender::append()- Cannot connect to server")); + return; + } + } + + tstring & str = formatEvent (event); + + internal::appender_sratch_pad & appender_sp + = internal::get_appender_sp (); + tostringstream & buffer = appender_sp.oss; + detail::clear_tostringstream (buffer); + + buffer << LOG4CPLUS_TEXT("<log4j:event logger=\"") + << outputXMLEscaped (event.getLoggerName()) + << LOG4CPLUS_TEXT("\" level=\"") + // TODO: Some escaping of special characters is needed here. + << outputXMLEscaped (getLogLevelManager().toString(event.getLogLevel())) + << LOG4CPLUS_TEXT("\" timestamp=\"") + << event.getTimestamp().getFormattedTime(LOG4CPLUS_TEXT("%s%q")) + << LOG4CPLUS_TEXT("\" thread=\"") << event.getThread() + << LOG4CPLUS_TEXT("\">") + + << LOG4CPLUS_TEXT("<log4j:message>") + // TODO: Some escaping of special characters is needed here. + << outputXMLEscaped (str) + << LOG4CPLUS_TEXT("</log4j:message>") + + << LOG4CPLUS_TEXT("<log4j:NDC>") + // TODO: Some escaping of special characters is needed here. + << outputXMLEscaped (event.getNDC()) + << LOG4CPLUS_TEXT("</log4j:NDC>") + + << LOG4CPLUS_TEXT("<log4j:locationInfo class=\"\" file=\"") + // TODO: Some escaping of special characters is needed here. + << outputXMLEscaped (event.getFile()) + << LOG4CPLUS_TEXT("\" method=\"") + << outputXMLEscaped (event.getFunction()) + << LOG4CPLUS_TEXT("\" line=\"") + << event.getLine() + << LOG4CPLUS_TEXT("\"/>") + << LOG4CPLUS_TEXT("</log4j:event>"); + + LOG4CPLUS_TSTRING_TO_STRING (buffer.str ()).swap (appender_sp.chstr); + + bool ret = socket.write(appender_sp.chstr); + if (!ret) + { + helpers::getLogLog().error( + LOG4CPLUS_TEXT( + "Log4jUdpAppender::append()- Cannot write to server")); + } +} + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/logger.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/logger.cxx new file mode 100644 index 000000000..2d490437c --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/logger.cxx @@ -0,0 +1,332 @@ +// Module: Log4CPLUS +// File: logger.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// +// Copyright 2001-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/logger.h> +#include <log4cplus/appender.h> +#include <log4cplus/hierarchy.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/spi/loggerimpl.h> +#include <utility> + + +namespace log4cplus +{ + + +Logger +DefaultLoggerFactory::makeNewLoggerInstance (const log4cplus::tstring & name, + Hierarchy& h) +{ + return Logger (new spi::LoggerImpl (name, h)); +} + + +////////////////////////////////////////////////////////////////////////////// +// static Logger Methods +////////////////////////////////////////////////////////////////////////////// +// +Hierarchy & +Logger::getDefaultHierarchy () +{ + return log4cplus::getDefaultHierarchy (); +} + + +bool +Logger::exists (const log4cplus::tstring & name) +{ + return getDefaultHierarchy().exists(name); +} + + +LoggerList +Logger::getCurrentLoggers () +{ + return getDefaultHierarchy ().getCurrentLoggers (); +} + + +Logger +Logger::getInstance (const log4cplus::tstring& name) +{ + return getDefaultHierarchy().getInstance(name); +} + + +Logger +Logger::getInstance (const log4cplus::tstring& name, + spi::LoggerFactory& factory) +{ + return getDefaultHierarchy().getInstance(name, factory); +} + + +Logger +Logger::getRoot () +{ + return getDefaultHierarchy ().getRoot (); +} + + +void +Logger::shutdown () +{ + getDefaultHierarchy ().shutdown (); +} + + + +////////////////////////////////////////////////////////////////////////////// +// Logger ctors and dtor +////////////////////////////////////////////////////////////////////////////// + +Logger::Logger () + : value (0) +{ } + + +Logger::Logger (spi::LoggerImpl * ptr) + : value (ptr) +{ + if (value) + value->addReference (); +} + + +Logger::Logger (const Logger& rhs) + : spi::AppenderAttachable (rhs) + , value (rhs.value) +{ + if (value) + value->addReference (); +} + + +Logger & +Logger::operator = (const Logger& rhs) +{ + Logger (rhs).swap (*this); + return *this; +} + + +#if defined (LOG4CPLUS_HAVE_RVALUE_REFS) +Logger::Logger (Logger && rhs) + : spi::AppenderAttachable (std::move (rhs)) + , value (std::move (rhs.value)) +{ + rhs.value = 0; +} + + +Logger & +Logger::operator = (Logger && rhs) +{ + Logger (std::move (rhs)).swap (*this); + return *this; +} + +#endif + + +Logger::~Logger () +{ + if (value) + value->removeReference (); +} + + +////////////////////////////////////////////////////////////////////////////// +// Logger Methods +////////////////////////////////////////////////////////////////////////////// + +void +Logger::swap (Logger & other) +{ + std::swap (value, other.value); +} + + +Logger +Logger::getParent () const +{ + if (value->parent) + return Logger (value->parent.get ()); + else + { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("********* This logger has no parent: " + + getName())); + return *this; + } +} + + +void +Logger::addAppender (SharedAppenderPtr newAppender) +{ + value->addAppender(newAppender); +} + + +SharedAppenderPtrList +Logger::getAllAppenders () +{ + return value->getAllAppenders(); +} + + +SharedAppenderPtr +Logger::getAppender (const log4cplus::tstring& name) +{ + return value->getAppender (name); +} + + +void +Logger::removeAllAppenders () +{ + value->removeAllAppenders (); +} + + +void +Logger::removeAppender (SharedAppenderPtr appender) +{ + value->removeAppender(appender); +} + + +void +Logger::removeAppender (const log4cplus::tstring& name) +{ + value->removeAppender (name); +} + + +void +Logger::assertion (bool assertionVal, const log4cplus::tstring& msg) const +{ + if (! assertionVal) + log (FATAL_LOG_LEVEL, msg); +} + + +void +Logger::closeNestedAppenders () const +{ + value->closeNestedAppenders (); +} + + +bool +Logger::isEnabledFor (LogLevel ll) const +{ + return value->isEnabledFor (ll); +} + + +void +Logger::log (LogLevel ll, const log4cplus::tstring& message, const char* file, + int line) const +{ + value->log (ll, message, file, line); +} + + +void +Logger::log (spi::InternalLoggingEvent const & ev) const +{ + value->log (ev); +} + + +void +Logger::forcedLog (LogLevel ll, const log4cplus::tstring& message, + const char* file, int line) const +{ + value->forcedLog (ll, message, file, line); +} + + +void +Logger::forcedLog (spi::InternalLoggingEvent const & ev) const +{ + value->forcedLog (ev); +} + + +void +Logger::callAppenders (const spi::InternalLoggingEvent& event) const +{ + value->callAppenders (event); +} + + +LogLevel +Logger::getChainedLogLevel () const +{ + return value->getChainedLogLevel (); +} + + +LogLevel +Logger::getLogLevel() const +{ + return value->getLogLevel (); +} + + +void +Logger::setLogLevel (LogLevel ll) +{ + value->setLogLevel (ll); +} + + +Hierarchy & +Logger::getHierarchy () const +{ + return value->getHierarchy (); +} + + +log4cplus::tstring const & +Logger::getName () const +{ + return value->getName (); +} + + +bool +Logger::getAdditivity () const +{ + return value->getAdditivity (); +} + + +void +Logger::setAdditivity (bool additive) +{ + value->setAdditivity (additive); +} + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loggerimpl.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loggerimpl.cxx new file mode 100644 index 000000000..08ba0aaca --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loggerimpl.cxx @@ -0,0 +1,176 @@ +// Module: Log4CPLUS +// File: loggerimpl.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// +// Copyright 2001-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/internal/internal.h> +#include <log4cplus/spi/loggerimpl.h> +#include <log4cplus/appender.h> +#include <log4cplus/hierarchy.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/spi/loggingevent.h> +#include <log4cplus/spi/rootlogger.h> +#include <log4cplus/thread/syncprims-pub-impl.h> + + +namespace log4cplus { namespace spi { + +////////////////////////////////////////////////////////////////////////////// +// Logger Constructors and Destructor +////////////////////////////////////////////////////////////////////////////// +LoggerImpl::LoggerImpl(const log4cplus::tstring& name_, Hierarchy& h) + : name(name_), + ll(NOT_SET_LOG_LEVEL), + parent(NULL), + additive(true), + hierarchy(h) +{ +} + + +LoggerImpl::~LoggerImpl() +{ +} + + +////////////////////////////////////////////////////////////////////////////// +// Logger Methods +////////////////////////////////////////////////////////////////////////////// + +void +LoggerImpl::callAppenders(const InternalLoggingEvent& event) +{ + int writes = 0; + for(const LoggerImpl* c = this; c != NULL; c=c->parent.get()) { + writes += c->appendLoopOnAppenders(event); + if(!c->additive) { + break; + } + } + + // No appenders in hierarchy, warn user only once. + if(!hierarchy.emittedNoAppenderWarning && writes == 0) { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("No appenders could be found for logger (") + + getName() + + LOG4CPLUS_TEXT(").")); + helpers::getLogLog().error( + LOG4CPLUS_TEXT("Please initialize the log4cplus system properly.")); + hierarchy.emittedNoAppenderWarning = true; + } +} + + +void +LoggerImpl::closeNestedAppenders() +{ + SharedAppenderPtrList appenders = getAllAppenders(); + for(SharedAppenderPtrList::iterator it=appenders.begin(); it!=appenders.end(); ++it) + { + (*it)->close(); + } +} + + +bool +LoggerImpl::isEnabledFor(LogLevel loglevel) const +{ + if(hierarchy.disableValue >= loglevel) { + return false; + } + return loglevel >= getChainedLogLevel(); +} + + +void +LoggerImpl::log(LogLevel loglevel, + const log4cplus::tstring& message, + const char* file, + int line) +{ + if(isEnabledFor(loglevel)) { + forcedLog(loglevel, message, file, line); + } +} + + +void +LoggerImpl::log(spi::InternalLoggingEvent const & ev) +{ + if (isEnabledFor(ev.getLogLevel ())) + forcedLog(ev); +} + + +LogLevel +LoggerImpl::getChainedLogLevel() const +{ + for(const LoggerImpl *c=this; c != NULL; c=c->parent.get()) { + if(c->ll != NOT_SET_LOG_LEVEL) { + return c->ll; + } + } + + helpers::getLogLog().error( + LOG4CPLUS_TEXT("LoggerImpl::getChainedLogLevel()- No valid LogLevel found"), + true); + return NOT_SET_LOG_LEVEL; +} + + +Hierarchy& +LoggerImpl::getHierarchy() const +{ + return hierarchy; +} + + +bool +LoggerImpl::getAdditivity() const +{ + return additive; +} + + +void +LoggerImpl::setAdditivity(bool additive_) +{ + additive = additive_; +} + + +void +LoggerImpl::forcedLog(LogLevel loglevel, + const log4cplus::tstring& message, + const char* file, + int line) +{ + spi::InternalLoggingEvent & ev = internal::get_ptd ()->forced_log_ev; + ev.setLoggingEvent (this->getName(), loglevel, message, file, line); + callAppenders(ev); +} + + +void +LoggerImpl::forcedLog(spi::InternalLoggingEvent const & ev) +{ + callAppenders(ev); +} + + +} } // namespace log4cplus { namespace spi { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loggingevent.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loggingevent.cxx new file mode 100644 index 000000000..f0c951bde --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loggingevent.cxx @@ -0,0 +1,252 @@ +// Module: Log4CPLUS +// File: loggingevent.cxx +// Created: 6/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/spi/loggingevent.h> +#include <log4cplus/internal/internal.h> +#include <algorithm> + + +namespace log4cplus { namespace spi { + + +static const int LOG4CPLUS_DEFAULT_TYPE = 1; + + +/////////////////////////////////////////////////////////////////////////////// +// InternalLoggingEvent ctors and dtor +/////////////////////////////////////////////////////////////////////////////// + +InternalLoggingEvent::InternalLoggingEvent(const log4cplus::tstring& logger, + LogLevel loglevel, const log4cplus::tstring& message_, const char* filename, + int line_) + : message(message_) + , loggerName(logger) + , ll(loglevel) + , ndc() + , mdc() + , thread() + , timestamp(log4cplus::helpers::Time::gettimeofday()) + , file(filename + ? LOG4CPLUS_C_STR_TO_TSTRING(filename) + : log4cplus::tstring()) + , function () + , line(line_) + , threadCached(false) + , thread2Cached(false) + , ndcCached(false) + , mdcCached(false) +{ +} + + +InternalLoggingEvent::InternalLoggingEvent(const log4cplus::tstring& logger, + LogLevel loglevel, const log4cplus::tstring& ndc_, + MappedDiagnosticContextMap const & mdc_, const log4cplus::tstring& message_, + const log4cplus::tstring& thread_, log4cplus::helpers::Time time, + const log4cplus::tstring& file_, int line_) + : message(message_) + , loggerName(logger) + , ll(loglevel) + , ndc(ndc_) + , mdc(mdc_) + , thread(thread_) + , timestamp(time) + , file(file_) + , function () + , line(line_) + , threadCached(true) + , thread2Cached(true) + , ndcCached(true) + , mdcCached(true) +{ +} + + +InternalLoggingEvent::InternalLoggingEvent () + : ll (NOT_SET_LOG_LEVEL) + , function () + , line (0) + , threadCached(false) + , thread2Cached(false) + , ndcCached(false) + , mdcCached(false) +{ } + + +InternalLoggingEvent::InternalLoggingEvent( + const log4cplus::spi::InternalLoggingEvent& rhs) + : message(rhs.getMessage()) + , loggerName(rhs.getLoggerName()) + , ll(rhs.getLogLevel()) + , ndc(rhs.getNDC()) + , mdc(rhs.getMDCCopy()) + , thread(rhs.getThread()) + , timestamp(rhs.getTimestamp()) + , file(rhs.getFile()) + , function(rhs.getFunction()) + , line(rhs.getLine()) + , threadCached(true) + , thread2Cached(true) + , ndcCached(true) + , mdcCached(true) +{ +} + + +InternalLoggingEvent::~InternalLoggingEvent() +{ +} + + + +/////////////////////////////////////////////////////////////////////////////// +// InternalLoggingEvent static methods +/////////////////////////////////////////////////////////////////////////////// + +unsigned int +InternalLoggingEvent::getDefaultType() +{ + return LOG4CPLUS_DEFAULT_TYPE; +} + + + +/////////////////////////////////////////////////////////////////////////////// +// InternalLoggingEvent implementation +/////////////////////////////////////////////////////////////////////////////// + +void +InternalLoggingEvent::setLoggingEvent (const log4cplus::tstring & logger, + LogLevel loglevel, const log4cplus::tstring & msg, const char * filename, + int fline) +{ + // This could be imlemented using the swap idiom: + // + // InternalLoggingEvent (logger, loglevel, msg, filename, fline).swap (*this); + // + // But that defeats the optimization of using thread local instance + // of InternalLoggingEvent to avoid memory allocation. + + loggerName = logger; + ll = loglevel; + message = msg; + timestamp = helpers::Time::gettimeofday(); + if (filename) + file = LOG4CPLUS_C_STR_TO_TSTRING (filename); + else + file.clear (); + line = fline; + threadCached = false; + thread2Cached = false; + ndcCached = false; + mdcCached = false; +} + + +void +InternalLoggingEvent::setFunction (char const * func) +{ + function = LOG4CPLUS_C_STR_TO_TSTRING (func); +} + + +void +InternalLoggingEvent::setFunction (log4cplus::tstring const & func) +{ + function = func; +} + + +const log4cplus::tstring& +InternalLoggingEvent::getMessage() const +{ + return message; +} + + +unsigned int +InternalLoggingEvent::getType() const +{ + return LOG4CPLUS_DEFAULT_TYPE; +} + + + +std::auto_ptr<InternalLoggingEvent> +InternalLoggingEvent::clone() const +{ + std::auto_ptr<InternalLoggingEvent> tmp(new InternalLoggingEvent(*this)); + return tmp; +} + + +tstring const & +InternalLoggingEvent::getMDC (tstring const & key) const +{ + MappedDiagnosticContextMap const & mdc_ = getMDCCopy (); + MappedDiagnosticContextMap::const_iterator it = mdc_.find (key); + if (it != mdc_.end ()) + return it->second; + else + return internal::empty_str; +} + + + +InternalLoggingEvent & +InternalLoggingEvent::operator = (const InternalLoggingEvent& rhs) +{ + InternalLoggingEvent (rhs).swap (*this); + return *this; +} + + +void +InternalLoggingEvent::gatherThreadSpecificData () const +{ + getNDC (); + getMDCCopy (); + getThread (); + getThread2 (); +} + + +void +InternalLoggingEvent::swap (InternalLoggingEvent & other) +{ + using std::swap; + + swap (message, other.message); + swap (loggerName, other.loggerName); + swap (ll, other.ll); + swap (ndc, other.ndc); + swap (mdc, other.mdc); + swap (thread, other.thread); + swap (thread2, other.thread2); + swap (timestamp, other.timestamp); + swap (file, other.file); + swap (function, other.function); + swap (line, other.line); + swap (threadCached, other.threadCached); + swap (ndcCached, other.ndcCached); +} + + +} } // namespace log4cplus { namespace spi { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loggingmacros.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loggingmacros.cxx new file mode 100644 index 000000000..3005ed8d3 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loggingmacros.cxx @@ -0,0 +1,89 @@ +// Module: Log4CPLUS +// File: loggingmacros.cxx +// Created: 4/2010 +// Author: Vaclav Haisman +// +// +// Copyright 2010 Vaclav Haisman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** @file + * This file implements support function for loggingmacros.h file. */ + +#include <log4cplus/internal/internal.h> +#include <log4cplus/loggingmacros.h> + + +namespace log4cplus { namespace detail { + + +//! Helper stream to get the defaults from. +static tostringstream const macros_oss_defaults; + +// Individual defaults. + +static std::ios_base::fmtflags const default_flags + = macros_oss_defaults.flags (); +static log4cplus::tchar const default_fill = macros_oss_defaults.fill (); +static std::streamsize const default_precision + = macros_oss_defaults.precision (); +static std::streamsize const default_width = macros_oss_defaults.width (); + +//! Clears string stream using defaults taken from macros_oss_defaults. +void +clear_tostringstream (tostringstream & os) +{ + os.clear (); + os.str (internal::empty_str); + os.setf (default_flags); + os.fill (default_fill); + os.precision (default_precision); + os.width (default_width); +#if defined (LOG4CPLUS_WORKING_LOCALE) + std::locale glocale = std::locale (); + if (os.getloc () != glocale) + os.imbue (glocale); +#endif // defined (LOG4CPLUS_WORKING_LOCALE) +} + + +log4cplus::tostringstream & +get_macro_body_oss () +{ + tostringstream & oss = internal::get_ptd ()->macros_oss; + clear_tostringstream (oss); + return oss; +} + + +log4cplus::helpers::snprintf_buf & +get_macro_body_snprintf_buf () +{ + return internal::get_ptd ()->snprintf_buf; +} + + +void +macro_forced_log (log4cplus::Logger const & logger, + log4cplus::LogLevel log_level, log4cplus::tstring const & msg, + char const * filename, int line, char const * func) +{ + log4cplus::spi::InternalLoggingEvent & ev = internal::get_ptd ()->forced_log_ev; + ev.setLoggingEvent (logger.getName (), log_level, msg, filename, line); + ev.setFunction (func ? func : ""); + logger.forcedLog (ev); +} + + +} } // namespace log4cplus { namespace detail { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loglevel.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loglevel.cxx new file mode 100644 index 000000000..4481f792a --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loglevel.cxx @@ -0,0 +1,206 @@ +// Module: Log4CPLUS +// File: loglevel.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// +// Copyright 2001-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/loglevel.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/internal/internal.h> +#include <algorithm> + + +namespace log4cplus +{ + + +namespace +{ + +static tstring const ALL_STRING (LOG4CPLUS_TEXT("ALL")); +static tstring const TRACE_STRING (LOG4CPLUS_TEXT("TRACE")); +static tstring const DEBUG_STRING (LOG4CPLUS_TEXT("DEBUG")); +static tstring const INFO_STRING (LOG4CPLUS_TEXT("INFO")); +static tstring const WARN_STRING (LOG4CPLUS_TEXT("WARN")); +static tstring const ERROR_STRING (LOG4CPLUS_TEXT("ERROR")); +static tstring const FATAL_STRING (LOG4CPLUS_TEXT("FATAL")); +static tstring const OFF_STRING (LOG4CPLUS_TEXT("OFF")); +static tstring const NOTSET_STRING (LOG4CPLUS_TEXT("NOTSET")); +static tstring const UNKNOWN_STRING (LOG4CPLUS_TEXT("UNKNOWN")); + + +struct log_levels_table_rec +{ + LogLevel const ll; + tstring const * const str; +}; + + +#define DEF_LLTAB_REC(x) { x ## _LOG_LEVEL, &(x ## _STRING) } + +static log_levels_table_rec const log_levels_table[8] = { + DEF_LLTAB_REC (OFF), + DEF_LLTAB_REC (FATAL), + DEF_LLTAB_REC (ERROR), + DEF_LLTAB_REC (WARN), + DEF_LLTAB_REC (INFO), + DEF_LLTAB_REC (DEBUG), + DEF_LLTAB_REC (TRACE), + DEF_LLTAB_REC (ALL), +}; + +#undef DEF_LLTAB_REC + + +static +tstring const & +defaultLogLevelToStringMethod(LogLevel ll) +{ + switch(ll) { + case OFF_LOG_LEVEL: return OFF_STRING; + case FATAL_LOG_LEVEL: return FATAL_STRING; + case ERROR_LOG_LEVEL: return ERROR_STRING; + case WARN_LOG_LEVEL: return WARN_STRING; + case INFO_LOG_LEVEL: return INFO_STRING; + case DEBUG_LOG_LEVEL: return DEBUG_STRING; + case TRACE_LOG_LEVEL: return TRACE_STRING; + //case ALL_LOG_LEVEL: return ALL_STRING; + case NOT_SET_LOG_LEVEL: return NOTSET_STRING; + }; + + return internal::empty_str; +} + + +static +LogLevel +defaultStringToLogLevelMethod(const tstring& s) +{ + std::size_t const tbl_size + = sizeof (log_levels_table) / sizeof (log_levels_table[0]); + + for (log_levels_table_rec const * it = log_levels_table; + it != log_levels_table + tbl_size; ++it) + { + if (*it->str == s) + return it->ll; + } + + return NOT_SET_LOG_LEVEL; +} + +} // namespace + + + +////////////////////////////////////////////////////////////////////////////// +// LogLevelManager ctors and dtor +////////////////////////////////////////////////////////////////////////////// + +LogLevelManager::LogLevelManager() +{ + LogLevelToStringMethodRec rec; + rec.func = defaultLogLevelToStringMethod; + rec.use_1_0 = false; + toStringMethods.push_back (rec); + + fromStringMethods.push_back (defaultStringToLogLevelMethod); +} + + +LogLevelManager::~LogLevelManager() +{ } + + + +////////////////////////////////////////////////////////////////////////////// +// LogLevelManager public methods +////////////////////////////////////////////////////////////////////////////// + +tstring const & +LogLevelManager::toString(LogLevel ll) const +{ + tstring const * ret; + for (LogLevelToStringMethodList::const_iterator it + = toStringMethods.begin (); it != toStringMethods.end (); ++it) + { + LogLevelToStringMethodRec const & rec = *it; + if (rec.use_1_0) + { + // Use TLS to store the result to allow us to return + // a reference. + tstring & ll_str = internal::get_ptd ()->ll_str; + rec.func_1_0 (ll).swap (ll_str); + ret = &ll_str; + } + else + ret = &rec.func (ll); + + if (! ret->empty ()) + return *ret; + } + + return UNKNOWN_STRING; +} + + +LogLevel +LogLevelManager::fromString(const tstring& arg) const +{ + tstring s = helpers::toUpper(arg); + + for (StringToLogLevelMethodList::const_iterator it + = fromStringMethods.begin (); it != fromStringMethods.end (); ++it) + { + LogLevel ret = (*it) (s); + if (ret != NOT_SET_LOG_LEVEL) + return ret; + } + + return NOT_SET_LOG_LEVEL; +} + + +void +LogLevelManager::pushToStringMethod(LogLevelToStringMethod newToString) +{ + LogLevelToStringMethodRec rec; + rec.func = newToString; + rec.use_1_0 = false; + toStringMethods.push_back (rec); +} + + +void +LogLevelManager::pushToStringMethod(LogLevelToStringMethod_1_0 newToString) +{ + LogLevelToStringMethodRec rec; + rec.func_1_0 = newToString; + rec.use_1_0 = true; + toStringMethods.push_back (rec); +} + + +void +LogLevelManager::pushFromStringMethod(StringToLogLevelMethod newFromString) +{ + fromStringMethods.push_back (newFromString); +} + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loglog.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loglog.cxx new file mode 100644 index 000000000..0e174e10c --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/loglog.cxx @@ -0,0 +1,188 @@ +// Module: Log4CPLUS +// File: loglog.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// +// Copyright 2001-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/streams.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <log4cplus/thread/threads.h> +#include <log4cplus/internal/env.h> +#include <log4cplus/consoleappender.h> +#include <ostream> +#include <stdexcept> + + +namespace log4cplus { namespace helpers { + +namespace +{ + +static tchar const PREFIX[] = LOG4CPLUS_TEXT("log4cplus: "); +static tchar const WARN_PREFIX[] = LOG4CPLUS_TEXT("log4cplus:WARN "); +static tchar const ERR_PREFIX[] = LOG4CPLUS_TEXT("log4cplus:ERROR "); + +} // namespace + + +LogLog * +LogLog::getLogLog() +{ + return &helpers::getLogLog (); +} + + +LogLog::LogLog() + : debugEnabled(TriUndef) + , quietMode(TriUndef) +{ } + + +LogLog::~LogLog() +{ } + + +void +LogLog::setInternalDebugging(bool enabled) +{ + thread::MutexGuard guard (mutex); + + debugEnabled = enabled ? TriTrue : TriFalse; +} + + +void +LogLog::setQuietMode(bool quietModeVal) +{ + thread::MutexGuard guard (mutex); + + quietMode = quietModeVal ? TriTrue : TriFalse; +} + + +void +LogLog::debug(const log4cplus::tstring& msg) const +{ + logging_worker (tcout, &LogLog::get_debug_mode, PREFIX, msg); +} + + +void +LogLog::debug(tchar const * msg) const +{ + logging_worker (tcout, &LogLog::get_debug_mode, PREFIX, msg); +} + + +void +LogLog::warn(const log4cplus::tstring& msg) const +{ + logging_worker (tcerr, &LogLog::get_not_quiet_mode, WARN_PREFIX, msg); +} + + +void +LogLog::warn(tchar const * msg) const +{ + logging_worker (tcerr, &LogLog::get_not_quiet_mode, WARN_PREFIX, msg); +} + + +void +LogLog::error(const log4cplus::tstring& msg, bool throw_flag) const +{ + logging_worker (tcerr, &LogLog::get_not_quiet_mode, ERR_PREFIX, msg, + throw_flag); +} + + +void +LogLog::error(tchar const * msg, bool throw_flag) const +{ + logging_worker (tcerr, &LogLog::get_not_quiet_mode, ERR_PREFIX, msg, + throw_flag); +} + + +bool +LogLog::get_quiet_mode () const +{ + if (quietMode == TriUndef) + set_tristate_from_env (&quietMode, + LOG4CPLUS_TEXT ("LOG4CPLUS_LOGLOG_QUIETMODE")); + + return quietMode == TriTrue; +} + + +bool +LogLog::get_not_quiet_mode () const +{ + return ! get_quiet_mode (); +} + + +bool +LogLog::get_debug_mode () const +{ + if (debugEnabled == TriUndef) + set_tristate_from_env (&debugEnabled, + LOG4CPLUS_TEXT ("LOG4CPLUS_LOGLOG_DEBUGENABLED")); + + return debugEnabled && ! get_quiet_mode (); +} + + +void +LogLog::set_tristate_from_env (TriState * result, tchar const * envvar_name) +{ + tstring envvar_value; + bool exists = internal::get_env_var (envvar_value, envvar_name); + bool value = false; + if (exists && internal::parse_bool (value, envvar_value) && value) + *result = TriTrue; + else + *result = TriFalse; +} + + +template <typename StringType> +void +LogLog::logging_worker (tostream & os, bool (LogLog:: * cond) () const, + tchar const * prefix, StringType const & msg, bool throw_flag) const +{ + bool output; + { + thread::MutexGuard guard (mutex); + output = (this->*cond) (); + } + + if (LOG4CPLUS_UNLIKELY (output)) + { + // XXX This is potential recursive lock of + // ConsoleAppender::outputMutex. + thread::MutexGuard outputGuard (ConsoleAppender::getOutputMutex ()); + os << prefix << msg << std::endl; + } + + if (LOG4CPLUS_UNLIKELY (throw_flag)) + throw std::runtime_error (LOG4CPLUS_TSTRING_TO_STRING (msg)); +} + + +} } // namespace log4cplus { namespace helpers { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/logloguser.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/logloguser.cxx new file mode 100644 index 000000000..2804c22b7 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/logloguser.cxx @@ -0,0 +1,53 @@ +// Module: Log4CPLUS +// File: logloguser.cxx +// Created: 6/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/helpers/logloguser.h> +#include <log4cplus/helpers/loglog.h> + + +namespace log4cplus { namespace helpers { + + +LogLogUser::LogLogUser() +{ } + + +LogLogUser::LogLogUser(const LogLogUser&) +{ } + + +LogLogUser::~LogLogUser() +{ } + + +LogLog& +LogLogUser::getLogLog() const +{ + return *LogLog::getLogLog (); +} + + +LogLogUser& +LogLogUser::operator=(const LogLogUser&) +{ + return *this; +} + +} } // namespace log4cplus { namespace helpers { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/mdc.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/mdc.cxx new file mode 100644 index 000000000..6d83ed649 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/mdc.cxx @@ -0,0 +1,95 @@ +// Copyright (C) 2010, Vaclav Haisman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <log4cplus/mdc.h> +#include <log4cplus/internal/internal.h> + + +namespace log4cplus +{ + + +MDC::MDC () +{ } + + +MDC::~MDC () +{ } + + +MappedDiagnosticContextMap * +MDC::getPtr () +{ + return &internal::get_ptd ()->mdc_map; +} + + +void +MDC::clear() +{ + MappedDiagnosticContextMap * const dc = getPtr (); + MappedDiagnosticContextMap ().swap (*dc); +} + + +void +MDC::put (tstring const & key, tstring const & value) +{ + MappedDiagnosticContextMap * const dc = getPtr (); + (*dc)[key] = value; +} + + +bool +MDC::get (tstring * value, tstring const & key) const +{ + assert (value); + + MappedDiagnosticContextMap * const dc = getPtr (); + MappedDiagnosticContextMap::const_iterator it = dc->find (key); + if (it != dc->end ()) + { + *value = it->second; + return true; + } + else + return false; +} + + +void +MDC::remove (tstring const & key) +{ + MappedDiagnosticContextMap * const dc = getPtr (); + dc->erase (key); +} + + +MappedDiagnosticContextMap const & +MDC::getContext () const +{ + return *getPtr (); +} + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/ndc.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/ndc.cxx new file mode 100644 index 000000000..e17285593 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/ndc.cxx @@ -0,0 +1,304 @@ +// Module: Log4CPLUS +// File: ndc.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// +// Copyright 2001-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/ndc.h> +#include <log4cplus/internal/internal.h> +#include <utility> +#include <algorithm> + + +namespace log4cplus +{ + + + +/////////////////////////////////////////////////////////////////////////////// +// log4cplus::DiagnosticContext ctors +/////////////////////////////////////////////////////////////////////////////// + + +namespace +{ + + +static +void +init_full_message (log4cplus::tstring & fullMessage, + log4cplus::tstring const & message, DiagnosticContext const * parent) +{ + if (parent) + { + fullMessage.reserve (parent->fullMessage.size () + 1 + + message.size ()); + fullMessage = parent->fullMessage; + fullMessage += LOG4CPLUS_TEXT(" "); + fullMessage += message; + } + else + fullMessage = message; +} + + +} // namespace + + +DiagnosticContext::DiagnosticContext(const log4cplus::tstring& message_, + DiagnosticContext const * parent) + : message(message_) + , fullMessage() +{ + init_full_message (fullMessage, message, parent); +} + + +DiagnosticContext::DiagnosticContext(tchar const * message_, + DiagnosticContext const * parent) + : message(message_) + , fullMessage() +{ + init_full_message (fullMessage, message, parent); +} + + +DiagnosticContext::DiagnosticContext(const log4cplus::tstring& message_) + : message(message_) + , fullMessage(message) +{ +} + + +DiagnosticContext::DiagnosticContext(tchar const * message_) + : message(message_) + , fullMessage(message) +{ +} + + +DiagnosticContext::DiagnosticContext (DiagnosticContext const & other) + : message (other.message) + , fullMessage (other.fullMessage) +{ } + + +DiagnosticContext & DiagnosticContext::operator = ( + DiagnosticContext const & other) +{ + DiagnosticContext (other).swap (*this); + return *this; +} + + +#if defined (LOG4CPLUS_HAVE_RVALUE_REFS) +DiagnosticContext::DiagnosticContext (DiagnosticContext && other) + : message (std::move (other.message)) + , fullMessage (std::move (other.fullMessage)) +{ } + + +DiagnosticContext & +DiagnosticContext::operator = (DiagnosticContext && other) +{ + DiagnosticContext (std::move (other)).swap (*this); + return *this; +} + +#endif + + +void +DiagnosticContext::swap (DiagnosticContext & other) +{ + using std::swap; + swap (message, other.message); + swap (fullMessage, other.fullMessage); +} + +/////////////////////////////////////////////////////////////////////////////// +// log4cplus::NDC ctor and dtor +/////////////////////////////////////////////////////////////////////////////// + +NDC::NDC() +{ } + + +NDC::~NDC() +{ } + + + +/////////////////////////////////////////////////////////////////////////////// +// log4cplus::NDC public methods +/////////////////////////////////////////////////////////////////////////////// + +void +NDC::clear() +{ + DiagnosticContextStack* ptr = getPtr(); + DiagnosticContextStack ().swap (*ptr); +} + + +DiagnosticContextStack +NDC::cloneStack() const +{ + DiagnosticContextStack* ptr = getPtr(); + return DiagnosticContextStack(*ptr); +} + + +void +NDC::inherit(const DiagnosticContextStack& stack) +{ + DiagnosticContextStack* ptr = getPtr(); + DiagnosticContextStack (stack).swap (*ptr); +} + + +log4cplus::tstring const & +NDC::get() const +{ + DiagnosticContextStack* ptr = getPtr(); + if(!ptr->empty()) + return ptr->back().fullMessage; + else + return internal::empty_str; +} + + +std::size_t +NDC::getDepth() const +{ + DiagnosticContextStack* ptr = getPtr(); + return ptr->size(); +} + + +log4cplus::tstring +NDC::pop() +{ + DiagnosticContextStack* ptr = getPtr(); + if(!ptr->empty()) + { + tstring message; + message.swap (ptr->back ().message); + ptr->pop_back(); + return message; + } + else + return log4cplus::tstring (); +} + + +void +NDC::pop_void () +{ + DiagnosticContextStack* ptr = getPtr (); + if (! ptr->empty ()) + ptr->pop_back (); +} + + +log4cplus::tstring const & +NDC::peek() const +{ + DiagnosticContextStack* ptr = getPtr(); + if(!ptr->empty()) + return ptr->back().message; + else + return internal::empty_str; +} + + +void +NDC::push(const log4cplus::tstring& message) +{ + push_worker (message); +} + + +void +NDC::push(tchar const * message) +{ + push_worker (message); +} + + +template <typename StringType> +void +NDC::push_worker (StringType const & message) +{ + DiagnosticContextStack* ptr = getPtr(); + if (ptr->empty()) + ptr->push_back( DiagnosticContext(message, NULL) ); + else + { + DiagnosticContext const & dc = ptr->back(); + ptr->push_back( DiagnosticContext(message, &dc) ); + } +} + + +void +NDC::remove() +{ + DiagnosticContextStack* ptr = getPtr(); + DiagnosticContextStack ().swap (*ptr); +} + + +void +NDC::setMaxDepth(std::size_t maxDepth) +{ + DiagnosticContextStack* ptr = getPtr(); + while(maxDepth < ptr->size()) + ptr->pop_back(); +} + + +DiagnosticContextStack* NDC::getPtr() +{ + internal::per_thread_data * ptd = internal::get_ptd (); + return &ptd->ndc_dcs; +} + + +// +// +// + +NDCContextCreator::NDCContextCreator(const log4cplus::tstring& msg) +{ + getNDC().push(msg); +} + + +NDCContextCreator::NDCContextCreator(tchar const * msg) +{ + getNDC().push(msg); +} + + +NDCContextCreator::~NDCContextCreator() +{ + getNDC().pop_void(); +} + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/nteventlogappender.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/nteventlogappender.cxx new file mode 100644 index 000000000..cc2d19a5e --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/nteventlogappender.cxx @@ -0,0 +1,349 @@ +// Module: LOG4CPLUS +// File: nteventlogappender.cxx +// Created: 4/2003 +// Author: Michael CATANZARITI +// +// Copyright 2003-2010 Michael CATANZARITI +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/config.hxx> +#if defined (LOG4CPLUS_HAVE_NT_EVENT_LOG) + +#include <log4cplus/nteventlogappender.h> +#include <log4cplus/loglevel.h> +#include <log4cplus/streams.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/spi/loggingevent.h> +#include <log4cplus/internal/internal.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <sstream> +#include <cstdlib> + + +namespace log4cplus +{ + + +////////////////////////////////////////////////////////////////////////////// +// File LOCAL methods +////////////////////////////////////////////////////////////////////////////// + +namespace { + + static + bool + copySID(SID** ppDstSid, SID* pSrcSid) + { + DWORD dwLength = ::GetLengthSid(pSrcSid); + + SID * pDstSid = (SID *) std::calloc (1, dwLength); + if (! pDstSid) + return false; + + if (CopySid(dwLength, pDstSid, pSrcSid)) + { + *ppDstSid = pDstSid; + return true; + } + else + { + std::free (pDstSid); + return false; + } + } + + + static + bool + GetCurrentUserSID(SID** ppSid) + { + bool bSuccess = false; + TOKEN_USER * ptu = 0; + DWORD tusize = 0; + HANDLE hProcess = ::GetCurrentProcess(); + HANDLE hToken = 0; + + if (! ::OpenProcessToken(hProcess, TOKEN_QUERY, &hToken)) + goto finish; + + // Get the required size + if (! GetTokenInformation(hToken, TokenUser, NULL, 0, &tusize)) + goto finish; + + ptu = (TOKEN_USER*) std::calloc (1, tusize); + if (! ptu) + goto finish; + + if (GetTokenInformation(hToken, TokenUser, (LPVOID)ptu, tusize, &tusize)) + bSuccess = copySID (ppSid, (SID *)ptu->User.Sid); + + finish:; + if (hToken) + CloseHandle (hToken); + + std::free (ptu); + + return bSuccess; + } + + + static + HKEY + regGetKey(const tstring& subkey, DWORD* disposition) + { + HKEY hkey = 0; + RegCreateKeyEx(HKEY_LOCAL_MACHINE, + subkey.c_str(), + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_SET_VALUE, + NULL, + &hkey, + disposition); + return hkey; + } + + + static + void + regSetString(HKEY hkey, const tstring& name, const tstring& value) + { + RegSetValueEx(hkey, + name.c_str(), + 0, + REG_SZ, + reinterpret_cast<BYTE const *>(value.c_str()), + static_cast<DWORD>(value.length() * sizeof(tchar))); + } + + + static + void + regSetDword(HKEY hkey, const tstring& name, DWORD value) + { + RegSetValueEx(hkey, + name.c_str(), + 0, + REG_DWORD, + reinterpret_cast<LPBYTE>(&value), + sizeof(DWORD)); + } + +} + + + +////////////////////////////////////////////////////////////////////////////// +// NTEventLogAppender ctor and dtor +////////////////////////////////////////////////////////////////////////////// + +NTEventLogAppender::NTEventLogAppender(const tstring& server, + const tstring& log, + const tstring& source) +: server(server), + log(log), + source(source), + hEventLog(NULL), + pCurrentUserSID(NULL) +{ + init(); +} + + + +NTEventLogAppender::NTEventLogAppender(const helpers::Properties & properties) +: Appender(properties), + hEventLog(NULL), + pCurrentUserSID(NULL) +{ + server = properties.getProperty( LOG4CPLUS_TEXT("server") ); + log = properties.getProperty( LOG4CPLUS_TEXT("log") ); + source = properties.getProperty( LOG4CPLUS_TEXT("source") ); + + init(); +} + + + +void +NTEventLogAppender::init() +{ + if(source.empty()) { + helpers::getLogLog().warn( + LOG4CPLUS_TEXT("Source option not set for appender [") + + name + + LOG4CPLUS_TEXT("].")); + return; + } + + if(log.empty ()) { + log = LOG4CPLUS_TEXT("Application"); + } + + // current user security identifier + GetCurrentUserSID(&pCurrentUserSID); + + addRegistryInfo(); + + hEventLog = ::RegisterEventSource(server.empty () ? 0 : server.c_str(), + source.c_str()); + if (! hEventLog || hEventLog == HANDLE(ERROR_INVALID_HANDLE)) + helpers::getLogLog().warn ( + LOG4CPLUS_TEXT("Event source registration failed.")); +} + + + +NTEventLogAppender::~NTEventLogAppender() +{ + destructorImpl(); + + if(pCurrentUserSID != NULL) { + std::free (pCurrentUserSID); + pCurrentUserSID = NULL; + } +} + + + +////////////////////////////////////////////////////////////////////////////// +// NTEventLogAppender public methods +////////////////////////////////////////////////////////////////////////////// + +void +NTEventLogAppender::close() +{ + if(hEventLog != NULL) { + ::DeregisterEventSource(hEventLog); + hEventLog = NULL; + } + closed = true; +} + + + +////////////////////////////////////////////////////////////////////////////// +// NTEventLogAppender protected methods +////////////////////////////////////////////////////////////////////////////// + +void +NTEventLogAppender::append(const spi::InternalLoggingEvent& event) +{ + if(hEventLog == NULL) { + helpers::getLogLog().warn(LOG4CPLUS_TEXT("NT EventLog not opened.")); + return; + } + + tstring & str = formatEvent (event); + + // From MSDN documentation for ReportEvent(): + // Each string is limited to 31,839 characters. + if (str.size () > 31839) + str.resize (31839); + + const tchar * s = str.c_str (); + BOOL bSuccess = ::ReportEvent(hEventLog, + getEventType(event), + getEventCategory(event), + 0x1000, + pCurrentUserSID, + 1, + 0, + &s, + NULL); + + if(!bSuccess) { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("Cannot report event in NT EventLog.")); + } +} + + + + +WORD +NTEventLogAppender::getEventType(const spi::InternalLoggingEvent& event) +{ + WORD ret_val; + LogLevel const ll = event.getLogLevel(); + + if (ll >= ERROR_LOG_LEVEL) // or FATAL_LOG_LEVEL + ret_val = EVENTLOG_ERROR_TYPE; + else if (ll >= WARN_LOG_LEVEL) + ret_val = EVENTLOG_WARNING_TYPE; + else // INFO_LOG_LEVEL or DEBUG_LOG_LEVEL or TRACE_LOG_LEVEL + ret_val = EVENTLOG_INFORMATION_TYPE; + + return ret_val; +} + + + +WORD +NTEventLogAppender::getEventCategory(const spi::InternalLoggingEvent& event) +{ + WORD ret_val; + LogLevel const ll = event.getLogLevel(); + + if (ll >= FATAL_LOG_LEVEL) + ret_val = 1; + else if (ll >= ERROR_LOG_LEVEL) + ret_val = 2; + else if (ll >= WARN_LOG_LEVEL) + ret_val = 3; + else if (ll >= INFO_LOG_LEVEL) + ret_val = 4; + else if (ll >= DEBUG_LOG_LEVEL) + ret_val = 5; + else // TRACE_LOG_LEVEL + ret_val = 6; + + return ret_val; +} + + +// Add this source with appropriate configuration keys to the registry. +void +NTEventLogAppender::addRegistryInfo() +{ + DWORD disposition; + HKEY hkey = 0; + tstring subkey = LOG4CPLUS_TEXT("SYSTEM\\CurrentControlSet\\Services\\EventLog\\") + + log + + LOG4CPLUS_TEXT("\\") + + source; + + hkey = regGetKey(subkey, &disposition); + if(disposition == REG_CREATED_NEW_KEY) { + regSetString(hkey, + LOG4CPLUS_TEXT("EventMessageFile"), + LOG4CPLUS_TEXT("NTEventLogAppender.dll")); + regSetString(hkey, + LOG4CPLUS_TEXT("CategoryMessageFile"), + LOG4CPLUS_TEXT("NTEventLogAppender.dll")); + regSetDword(hkey, LOG4CPLUS_TEXT("TypesSupported"), (DWORD)7); + regSetDword(hkey, LOG4CPLUS_TEXT("CategoryCount"), (DWORD)5); + } + + RegCloseKey(hkey); + return; +} + + +} // namespace log4cplus + + +#endif // LOG4CPLUS_HAVE_NT_EVENT_LOG diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/nullappender.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/nullappender.cxx new file mode 100644 index 000000000..67111934c --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/nullappender.cxx @@ -0,0 +1,75 @@ +// Module: Log4CPLUS +// File: nullappender.cxx +// Created: 6/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/nullappender.h> +#include <log4cplus/thread/syncprims-pub-impl.h> + + +namespace log4cplus +{ + + +/////////////////////////////////////////////////////////////////////////////// +// NullAppender ctors and dtor +/////////////////////////////////////////////////////////////////////////////// + +NullAppender::NullAppender() +{ +} + + +NullAppender::NullAppender(const helpers::Properties& properties) +: Appender(properties) +{ +} + + + +NullAppender::~NullAppender() +{ + destructorImpl(); +} + + + +/////////////////////////////////////////////////////////////////////////////// +// NullAppender public methods +/////////////////////////////////////////////////////////////////////////////// + +void +NullAppender::close() +{ +} + + + +/////////////////////////////////////////////////////////////////////////////// +// NullAppender protected methods +/////////////////////////////////////////////////////////////////////////////// + +// This method does not need to be locked since it is called by +// doAppend() which performs the locking +void +NullAppender::append(const spi::InternalLoggingEvent&) +{ +} + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/objectregistry.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/objectregistry.cxx new file mode 100644 index 000000000..edc6c9889 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/objectregistry.cxx @@ -0,0 +1,117 @@ +// Module: Log4CPLUS +// File: objectregistry.cxx +// Created: 3/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/spi/objectregistry.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <log4cplus/thread/threads.h> + + +namespace log4cplus { namespace spi { + + +/////////////////////////////////////////////////////////////////////////////// +// ObjectRegistryBase ctor and dtor +/////////////////////////////////////////////////////////////////////////////// + +ObjectRegistryBase::ObjectRegistryBase() +{ } + + +ObjectRegistryBase::~ObjectRegistryBase() +{ } + + + +/////////////////////////////////////////////////////////////////////////////// +// ObjectRegistryBase public methods +/////////////////////////////////////////////////////////////////////////////// + +bool +ObjectRegistryBase::exists(const tstring& name) const +{ + thread::MutexGuard guard (mutex); + + return data.find(name) != data.end(); +} + + +std::vector<tstring> +ObjectRegistryBase::getAllNames() const +{ + std::vector<tstring> tmp; + + { + thread::MutexGuard guard (mutex); + for(ObjectMap::const_iterator it=data.begin(); it!=data.end(); ++it) + tmp.push_back( (*it).first ); + } + + return tmp; +} + + + +/////////////////////////////////////////////////////////////////////////////// +// ObjectRegistryBase protected methods +/////////////////////////////////////////////////////////////////////////////// + +bool +ObjectRegistryBase::putVal(const tstring& name, void* object) +{ + ObjectMap::value_type value(name, object); + std::pair<ObjectMap::iterator, bool> ret; + + { + thread::MutexGuard guard (mutex); + ret = data.insert(value); + } + + if (! ret.second) + deleteObject( value.second ); + return ret.second; +} + + +void* +ObjectRegistryBase::getVal(const tstring& name) const +{ + thread::MutexGuard guard (mutex); + + ObjectMap::const_iterator it (data.find (name)); + if (it != data.end ()) + return it->second; + else + return 0; +} + + + + +void +ObjectRegistryBase::clear() +{ + thread::MutexGuard guard (mutex); + + for(ObjectMap::iterator it=data.begin(); it!=data.end(); ++it) + deleteObject( it->second ); +} + + +} } // namespace log4cplus { namespace spi { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/patternlayout.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/patternlayout.cxx new file mode 100644 index 000000000..2771d081f --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/patternlayout.cxx @@ -0,0 +1,1046 @@ +// Module: Log4CPLUS +// File: patternlayout.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// +// Copyright 2001-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/layout.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/timehelper.h> +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/helpers/socket.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/spi/loggingevent.h> +#include <log4cplus/internal/internal.h> +#include <log4cplus/internal/env.h> +#include <cstdlib> + + +namespace +{ + + +static +log4cplus::tstring +get_basename (const log4cplus::tstring& filename) +{ +#if defined(_WIN32) + log4cplus::tchar const dir_sep(LOG4CPLUS_TEXT('\\')); +#else + log4cplus::tchar const dir_sep(LOG4CPLUS_TEXT('/')); +#endif + + log4cplus::tstring::size_type pos = filename.rfind(dir_sep); + if (pos != log4cplus::tstring::npos) + return filename.substr(pos+1); + else + return filename; +} + + +} // namespace + + +namespace log4cplus +{ + +static tchar const ESCAPE_CHAR = LOG4CPLUS_TEXT('%'); + +extern void formatRelativeTimestamp (log4cplus::tostream & output, + log4cplus::spi::InternalLoggingEvent const & event); + + +namespace pattern +{ + + +/** + * This is used by PatternConverter class to inform them how to format + * their output. + */ +struct FormattingInfo { + int minLen; + std::size_t maxLen; + bool leftAlign; + FormattingInfo() { reset(); } + + void reset(); + void dump(helpers::LogLog&); +}; + + + +/** + * This is the base class of all "Converter" classes that format a + * field of InternalLoggingEvent objects. In fact, the PatternLayout + * class simply uses an array of PatternConverter objects to format + * and append a logging event. + */ +class PatternConverter +{ +public: + explicit PatternConverter(const FormattingInfo& info); + virtual ~PatternConverter() {} + void formatAndAppend(tostream& output, + const spi::InternalLoggingEvent& event); + + virtual void convert(tstring & result, + const spi::InternalLoggingEvent& event) = 0; + +private: + int minLen; + std::size_t maxLen; + bool leftAlign; +}; + + +typedef std::vector<pattern::PatternConverter*> PatternConverterList; + + +/** + * This PatternConverter returns a constant string. + */ +class LiteralPatternConverter : public PatternConverter +{ +public: + LiteralPatternConverter(const tstring& str); + virtual void convert(tstring & result, + const spi::InternalLoggingEvent&) + { + result = str; + } + +private: + tstring str; +}; + + +/** + * This PatternConverter is used to format most of the "simple" fields + * found in the InternalLoggingEvent object. + */ +class BasicPatternConverter + : public PatternConverter +{ +public: + enum Type { THREAD_CONVERTER, + THREAD2_CONVERTER, + PROCESS_CONVERTER, + LOGLEVEL_CONVERTER, + NDC_CONVERTER, + MESSAGE_CONVERTER, + NEWLINE_CONVERTER, + BASENAME_CONVERTER, + FILE_CONVERTER, + LINE_CONVERTER, + FULL_LOCATION_CONVERTER, + FUNCTION_CONVERTER }; + BasicPatternConverter(const FormattingInfo& info, Type type); + virtual void convert(tstring & result, + const spi::InternalLoggingEvent& event); + +private: + // Disable copy + BasicPatternConverter(const BasicPatternConverter&); + BasicPatternConverter& operator=(BasicPatternConverter&); + + LogLevelManager& llmCache; + Type type; +}; + + + +/** + * This PatternConverter is used to format the Logger field found in + * the InternalLoggingEvent object. + */ +class LoggerPatternConverter : public PatternConverter { +public: + LoggerPatternConverter(const FormattingInfo& info, int precision); + virtual void convert(tstring & result, + const spi::InternalLoggingEvent& event); + +private: + int precision; +}; + + + +/** + * This PatternConverter is used to format the timestamp field found in + * the InternalLoggingEvent object. It will be formatted according to + * the specified "pattern". + */ +class DatePatternConverter : public PatternConverter { +public: + DatePatternConverter(const FormattingInfo& info, + const tstring& pattern, + bool use_gmtime); + virtual void convert(tstring & result, + const spi::InternalLoggingEvent& event); + +private: + bool use_gmtime; + tstring format; +}; + + +//! This pattern is used to format miliseconds since process start. +class RelativeTimestampConverter: public PatternConverter { +public: + RelativeTimestampConverter(const FormattingInfo& info); + virtual void convert(tstring & result, + const spi::InternalLoggingEvent& event); +}; + + +/** + * This PatternConverter is used to format the hostname field. + */ +class HostnamePatternConverter : public PatternConverter { +public: + HostnamePatternConverter(const FormattingInfo& info, bool fqdn); + virtual void convert(tstring & result, + const spi::InternalLoggingEvent& event); + +private: + tstring hostname_; +}; + + +/** + * This PatternConverter is used to format the MDC field found in + * the InternalLoggingEvent object, optionally limited to + * \c k Mapped diagnostic context key. + */ +class MDCPatternConverter + : public PatternConverter +{ +public: + MDCPatternConverter(const FormattingInfo& info, tstring const & k); + virtual void convert(tstring & result, + const spi::InternalLoggingEvent& event); + +private: + tstring key; +}; + + +/** + * This PatternConverter is used to format the NDC field found in + * the InternalLoggingEvent object, optionally limited to + * \c precision levels (using space to separate levels). + */ +class NDCPatternConverter : public PatternConverter { +public: + NDCPatternConverter(const FormattingInfo& info, int precision); + virtual void convert(tstring & result, + const spi::InternalLoggingEvent& event); + +private: + int precision; +}; + + + +/** + * This class parses a "pattern" string into an array of + * PatternConverter objects. + * <p> + * @see PatternLayout for the formatting of the "pattern" string. + */ +class PatternParser +{ +public: + PatternParser(const tstring& pattern, unsigned ndcMaxDepth); + std::vector<PatternConverter*> parse(); + +private: + // Types + enum ParserState { LITERAL_STATE, + CONVERTER_STATE, + DOT_STATE, + MIN_STATE, + MAX_STATE }; + + // Methods + tstring extractOption(); + int extractPrecisionOption(); + void finalizeConverter(tchar c); + + // Data + tstring pattern; + FormattingInfo formattingInfo; + std::vector<PatternConverter*> list; + ParserState state; + tstring::size_type pos; + tstring currentLiteral; + unsigned ndcMaxDepth; +}; + + +//////////////////////////////////////////////// +// FormattingInfo methods: +//////////////////////////////////////////////// + +void +FormattingInfo::reset() { + minLen = -1; + maxLen = 0x7FFFFFFF; + leftAlign = false; +} + + +void +FormattingInfo::dump(helpers::LogLog& loglog) { + tostringstream buf; + buf << LOG4CPLUS_TEXT("min=") << minLen + << LOG4CPLUS_TEXT(", max=") << maxLen + << LOG4CPLUS_TEXT(", leftAlign=") << std::boolalpha << leftAlign; + loglog.debug(buf.str()); +} + + + + +//////////////////////////////////////////////// +// PatternConverter methods: +//////////////////////////////////////////////// + +PatternConverter::PatternConverter(const FormattingInfo& i) +{ + minLen = i.minLen; + maxLen = i.maxLen; + leftAlign = i.leftAlign; +} + + + +void +PatternConverter::formatAndAppend( + tostream& output, const spi::InternalLoggingEvent& event) +{ + tstring & s = internal::get_ptd ()->faa_str; + convert (s, event); + std::size_t len = s.length(); + + if (len > maxLen) + output << s.substr(len - maxLen); + else if (static_cast<int>(len) < minLen) + { + std::ios_base::fmtflags const original_flags = output.flags (); + tchar const fill = output.fill (LOG4CPLUS_TEXT(' ')); + output.setf (leftAlign ? std::ios_base::left : std::ios_base::right, + std::ios_base::adjustfield); + output.width (minLen); + output << s; + output.fill (fill); + output.flags (original_flags); + } + else + output << s; +} + + + +//////////////////////////////////////////////// +// LiteralPatternConverter methods: +//////////////////////////////////////////////// + +LiteralPatternConverter::LiteralPatternConverter( + const tstring& str_) + : PatternConverter(FormattingInfo()) + , str(str_) +{ +} + + + +//////////////////////////////////////////////// +// BasicPatternConverter methods: +//////////////////////////////////////////////// + +BasicPatternConverter::BasicPatternConverter( + const FormattingInfo& info, Type type_) + : PatternConverter(info) + , llmCache(getLogLevelManager()) + , type(type_) +{ +} + + + +void +BasicPatternConverter::convert(tstring & result, + const spi::InternalLoggingEvent& event) +{ + switch(type) + { + case LOGLEVEL_CONVERTER: + result = llmCache.toString(event.getLogLevel()); + return; + + case BASENAME_CONVERTER: + result = get_basename(event.getFile()); + return; + + case PROCESS_CONVERTER: + helpers::convertIntegerToString(result, internal::get_process_id ()); + return; + + case NDC_CONVERTER: + result = event.getNDC(); + return; + + case MESSAGE_CONVERTER: + result = event.getMessage(); + return; + + case NEWLINE_CONVERTER: + result = LOG4CPLUS_TEXT("\n"); + return; + + case FILE_CONVERTER: + result = event.getFile(); + return; + + case THREAD_CONVERTER: + result = event.getThread(); + return; + + case THREAD2_CONVERTER: + result = event.getThread2(); + return; + + case LINE_CONVERTER: + { + if(event.getLine() != -1) + helpers::convertIntegerToString(result, event.getLine()); + else + result.clear (); + return; + } + + case FULL_LOCATION_CONVERTER: + { + tstring const & file = event.getFile(); + if (! file.empty ()) + { + result = file; + result += LOG4CPLUS_TEXT(":"); + result += helpers::convertIntegerToString(event.getLine()); + } + else + result = LOG4CPLUS_TEXT(":"); + return; + } + + case FUNCTION_CONVERTER: + result = event.getFunction (); + return; + } + + result = LOG4CPLUS_TEXT("INTERNAL LOG4CPLUS ERROR"); +} + + + +//////////////////////////////////////////////// +// LoggerPatternConverter methods: +//////////////////////////////////////////////// + +LoggerPatternConverter::LoggerPatternConverter( + const FormattingInfo& info, int prec) + : PatternConverter(info) + , precision(prec) +{ +} + + + +void +LoggerPatternConverter::convert(tstring & result, + const spi::InternalLoggingEvent& event) +{ + const tstring& name = event.getLoggerName(); + if (precision <= 0) { + result = name; + } + else { + std::size_t len = name.length(); + + // We substract 1 from 'len' when assigning to 'end' to avoid out of + // bounds exception in return r.substring(end+1, len). This can happen + // if precision is 1 and the logger name ends with a dot. + tstring::size_type end = len - 1; + for (int i = precision; i > 0; --i) + { + end = name.rfind(LOG4CPLUS_TEXT('.'), end - 1); + if(end == tstring::npos) { + result = name; + return; + } + } + result = name.substr(end + 1); + } +} + + + +//////////////////////////////////////////////// +// DatePatternConverter methods: +//////////////////////////////////////////////// + + +DatePatternConverter::DatePatternConverter( + const FormattingInfo& info, const tstring& pattern, + bool use_gmtime_) + : PatternConverter(info) + , use_gmtime(use_gmtime_) + , format(pattern) +{ +} + + + +void +DatePatternConverter::convert(tstring & result, + const spi::InternalLoggingEvent& event) +{ + result = event.getTimestamp().getFormattedTime(format, use_gmtime); +} + + +// +// +// + +RelativeTimestampConverter::RelativeTimestampConverter (FormattingInfo const & info) + : PatternConverter (info) +{ } + + +void +RelativeTimestampConverter::convert (tstring & result, + spi::InternalLoggingEvent const & event) +{ + tostringstream & oss = internal::get_ptd ()->layout_oss; + detail::clear_tostringstream (oss); + formatRelativeTimestamp (oss, event); + oss.str ().swap (result); +} + + +//////////////////////////////////////////////// +// HostnamePatternConverter methods: +//////////////////////////////////////////////// + +HostnamePatternConverter::HostnamePatternConverter ( + const FormattingInfo& info, bool fqdn) + : PatternConverter(info) + , hostname_ (helpers::getHostname (fqdn)) +{ } + + +void +HostnamePatternConverter::convert ( + tstring & result, const spi::InternalLoggingEvent&) +{ + result = hostname_; +} + + + +//////////////////////////////////////////////// +// MDCPatternConverter methods: +//////////////////////////////////////////////// + +log4cplus::pattern::MDCPatternConverter::MDCPatternConverter ( + const FormattingInfo& info, tstring const & k) + : PatternConverter(info) + , key (k) +{ } + + +void +log4cplus::pattern::MDCPatternConverter::convert (tstring & result, + const spi::InternalLoggingEvent& event) +{ + result = event.getMDC (key); +} + + +//////////////////////////////////////////////// +// NDCPatternConverter methods: +//////////////////////////////////////////////// + +log4cplus::pattern::NDCPatternConverter::NDCPatternConverter ( + const FormattingInfo& info, int precision_) + : PatternConverter(info) + , precision(precision_) +{ } + + +void +log4cplus::pattern::NDCPatternConverter::convert (tstring & result, + const spi::InternalLoggingEvent& event) +{ + const log4cplus::tstring& text = event.getNDC(); + if (precision <= 0) + result = text; + else + { + tstring::size_type p = text.find(LOG4CPLUS_TEXT(' ')); + for (int i = 1; i < precision && p != tstring::npos; ++i) + p = text.find(LOG4CPLUS_TEXT(' '), p + 1); + + result = text.substr(0, p); + } +} + + + +//////////////////////////////////////////////// +// PatternParser methods: +//////////////////////////////////////////////// + +PatternParser::PatternParser( + const tstring& pattern_, unsigned ndcMaxDepth_) + : pattern(pattern_) + , state(LITERAL_STATE) + , pos(0) + , ndcMaxDepth (ndcMaxDepth_) +{ +} + + + +tstring +PatternParser::extractOption() +{ + if ( (pos < pattern.length()) + && (pattern[pos] == LOG4CPLUS_TEXT('{'))) + { + tstring::size_type end = pattern.find_first_of(LOG4CPLUS_TEXT('}'), pos); + if (end != tstring::npos) { + tstring r = pattern.substr(pos + 1, end - pos - 1); + pos = end + 1; + return r; + } + else { + log4cplus::tostringstream buf; + buf << LOG4CPLUS_TEXT("No matching '}' found in conversion pattern string \"") + << pattern + << LOG4CPLUS_TEXT("\""); + helpers::getLogLog().error(buf.str()); + pos = pattern.length(); + } + } + + return LOG4CPLUS_TEXT(""); +} + + +int +PatternParser::extractPrecisionOption() +{ + tstring opt = extractOption(); + int r = 0; + if (! opt.empty ()) + r = std::atoi(LOG4CPLUS_TSTRING_TO_STRING(opt).c_str()); + + return r; +} + + + +PatternConverterList +PatternParser::parse() +{ + tchar c; + pos = 0; + while(pos < pattern.length()) { + c = pattern[pos++]; + switch (state) { + case LITERAL_STATE : + // In literal state, the last char is always a literal. + if(pos == pattern.length()) { + currentLiteral += c; + continue; + } + if(c == ESCAPE_CHAR) { + // peek at the next char. + switch (pattern[pos]) { + case ESCAPE_CHAR: + currentLiteral += c; + pos++; // move pointer + break; + default: + if(! currentLiteral.empty ()) { + list.push_back + (new LiteralPatternConverter(currentLiteral)); + //getLogLog().debug("Parsed LITERAL converter: \"" + // +currentLiteral+"\"."); + } + currentLiteral.resize(0); + currentLiteral += c; // append % + state = CONVERTER_STATE; + formattingInfo.reset(); + } + } + else { + currentLiteral += c; + } + break; + + case CONVERTER_STATE: + currentLiteral += c; + switch (c) { + case LOG4CPLUS_TEXT('-'): + formattingInfo.leftAlign = true; + break; + case LOG4CPLUS_TEXT('.'): + state = DOT_STATE; + break; + default: + if(c >= LOG4CPLUS_TEXT('0') && c <= LOG4CPLUS_TEXT('9')) { + formattingInfo.minLen = c - LOG4CPLUS_TEXT('0'); + state = MIN_STATE; + } + else { + finalizeConverter(c); + } + } // switch + break; + + case MIN_STATE: + currentLiteral += c; + if (c >= LOG4CPLUS_TEXT('0') && c <= LOG4CPLUS_TEXT('9')) { + formattingInfo.minLen = formattingInfo.minLen * 10 + (c - LOG4CPLUS_TEXT('0')); + } + else if(c == LOG4CPLUS_TEXT('.')) { + state = DOT_STATE; + } + else { + finalizeConverter(c); + } + break; + + case DOT_STATE: + currentLiteral += c; + if(c >= LOG4CPLUS_TEXT('0') && c <= LOG4CPLUS_TEXT('9')) { + formattingInfo.maxLen = c - LOG4CPLUS_TEXT('0'); + state = MAX_STATE; + } + else { + tostringstream buf; + buf << LOG4CPLUS_TEXT("Error occured in position ") + << pos + << LOG4CPLUS_TEXT(".\n Was expecting digit, instead got char \"") + << c + << LOG4CPLUS_TEXT("\"."); + helpers::getLogLog().error(buf.str()); + state = LITERAL_STATE; + } + break; + + case MAX_STATE: + currentLiteral += c; + if (c >= LOG4CPLUS_TEXT('0') && c <= LOG4CPLUS_TEXT('9')) + formattingInfo.maxLen = formattingInfo.maxLen * 10 + (c - LOG4CPLUS_TEXT('0')); + else { + finalizeConverter(c); + state = LITERAL_STATE; + } + break; + } // end switch + } // end while + + if(! currentLiteral.empty ()) { + list.push_back(new LiteralPatternConverter(currentLiteral)); + //getLogLog().debug("Parsed LITERAL converter: \""+currentLiteral+"\"."); + } + + return list; +} + + + +void +PatternParser::finalizeConverter(tchar c) +{ + PatternConverter* pc = 0; + switch (c) { + case LOG4CPLUS_TEXT('b'): + pc = new BasicPatternConverter + (formattingInfo, + BasicPatternConverter::BASENAME_CONVERTER); + //getLogLog().debug("BASENAME converter."); + //formattingInfo.dump(getLogLog()); + break; + + case LOG4CPLUS_TEXT('c'): + pc = new LoggerPatternConverter(formattingInfo, + extractPrecisionOption()); + //getLogLog().debug( LOG4CPLUS_TEXT("LOGGER converter.") ); + //formattingInfo.dump(getLogLog()); + break; + + case LOG4CPLUS_TEXT('d'): + case LOG4CPLUS_TEXT('D'): + { + tstring dOpt = extractOption(); + if(dOpt.empty ()) { + dOpt = LOG4CPLUS_TEXT("%Y-%m-%d %H:%M:%S"); + } + bool use_gmtime = c == LOG4CPLUS_TEXT('d'); + pc = new DatePatternConverter(formattingInfo, dOpt, use_gmtime); + //if(use_gmtime) { + // getLogLog().debug("GMT DATE converter."); + //} + //else { + // getLogLog().debug("LOCAL DATE converter."); + //} + //formattingInfo.dump(getLogLog()); + } + break; + + case LOG4CPLUS_TEXT('F'): + pc = new BasicPatternConverter + (formattingInfo, + BasicPatternConverter::FILE_CONVERTER); + //getLogLog().debug("FILE NAME converter."); + //formattingInfo.dump(getLogLog()); + break; + + case LOG4CPLUS_TEXT('h'): + case LOG4CPLUS_TEXT('H'): + { + bool fqdn = (c == LOG4CPLUS_TEXT('H')); + pc = new HostnamePatternConverter(formattingInfo, fqdn); + // getLogLog().debug( LOG4CPLUS_TEXT("HOSTNAME converter.") ); + // formattingInfo.dump(getLogLog()); + } + break; + + case LOG4CPLUS_TEXT('i'): + pc = new BasicPatternConverter + (formattingInfo, + BasicPatternConverter::PROCESS_CONVERTER); + //getLogLog().debug("PROCESS_CONVERTER converter."); + //formattingInfo.dump(getLogLog()); + break; + + case LOG4CPLUS_TEXT('l'): + pc = new BasicPatternConverter + (formattingInfo, + BasicPatternConverter::FULL_LOCATION_CONVERTER); + //getLogLog().debug("FULL LOCATION converter."); + //formattingInfo.dump(getLogLog()); + break; + + case LOG4CPLUS_TEXT('L'): + pc = new BasicPatternConverter + (formattingInfo, + BasicPatternConverter::LINE_CONVERTER); + //getLogLog().debug("LINE NUMBER converter."); + //formattingInfo.dump(getLogLog()); + break; + + case LOG4CPLUS_TEXT('m'): + pc = new BasicPatternConverter + (formattingInfo, + BasicPatternConverter::MESSAGE_CONVERTER); + //getLogLog().debug("MESSAGE converter."); + //formattingInfo.dump(getLogLog()); + break; + + case LOG4CPLUS_TEXT('M'): + pc = new BasicPatternConverter ( + formattingInfo, BasicPatternConverter::FUNCTION_CONVERTER); + //getLogLog().debug("METHOD (function name) converter."); + //formattingInfo.dump(getLogLog()); + break; + + case LOG4CPLUS_TEXT('n'): + pc = new BasicPatternConverter + (formattingInfo, + BasicPatternConverter::NEWLINE_CONVERTER); + //getLogLog().debug("MESSAGE converter."); + //formattingInfo.dump(getLogLog()); + break; + + case LOG4CPLUS_TEXT('p'): + pc = new BasicPatternConverter + (formattingInfo, + BasicPatternConverter::LOGLEVEL_CONVERTER); + //getLogLog().debug("LOGLEVEL converter."); + //formattingInfo.dump(getLogLog()); + break; + + case LOG4CPLUS_TEXT('r'): + pc = new RelativeTimestampConverter (formattingInfo); + //getLogLog().debug("RELATIVE converter."); + //formattingInfo.dump(getLogLog()); + break; + + case LOG4CPLUS_TEXT('t'): + pc = new BasicPatternConverter + (formattingInfo, + BasicPatternConverter::THREAD_CONVERTER); + //getLogLog().debug("THREAD converter."); + //formattingInfo.dump(getLogLog()); + break; + + case LOG4CPLUS_TEXT('T'): + pc = new BasicPatternConverter + (formattingInfo, + BasicPatternConverter::THREAD2_CONVERTER); + //getLogLog().debug("THREAD2 converter."); + //formattingInfo.dump(getLogLog()); + break; + + case LOG4CPLUS_TEXT('x'): + pc = new NDCPatternConverter (formattingInfo, ndcMaxDepth); + //getLogLog().debug("NDC converter."); + break; + + case LOG4CPLUS_TEXT('X'): + pc = new MDCPatternConverter (formattingInfo, extractOption ()); + //getLogLog().debug("MDC converter."); + break; + + default: + tostringstream buf; + buf << LOG4CPLUS_TEXT("Unexpected char [") + << c + << LOG4CPLUS_TEXT("] at position ") + << pos + << LOG4CPLUS_TEXT(" in conversion patterrn."); + helpers::getLogLog().error(buf.str()); + pc = new LiteralPatternConverter(currentLiteral); + } + + list.push_back(pc); + currentLiteral.resize(0); + state = LITERAL_STATE; + formattingInfo.reset(); +} + + +} // namespace pattern + + +typedef pattern::PatternConverterList PatternConverterList; + + +//////////////////////////////////////////////// +// PatternLayout methods: +//////////////////////////////////////////////// + +PatternLayout::PatternLayout(const tstring& pattern_) +{ + init(pattern_, 0); +} + + +PatternLayout::PatternLayout(const helpers::Properties& properties) +{ + unsigned ndcMaxDepth = 0; + properties.getUInt (ndcMaxDepth, LOG4CPLUS_TEXT ("NDCMaxDepth")); + + bool hasPattern = properties.exists( LOG4CPLUS_TEXT("Pattern") ); + bool hasConversionPattern = properties.exists( LOG4CPLUS_TEXT("ConversionPattern") ); + + if(hasPattern) { + helpers::getLogLog().warn( + LOG4CPLUS_TEXT("PatternLayout- the \"Pattern\" property has been") + LOG4CPLUS_TEXT(" deprecated. Use \"ConversionPattern\" instead.")); + } + + if(hasConversionPattern) { + init(properties.getProperty( LOG4CPLUS_TEXT("ConversionPattern") ), + ndcMaxDepth); + } + else if(hasPattern) { + init(properties.getProperty( LOG4CPLUS_TEXT("Pattern") ), ndcMaxDepth); + } + else { + helpers::getLogLog().error( + LOG4CPLUS_TEXT ("ConversionPattern not specified in properties"), + true); + } + +} + + +void +PatternLayout::init(const tstring& pattern_, unsigned ndcMaxDepth) +{ + pattern = pattern_; + parsedPattern = pattern::PatternParser(pattern, ndcMaxDepth).parse(); + + // Let's validate that our parser didn't give us any NULLs. If it did, + // we will convert them to a valid PatternConverter that does nothing so + // at least we don't core. + for(PatternConverterList::iterator it=parsedPattern.begin(); + it!=parsedPattern.end(); + ++it) + { + if( (*it) == 0 ) { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("Parsed Pattern created a NULL PatternConverter")); + (*it) = new pattern::LiteralPatternConverter( LOG4CPLUS_TEXT("") ); + } + } + if(parsedPattern.empty ()) { + helpers::getLogLog().warn( + LOG4CPLUS_TEXT("PatternLayout pattern is empty. Using default...")); + parsedPattern.push_back ( + new pattern::BasicPatternConverter(pattern::FormattingInfo(), + pattern::BasicPatternConverter::MESSAGE_CONVERTER)); + } +} + + + +PatternLayout::~PatternLayout() +{ + for(PatternConverterList::iterator it=parsedPattern.begin(); + it!=parsedPattern.end(); + ++it) + { + delete (*it); + } +} + + + +void +PatternLayout::formatAndAppend(tostream& output, + const spi::InternalLoggingEvent& event) +{ + for(PatternConverterList::iterator it=parsedPattern.begin(); + it!=parsedPattern.end(); + ++it) + { + (*it)->formatAndAppend(output, event); + } +} + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/pointer.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/pointer.cxx new file mode 100644 index 000000000..a800a8591 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/pointer.cxx @@ -0,0 +1,113 @@ +// Module: Log4CPLUS +// File: pointer.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// +// Copyright 2001-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/streams.h> +#include <log4cplus/helpers/pointer.h> +#include <log4cplus/thread/threads.h> +#include <log4cplus/thread/impl/syncprims-impl.h> +#include <log4cplus/config/windowsh-inc.h> +#include <cassert> +#if defined (LOG4CPLUS_HAVE_INTRIN_H) +#include <intrin.h> +#endif + + +namespace log4cplus { namespace helpers { + + +/////////////////////////////////////////////////////////////////////////////// +// log4cplus::helpers::SharedObject dtor +/////////////////////////////////////////////////////////////////////////////// + +SharedObject::~SharedObject() +{ + assert(count == 0); +} + + + +/////////////////////////////////////////////////////////////////////////////// +// log4cplus::helpers::SharedObject public methods +/////////////////////////////////////////////////////////////////////////////// + +void +SharedObject::addReference() const +{ +#if defined (LOG4CPLUS_SINGLE_THREADED) + ++count; + +#elif defined (LOG4CPLUS_HAVE_CXX11_ATOMICS) + std::atomic_fetch_add_explicit (&count, 1u, + std::memory_order_relaxed); + +#elif defined (LOG4CPLUS_HAVE___SYNC_ADD_AND_FETCH) + __sync_add_and_fetch (&count, 1); + +#elif defined (_WIN32) && defined (LOG4CPLUS_HAVE_INTRIN_H) + _InterlockedIncrement (&count); + +#elif defined (_WIN32) + InterlockedIncrement (&count); + +#else + thread::MutexGuard guard (access_mutex); + ++count; + +#endif +} + + +void +SharedObject::removeReference() const +{ + assert (count > 0); + bool destroy; + +#if defined (LOG4CPLUS_SINGLE_THREADED) + destroy = --count == 0; + +#elif defined (LOG4CPLUS_HAVE_CXX11_ATOMICS) + destroy = std::atomic_fetch_sub_explicit (&count, 1u, + std::memory_order_release) == 1; + if (LOG4CPLUS_UNLIKELY (destroy)) + std::atomic_thread_fence (std::memory_order_acquire); + +#elif defined (LOG4CPLUS_HAVE___SYNC_SUB_AND_FETCH) + destroy = __sync_sub_and_fetch (&count, 1) == 0; + +#elif defined (_WIN32) && defined (LOG4CPLUS_HAVE_INTRIN_H) + destroy = _InterlockedDecrement (&count) == 0; + +#elif defined (_WIN32) + destroy = InterlockedDecrement (&count) == 0; + +#else + { + thread::MutexGuard guard (access_mutex); + destroy = --count == 0; + } + +#endif + if (LOG4CPLUS_UNLIKELY (destroy)) + delete this; +} + + +} } // namespace log4cplus { namespace helpers diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/property.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/property.cxx new file mode 100644 index 000000000..e2dd7ce13 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/property.cxx @@ -0,0 +1,392 @@ +// Module: Log4CPLUS +// File: property.cxx +// Created: 2/2002 +// Author: Tad E. Smith +// +// +// Copyright 2002-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/config.hxx> + +#include <cstring> +#if defined (UNICODE) +# include <cwctype> +#else +# include <cctype> +#endif +#if defined (LOG4CPLUS_HAVE_CODECVT_UTF8_FACET) \ + || defined (LOG4CPLUS_HAVE_CODECVT_UTF16_FACET) \ + || defined (LOG4CPLUS_HAVE_CODECVT_UTF32_FACET) +# include <codecvt> +#endif +#include <locale> +#include <fstream> +#include <sstream> +#include <log4cplus/streams.h> +#include <log4cplus/fstreams.h> +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/internal/internal.h> +#include <log4cplus/internal/env.h> +#include <log4cplus/helpers/loglog.h> + + +namespace log4cplus { namespace helpers { + + +const tchar Properties::PROPERTIES_COMMENT_CHAR = LOG4CPLUS_TEXT('#'); + + +namespace +{ + + +static +int +is_space (tchar ch) +{ +#if defined (UNICODE) + return std::iswspace (ch); +#else + return std::isspace (static_cast<unsigned char>(ch)); +#endif +} + + +static +void +trim_leading_ws (tstring & str) +{ + tstring::iterator it = str.begin (); + for (; it != str.end (); ++it) + { + if (! is_space (*it)) + break; + } + str.erase (str.begin (), it); +} + + +static +void +trim_trailing_ws (tstring & str) +{ + tstring::reverse_iterator rit = str.rbegin (); + for (; rit != str.rend (); ++rit) + { + if (! is_space (*rit)) + break; + } + str.erase (rit.base (), str.end ()); +} + + +static +void +trim_ws (tstring & str) +{ + trim_trailing_ws (str); + trim_leading_ws (str); +} + + +} // namespace + + + +/////////////////////////////////////////////////////////////////////////////// +// Properties ctors and dtor +/////////////////////////////////////////////////////////////////////////////// + +Properties::Properties() +{ +} + + + +Properties::Properties(tistream& input) +{ + init(input); +} + + + +Properties::Properties(const tstring& inputFile, unsigned flags) +{ + if (inputFile.empty ()) + return; + + tifstream file; + + switch (flags & fEncodingMask) + { +#if defined (LOG4CPLUS_HAVE_CODECVT_UTF8_FACET) && defined (UNICODE) + case fUTF8: + file.imbue ( + std::locale (file.getloc (), + new std::codecvt_utf8<tchar, 0x10FFFF, + static_cast<std::codecvt_mode>(std::consume_header | std::little_endian)>)); + break; +#endif + +#if defined (LOG4CPLUS_HAVE_CODECVT_UTF16_FACET) && defined (UNICODE) + case fUTF16: + file.imbue ( + std::locale (file.getloc (), + new std::codecvt_utf16<tchar, 0x10FFFF, + static_cast<std::codecvt_mode>(std::consume_header | std::little_endian)>)); + break; + +#elif defined (UNICODE) && defined (WIN32) + case fUTF16: + file.imbue ( + std::locale (file.getloc (), + new std::codecvt<wchar_t, wchar_t, std::mbstate_t>)); + break; + +#endif + +#if defined (LOG4CPLUS_HAVE_CODECVT_UTF32_FACET) && defined (UNICODE) + case fUTF32: + file.imbue ( + std::locale (file.getloc (), + new std::codecvt_utf32<tchar, 0x10FFFF, + static_cast<std::codecvt_mode>(std::consume_header | std::little_endian)>)); + break; +#endif + + case fUnspecEncoding:; + default: + // Do nothing. + ; + } + + file.open(LOG4CPLUS_FSTREAM_PREFERED_FILE_NAME(inputFile).c_str(), + std::ios::binary); + if (! file.good ()) + helpers::getLogLog ().error (LOG4CPLUS_TEXT ("could not open file ") + + inputFile); + + init(file); +} + + + +void +Properties::init(tistream& input) +{ + if (! input) + return; + + tstring buffer; + while (std::getline (input, buffer)) + { + trim_leading_ws (buffer); + + tstring::size_type const buffLen = buffer.size (); + if (buffLen == 0 || buffer[0] == PROPERTIES_COMMENT_CHAR) + continue; + + // Check if we have a trailing \r because we are + // reading a properties file produced on Windows. + if (buffer[buffLen-1] == LOG4CPLUS_TEXT('\r')) + // Remove trailing 'Windows' \r. + buffer.resize (buffLen - 1); + + tstring::size_type const idx = buffer.find('='); + if (idx != tstring::npos) + { + tstring key = buffer.substr(0, idx); + tstring value = buffer.substr(idx + 1); + trim_trailing_ws (key); + trim_ws (value); + setProperty(key, value); + } + } +} + + + +Properties::~Properties() +{ +} + + + +/////////////////////////////////////////////////////////////////////////////// +// helpers::Properties public methods +/////////////////////////////////////////////////////////////////////////////// + + +bool +Properties::exists(const log4cplus::tstring& key) const +{ + return data.find(key) != data.end(); +} + + +bool +Properties::exists(tchar const * key) const +{ + return data.find(key) != data.end(); +} + + +tstring const & +Properties::getProperty(const tstring& key) const +{ + return get_property_worker (key); +} + + +log4cplus::tstring const & +Properties::getProperty(tchar const * key) const +{ + return get_property_worker (key); +} + + +tstring +Properties::getProperty(const tstring& key, const tstring& defaultVal) const +{ + StringMap::const_iterator it (data.find (key)); + if (it == data.end ()) + return defaultVal; + else + return it->second; +} + + +std::vector<tstring> +Properties::propertyNames() const +{ + std::vector<tstring> tmp; + for (StringMap::const_iterator it=data.begin(); it!=data.end(); ++it) + tmp.push_back(it->first); + + return tmp; +} + + + +void +Properties::setProperty(const log4cplus::tstring& key, + const log4cplus::tstring& value) +{ + data[key] = value; +} + + +bool +Properties::removeProperty(const log4cplus::tstring& key) +{ + return data.erase(key) > 0; +} + + +Properties +Properties::getPropertySubset(const log4cplus::tstring& prefix) const +{ + Properties ret; + std::size_t const prefix_len = prefix.size (); + std::vector<tstring> keys = propertyNames(); + for (std::vector<tstring>::iterator it=keys.begin(); it!=keys.end(); ++it) + { + int result = it->compare (0, prefix_len, prefix); + if (result == 0) + ret.setProperty (it->substr (prefix_len), getProperty(*it)); + } + + return ret; +} + + +bool +Properties::getInt (int & val, log4cplus::tstring const & key) const +{ + return get_type_val_worker (val, key); +} + + +bool +Properties::getUInt (unsigned & val, log4cplus::tstring const & key) const +{ + return get_type_val_worker (val, key); +} + + +bool +Properties::getLong (long & val, log4cplus::tstring const & key) const +{ + return get_type_val_worker (val, key); +} + + +bool +Properties::getULong (unsigned long & val, log4cplus::tstring const & key) const +{ + return get_type_val_worker (val, key); +} + + +bool +Properties::getBool (bool & val, log4cplus::tstring const & key) const +{ + if (! exists (key)) + return false; + + log4cplus::tstring const & prop_val = getProperty (key); + return internal::parse_bool (val, prop_val); +} + + +template <typename StringType> +log4cplus::tstring const & +Properties::get_property_worker (StringType const & key) const +{ + StringMap::const_iterator it (data.find (key)); + if (it == data.end ()) + return log4cplus::internal::empty_str; + else + return it->second; +} + + +template <typename ValType> +bool +Properties::get_type_val_worker (ValType & val, log4cplus::tstring const & key) + const +{ + if (! exists (key)) + return false; + + log4cplus::tstring const & prop_val = getProperty (key); + log4cplus::tistringstream iss (prop_val); + ValType tmp_val; + tchar ch; + + iss >> tmp_val; + if (! iss) + return false; + iss >> ch; + if (iss) + return false; + + val = tmp_val; + return true; +} + + +} } // namespace log4cplus { namespace helpers { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/queue.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/queue.cxx new file mode 100644 index 000000000..5630fad5b --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/queue.cxx @@ -0,0 +1,188 @@ +// Copyright (C) 2009-2010, Vaclav Haisman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <log4cplus/config.hxx> +#ifndef LOG4CPLUS_SINGLE_THREADED + +#include <log4cplus/helpers/queue.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <stdexcept> +#include <algorithm> +#include <iterator> + + +namespace log4cplus { namespace thread { + + +Queue::Queue (unsigned len) + : mutex (Mutex::DEFAULT) + , ev_consumer (false) + , sem (len, len) + , flags (DRAIN) +{ } + + +Queue::~Queue () +{ } + + +Queue::flags_type +Queue::put_event (spi::InternalLoggingEvent const & ev) +{ + flags_type ret_flags = ERROR_BIT; + try + { + ev.gatherThreadSpecificData (); + + SemaphoreGuard semguard (sem); + MutexGuard mguard (mutex); + + ret_flags |= flags; + + if (flags & EXIT) + { + ret_flags &= ~(ERROR_BIT | ERROR_AFTER); + return ret_flags; + } + else + { + queue.push_back (ev); + ret_flags |= ERROR_AFTER; + semguard.detach (); + flags |= QUEUE; + ret_flags |= flags; + mguard.unlock (); + mguard.detach (); + ev_consumer.signal (); + } + } + catch (std::runtime_error const & e) + { + (void)e; + return ret_flags; + } + + ret_flags &= ~(ERROR_BIT | ERROR_AFTER); + return ret_flags; +} + + +Queue::flags_type +Queue::signal_exit (bool drain) +{ + flags_type ret_flags = 0; + + try + { + MutexGuard mguard (mutex); + + ret_flags |= flags; + + if (! (flags & EXIT)) + { + if (drain) + flags |= DRAIN; + else + flags &= ~DRAIN; + flags |= EXIT; + ret_flags = flags; + mguard.unlock (); + mguard.detach (); + ev_consumer.signal (); + } + } + catch (std::runtime_error const & e) + { + (void)e; + ret_flags |= ERROR_BIT; + return ret_flags; + } + + return ret_flags; +} + + +Queue::flags_type +Queue::get_events (queue_storage_type * buf) +{ + flags_type ret_flags = 0; + + try + { + while (true) + { + MutexGuard mguard (mutex); + + ret_flags = flags; + + if (((QUEUE & flags) && ! (EXIT & flags)) + || ((EXIT | DRAIN | QUEUE) & flags) == (EXIT | DRAIN | QUEUE)) + { + assert (! queue.empty ()); + + std::size_t const count = queue.size (); + queue.swap (*buf); + queue.clear (); + flags &= ~QUEUE; + for (std::size_t i = 0; i != count; ++i) + sem.unlock (); + + ret_flags = flags | EVENT; + break; + } + else if (((EXIT | QUEUE) & flags) == (EXIT | QUEUE)) + { + assert (! queue.empty ()); + queue.clear (); + flags &= ~QUEUE; + ev_consumer.reset (); + sem.unlock (); + ret_flags = flags; + break; + } + else if (EXIT & flags) + break; + else + { + ev_consumer.reset (); + mguard.unlock (); + mguard.detach (); + ev_consumer.wait (); + } + } + } + catch (std::runtime_error const & e) + { + (void)e; + ret_flags |= ERROR_BIT; + } + + return ret_flags; +} + + +} } // namespace log4cplus { namespace thread { + + +#endif // LOG4CPLUS_SINGLE_THREADED diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/rootlogger.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/rootlogger.cxx new file mode 100644 index 000000000..ff0122059 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/rootlogger.cxx @@ -0,0 +1,65 @@ +// Module: Log4CPLUS +// File: rootlogger.cxx +// Created: 4/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/spi/rootlogger.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/thread/syncprims-pub-impl.h> + + +namespace log4cplus { namespace spi { + + +////////////////////////////////////////////////////////////////////////////// +// RootLogger Constructor +////////////////////////////////////////////////////////////////////////////// + +RootLogger::RootLogger(Hierarchy& h, LogLevel loglevel) +: LoggerImpl(LOG4CPLUS_TEXT("root"), h) +{ + setLogLevel(loglevel); +} + + + +////////////////////////////////////////////////////////////////////////////// +// Logger Methods +////////////////////////////////////////////////////////////////////////////// + +LogLevel +RootLogger::getChainedLogLevel() const +{ + return ll; +} + + +void +RootLogger::setLogLevel(LogLevel loglevel) +{ + if(loglevel == NOT_SET_LOG_LEVEL) { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("You have tried to set NOT_SET_LOG_LEVEL to root.")); + } + else { + LoggerImpl::setLogLevel(loglevel); + } +} + + +} } // namespace log4cplus { namespace spi { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/sleep.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/sleep.cxx new file mode 100644 index 000000000..901dddcde --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/sleep.cxx @@ -0,0 +1,110 @@ +// Module: Log4CPLUS +// File: sleep.cxx +// Created: 5/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/config/windowsh-inc.h> +#include <log4cplus/helpers/sleep.h> +#include <log4cplus/helpers/timehelper.h> + +#include <cerrno> +#if defined (LOG4CPLUS_HAVE_ERRNO_H) +#include <errno.h> +#endif + +#if defined (LOG4CPLUS_HAVE_TIME_H) +#include <time.h> +#endif + + +namespace log4cplus { namespace helpers { + + +/////////////////////////////////////////////////////////////////////////////// +// public methods +/////////////////////////////////////////////////////////////////////////////// + +int const MILLIS_TO_NANOS = 1000000; +int const SEC_TO_MILLIS = 1000; + + +#if ! defined (_WIN32) +static inline +int +unix_nanosleep (const struct timespec *req, struct timespec *rem) +{ +#if defined (LOG4CPLUS_HAVE_CLOCK_NANOSLEEP) + return clock_nanosleep (CLOCK_REALTIME, 0, req, rem); + +#elif defined (LOG4CPLUS_HAVE_NANOSLEEP) + return nanosleep (req, rem); + +#else +# error no nanosleep() or clock_nanosleep() +#endif +} + +#endif + + +void +sleep(unsigned long secs, unsigned long nanosecs) +{ +#if defined(_WIN32) + DWORD const MAX_SLEEP_SECONDS = 4294966; // (2**32-2)/1000 + + DWORD nano_millis = nanosecs / static_cast<unsigned long>(MILLIS_TO_NANOS); + if (secs <= MAX_SLEEP_SECONDS) { + Sleep((secs * SEC_TO_MILLIS) + nano_millis); + return; + } + + DWORD no_of_max_sleeps = secs / MAX_SLEEP_SECONDS; + + for(DWORD i = 0; i < no_of_max_sleeps; i++) { + Sleep(MAX_SLEEP_SECONDS * SEC_TO_MILLIS); + } + + Sleep((secs % MAX_SLEEP_SECONDS) * SEC_TO_MILLIS + nano_millis); +#else + timespec sleep_time = { static_cast<std::time_t>(secs), + static_cast<long>(nanosecs) }; + timespec remain; + while (unix_nanosleep (&sleep_time, &remain)) { + if (errno == EINTR) { + sleep_time.tv_sec = remain.tv_sec; + sleep_time.tv_nsec = remain.tv_nsec; + continue; + } + else { + return; + } + } +#endif +} + + +void +sleepmillis(unsigned long millis) +{ + unsigned long secs = millis / SEC_TO_MILLIS; + unsigned long nanosecs = (millis % SEC_TO_MILLIS) * MILLIS_TO_NANOS; + sleep(secs, nanosecs); +} + +} } // namespace log4cplus { namespace helpers { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/snprintf.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/snprintf.cxx new file mode 100644 index 000000000..8dbb5a9a5 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/snprintf.cxx @@ -0,0 +1,242 @@ +// Copyright (C) 2010, Vaclav Haisman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <log4cplus/helpers/snprintf.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/internal/internal.h> +#include <cstdarg> +#include <cstdio> +#if defined (UNICODE) +#include <cwchar> +#endif +#if defined (LOG4CPLUS_HAVE_STDARG_H) +# include <stdarg.h> +#endif +#if defined (LOG4CPLUS_HAVE_WCHAR_H) +# include <wchar.h> +#endif +#if defined (LOG4CPLUS_HAVE_STDIO_H) +# include <stdio.h> +#endif + + +namespace log4cplus { namespace helpers { + + +std::size_t const START_BUF_SIZE = 512; + +#if defined (_WIN32) +char const NULL_FILE[] = "NUL"; +#else +char const NULL_FILE[] = "/dev/null"; +#endif + + +namespace +{ + + +#if defined (LOG4CPLUS_USE_POOR_MANS_SNPRINTF) + +static inline int vftprintf (std::FILE * file, tchar const * fmt, + std::va_list args) LOG4CPLUS_FORMAT_ATTRIBUTE (__printf__, 2, 0); + +static inline +int +vftprintf (std::FILE * file, tchar const * fmt, std::va_list args) +{ +#if defined (UNICODE) +# if defined (LOG4CPLUS_HAVE_VFWPRINTF_S) + return vfwprintf_s (file, fmt, args); +# else + return std::vfwprintf (file, fmt, args); +# endif +#else +# if defined (LOG4CPLUS_HAVE_VFPRINTF_S) + return vfprintf_s (file, fmt, args); +# else + return std::vfprintf (file, fmt, args); +# endif +#endif +} + + +static inline int vstprintf (tchar * dest, std::size_t dest_size, + tchar const * fmt, std::va_list args) + LOG4CPLUS_FORMAT_ATTRIBUTE (__printf__, 3, 0); + +static inline +int +vstprintf (tchar * dest, std::size_t dest_size, tchar const * fmt, + std::va_list args) +{ + int ret; +#if defined (UNICODE) +# if defined (LOG4CPLUS_HAVE_VSWPRINTF_S) + ret = vswprintf_s (dest, dest_size, fmt, args); +# else + ret = std::vswprintf (dest, dest_size, fmt, args); +# endif +#else +# if defined (LOG4CPLUS_HAVE_VSPRINTF_S) + ret = vsprintf_s (dest, dest_size, fmt, args); +# else + ret = std::vsprintf (dest, fmt, args); +# endif +#endif + + if (ret >= 0) + assert (static_cast<std::size_t>(ret) <= dest_size); + + return ret; +} + +#else /* ?defined (LOG4CPLUS_USE_POOR_MANS_SNPRINTF) */ + +static inline int vsntprintf (tchar * dest, std::size_t dest_size, + tchar const * fmt, std::va_list args) + LOG4CPLUS_FORMAT_ATTRIBUTE (__printf__, 3, 0); + +static inline +int +vsntprintf (tchar * dest, std::size_t dest_size, tchar const * fmt, + std::va_list args) +{ + int ret; + +#if defined (UNICODE) +# if defined (LOG4CPLUS_HAVE__VSNWPRINTF_S) && defined (_TRUNCATE) + ret = _vsnwprintf_s (dest, dest_size, _TRUNCATE, fmt, args); +# else + ret = std::vswprintf (dest, dest_size, fmt, args); +# endif +#else +# if defined (LOG4CPLUS_HAVE_VSNPRINTF_S) && defined (_TRUNCATE) + ret = vsnprintf_s (dest, dest_size, _TRUNCATE, fmt, args); +# elif defined (LOG4CPLUS_HAVE__VSNPRINTF_S) && defined (_TRUNCATE) + ret = _vsnprintf_s (dest, dest_size, _TRUNCATE, fmt, args); +# elif defined (LOG4CPLUS_HAVE_VSNPRINTF) + ret = vsnprintf (dest, dest_size, fmt, args); +# elif defined (LOG4CPLUS_HAVE__VSNPRINTF) + ret = _vsnprintf (dest, dest_size, fmt, args); +# else +# error "None of vsnprintf_s, _vsnprintf_s, vsnprintf or _vsnprintf is available." +# endif +#endif + + return ret; +} +#endif + + +} + + +snprintf_buf::snprintf_buf () + : buf (START_BUF_SIZE) +{ } + + +tchar const * +snprintf_buf::print (tchar const * fmt, ...) +{ + assert (fmt); + + std::va_list args; + va_start (args, fmt); + tchar const * ret = print_va_list (fmt, args); + va_end (args); + return ret; +} + + +tchar const * +snprintf_buf::print_va_list(tchar const * fmt, std::va_list args) +{ + int printed; + std::size_t const fmt_len = std::char_traits<tchar>::length (fmt); + std::size_t buf_size = buf.size (); + std::size_t const output_estimate = fmt_len + fmt_len / 2 + 1; + if (output_estimate > buf_size) + buf.resize (output_estimate); + +#if defined (LOG4CPLUS_USE_POOR_MANS_SNPRINTF) + std::FILE * & fnull = internal::get_ptd ()->fnull; + if (! fnull) + { + fnull = std::fopen (NULL_FILE, "wb"); + if (! fnull) + { + LogLog::getLogLog ()->error ( + LOG4CPLUS_TEXT ("Could not open NULL_FILE.")); + buf.clear (); + buf.push_back (0); + return &buf[0]; + } + } + + printed = vftprintf (fnull, fmt, args); + if (printed == -1) + { + LogLog::getLogLog ()->error ( + LOG4CPLUS_TEXT ("Error printing into NULL_FILE.")); + buf.clear (); + buf.push_back (0); + return &buf[0]; + } + + buf.resize (printed + 1); + int sprinted = vstprintf (&buf[0], buf.size (), fmt, args); + if (sprinted == -1) + { + LogLog::getLogLog ()->error ( + LOG4CPLUS_TEXT ("Error printing into string.")); + buf.clear (); + buf.push_back (0); + return &buf[0]; + } + assert (printed == sprinted); + + buf[sprinted] = 0; + +#else + do + { + printed = vsntprintf (&buf[0], buf_size - 1, fmt, args); + if (printed == -1) + { + buf_size *= 2; + buf.resize (buf_size); + } + else + buf[printed] = 0; + } + while (printed == -1); + +#endif + + return &buf[0]; +} + + +} } // namespace log4cplus { namespace helpers diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socket-unix.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socket-unix.cxx new file mode 100644 index 000000000..ca84b7948 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socket-unix.cxx @@ -0,0 +1,414 @@ +// Module: Log4CPLUS +// File: socket-unix.cxx +// Created: 4/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +#include <log4cplus/config.hxx> +#if defined (LOG4CPLUS_USE_BSD_SOCKETS) + +#include <cstring> +#include <vector> +#include <algorithm> +#include <cerrno> +#include <log4cplus/internal/socket.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <log4cplus/spi/loggingevent.h> +#include <log4cplus/helpers/stringhelper.h> + +#ifdef LOG4CPLUS_HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif + +#ifdef LOG4CPLUS_HAVE_SYS_SOCKET_H +#include <sys/socket.h> +#endif + +#if defined (LOG4CPLUS_HAVE_NETINET_IN_H) +#include <netinet/in.h> +#endif + +#if defined (LOG4CPLUS_HAVE_NETINET_TCP_H) +#include <netinet/tcp.h> +#endif + +#if defined (LOG4CPLUS_HAVE_ARPA_INET_H) +#include <arpa/inet.h> +#endif + +#if defined (LOG4CPLUS_HAVE_ERRNO_H) +#include <errno.h> +#endif + +#ifdef LOG4CPLUS_HAVE_NETDB_H +#include <netdb.h> +#endif + +#ifdef LOG4CPLUS_HAVE_UNISTD_H +#include <unistd.h> +#endif + + +namespace log4cplus { namespace helpers { + + +namespace +{ + + +#if ! defined (LOG4CPLUS_SINGLE_THREADED) +// We need to use log4cplus::thread here to work around compilation +// problem on AIX. +static log4cplus::thread::Mutex ghbn_mutex; + +#endif + + +static +int +get_host_by_name (char const * hostname, std::string * name, + struct sockaddr_in * addr) +{ +#if defined (LOG4CPLUS_HAVE_GETADDRINFO) + struct addrinfo hints; + std::memset (&hints, 0, sizeof (hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + hints.ai_flags = AI_CANONNAME; + + if (inet_addr (hostname) != static_cast<in_addr_t>(-1)) + hints.ai_flags |= AI_NUMERICHOST; + + struct addrinfo * res = 0; + int ret = getaddrinfo (hostname, 0, &hints, &res); + if (ret != 0) + return ret; + + struct addrinfo const & ai = *res; + assert (ai.ai_family == AF_INET); + + if (name) + *name = ai.ai_canonname; + + if (addr) + std::memcpy (addr, ai.ai_addr, ai.ai_addrlen); + + freeaddrinfo (res); + +#else + #if ! defined (LOG4CPLUS_SINGLE_THREADED) + // We need to use log4cplus::thread here to work around + // compilation problem on AIX. + log4cplus::thread::MutexGuard guard (ghbn_mutex); + + #endif + + struct ::hostent * hp = gethostbyname (hostname); + if (! hp) + return 1; + assert (hp->h_addrtype == AF_INET); + + if (name) + *name = hp->h_name; + + if (addr) + { + assert (hp->h_length <= sizeof (addr->sin_addr)); + std::memcpy (&addr->sin_addr, hp->h_addr_list[0], hp->h_length); + } + +#endif + + return 0; +} + + +} // namespace + + +///////////////////////////////////////////////////////////////////////////// +// Global Methods +///////////////////////////////////////////////////////////////////////////// + +SOCKET_TYPE +openSocket(unsigned short port, SocketState& state) +{ + int sock = ::socket(AF_INET, SOCK_STREAM, 0); + if(sock < 0) { + return INVALID_SOCKET_VALUE; + } + + struct sockaddr_in server = sockaddr_in (); + server.sin_family = AF_INET; + server.sin_addr.s_addr = INADDR_ANY; + server.sin_port = htons(port); + + int optval = 1; + socklen_t optlen = sizeof (optval); + int ret = setsockopt( sock, SOL_SOCKET, SO_REUSEADDR, &optval, optlen ); + if (ret != 0) + { + helpers::getLogLog ().warn ("setsockopt() failed: " + + helpers::convertIntegerToString (errno)); + } + + int retval = bind(sock, reinterpret_cast<struct sockaddr*>(&server), + sizeof(server)); + if (retval < 0) + goto error; + + if (::listen(sock, 10)) + goto error; + + state = ok; + return to_log4cplus_socket (sock); + +error: + close (sock); + return INVALID_SOCKET_VALUE; +} + + +SOCKET_TYPE +connectSocket(const tstring& hostn, unsigned short port, bool udp, SocketState& state) +{ + struct sockaddr_in server; + int sock; + int retval; + + std::memset (&server, 0, sizeof (server)); + retval = get_host_by_name (LOG4CPLUS_TSTRING_TO_STRING(hostn).c_str(), + 0, &server); + if (retval != 0) + return INVALID_SOCKET_VALUE; + + server.sin_port = htons(port); + server.sin_family = AF_INET; + + sock = ::socket(AF_INET, (udp ? SOCK_DGRAM : SOCK_STREAM), 0); + if(sock < 0) { + return INVALID_SOCKET_VALUE; + } + + socklen_t namelen = sizeof (server); + while ( + (retval = ::connect(sock, reinterpret_cast<struct sockaddr*>(&server), + namelen)) + == -1 + && (errno == EINTR)) + ; + if (retval == INVALID_OS_SOCKET_VALUE) + { + ::close(sock); + return INVALID_SOCKET_VALUE; + } + + state = ok; + return to_log4cplus_socket (sock); +} + + +namespace +{ + +//! Helper for accept_wrap(). +template <typename T, typename U> +struct socklen_var +{ + typedef T type; +}; + + +template <typename U> +struct socklen_var<void, U> +{ + typedef U type; +}; + + +// Some systems like HP-UX have socklen_t but accept() does not use it +// as type of its 3rd parameter. This wrapper works around this +// incompatibility. +template <typename accept_sockaddr_ptr_type, typename accept_socklen_type> +static +SOCKET_TYPE +accept_wrap ( + int (* accept_func) (int, accept_sockaddr_ptr_type, accept_socklen_type *), + SOCKET_TYPE sock, struct sockaddr * sa, socklen_t * len) +{ + typedef typename socklen_var<accept_socklen_type, socklen_t>::type + socklen_var_type; + socklen_var_type l = static_cast<socklen_var_type>(*len); + SOCKET_TYPE result + = static_cast<SOCKET_TYPE>( + accept_func (sock, sa, + reinterpret_cast<accept_socklen_type *>(&l))); + *len = static_cast<socklen_t>(l); + return result; +} + + +} // namespace + + +SOCKET_TYPE +acceptSocket(SOCKET_TYPE sock, SocketState& state) +{ + struct sockaddr_in net_client; + socklen_t len = sizeof(struct sockaddr); + int clientSock; + + while( + (clientSock = accept_wrap (accept, to_os_socket (sock), + reinterpret_cast<struct sockaddr*>(&net_client), &len)) + == -1 + && (errno == EINTR)) + ; + + if(clientSock != INVALID_OS_SOCKET_VALUE) { + state = ok; + } + + return to_log4cplus_socket (clientSock); +} + + + +int +closeSocket(SOCKET_TYPE sock) +{ + return ::close(to_os_socket (sock)); +} + + + +long +read(SOCKET_TYPE sock, SocketBuffer& buffer) +{ + long res, readbytes = 0; + + do + { + res = ::read(to_os_socket (sock), buffer.getBuffer() + readbytes, + buffer.getMaxSize() - readbytes); + if( res <= 0 ) { + return res; + } + readbytes += res; + } while( readbytes < static_cast<long>(buffer.getMaxSize()) ); + + return readbytes; +} + + + +long +write(SOCKET_TYPE sock, const SocketBuffer& buffer) +{ +#if defined(MSG_NOSIGNAL) + int flags = MSG_NOSIGNAL; +#else + int flags = 0; +#endif + return ::send( to_os_socket (sock), buffer.getBuffer(), buffer.getSize(), + flags ); +} + + +long +write(SOCKET_TYPE sock, const std::string & buffer) +{ +#if defined(MSG_NOSIGNAL) + int flags = MSG_NOSIGNAL; +#else + int flags = 0; +#endif + return ::send (to_os_socket (sock), buffer.c_str (), buffer.size (), + flags); +} + + +tstring +getHostname (bool fqdn) +{ + char const * hostname = "unknown"; + int ret; + std::vector<char> hn (1024, 0); + + while (true) + { + ret = ::gethostname (&hn[0], static_cast<int>(hn.size ()) - 1); + if (ret == 0) + { + hostname = &hn[0]; + break; + } +#if defined (LOG4CPLUS_HAVE_ENAMETOOLONG) + else if (ret != 0 && errno == ENAMETOOLONG) + // Out buffer was too short. Retry with buffer twice the size. + hn.resize (hn.size () * 2, 0); +#endif + else + break; + } + + if (ret != 0 || (ret == 0 && ! fqdn)) + return LOG4CPLUS_STRING_TO_TSTRING (hostname); + + std::string full_hostname; + ret = get_host_by_name (hostname, &full_hostname, 0); + if (ret == 0) + hostname = full_hostname.c_str (); + + return LOG4CPLUS_STRING_TO_TSTRING (hostname); +} + + +int +setTCPNoDelay (SOCKET_TYPE sock, bool val) +{ +#if (defined (SOL_TCP) || defined (IPPROTO_TCP)) && defined (TCP_NODELAY) +#if defined (SOL_TCP) + int level = SOL_TCP; + +#elif defined (IPPROTO_TCP) + int level = IPPROTO_TCP; + +#endif + + int result; + int enabled = static_cast<int>(val); + if ((result = setsockopt(sock, level, TCP_NODELAY, &enabled, + sizeof(enabled))) != 0) + set_last_socket_error (errno); + + return result; + +#else + // No recognizable TCP_NODELAY option. + return 0; + +#endif +} + + +} } // namespace log4cplus + +#endif // LOG4CPLUS_USE_BSD_SOCKETS diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socket-win32.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socket-win32.cxx new file mode 100644 index 000000000..0f74dccf5 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socket-win32.cxx @@ -0,0 +1,380 @@ +// Module: Log4CPLUS +// File: socket-win32.cxx +// Created: 4/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/config.hxx> +#if defined (LOG4CPLUS_USE_WINSOCK) + +#include <cassert> +#include <cerrno> +#include <vector> +#include <cstring> +#include <log4cplus/internal/socket.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/thread/threads.h> + + +///////////////////////////////////////////////////////////////////////////// +// file LOCAL Classes +///////////////////////////////////////////////////////////////////////////// + +namespace +{ + +enum WSInitStates +{ + WS_UNINITIALIZED, + WS_INITIALIZING, + WS_INITIALIZED +}; + + +static WSADATA wsa; +static LONG volatile winsock_state = WS_UNINITIALIZED; + + +static +void +init_winsock_worker () +{ + log4cplus::helpers::LogLog * loglog + = log4cplus::helpers::LogLog::getLogLog (); + + // Try to change the state to WS_INITIALIZING. + LONG val = ::InterlockedCompareExchange ( + const_cast<LPLONG>(&winsock_state), WS_INITIALIZING, WS_UNINITIALIZED); + switch (val) + { + case WS_UNINITIALIZED: + { + int ret = WSAStartup (MAKEWORD (2, 2), &wsa); + if (ret != 0) + { + // Revert the state back to WS_UNINITIALIZED to unblock other + // threads and let them throw exception. + val = ::InterlockedCompareExchange ( + const_cast<LPLONG>(&winsock_state), WS_UNINITIALIZED, + WS_INITIALIZING); + assert (val == WS_INITIALIZING); + loglog->error (LOG4CPLUS_TEXT ("Could not initialize WinSock."), + true); + } + + // WinSock is initialized, change the state to WS_INITIALIZED. + val = ::InterlockedCompareExchange ( + const_cast<LPLONG>(&winsock_state), WS_INITIALIZED, + WS_INITIALIZING); + assert (val == WS_INITIALIZING); + return; + } + + case WS_INITIALIZING: + // Wait for state change. + while (true) + { + switch (winsock_state) + { + case WS_INITIALIZED: + return; + + case WS_INITIALIZING: + log4cplus::thread::yield (); + continue; + + default: + assert (0); + loglog->error (LOG4CPLUS_TEXT ("Unknown WinSock state."), true); + } + } + + case WS_INITIALIZED: + // WinSock is already initialized. + return; + + default: + assert (0); + loglog->error (LOG4CPLUS_TEXT ("Unknown WinSock state."), true); + } +} + + +static +void +init_winsock () +{ + // Quick check first to avoid the expensive interlocked compare + // and exchange. + if (winsock_state == WS_INITIALIZED) + return; + else + init_winsock_worker (); +} + + +struct WinSockInitializer +{ + ~WinSockInitializer () + { + if (winsock_state == WS_INITIALIZED) + WSACleanup (); + } + + static WinSockInitializer winSockInitializer; +}; + + +WinSockInitializer WinSockInitializer::winSockInitializer; + + +} // namespace + + +namespace log4cplus { namespace helpers { + + +///////////////////////////////////////////////////////////////////////////// +// Global Methods +///////////////////////////////////////////////////////////////////////////// + +SOCKET_TYPE +openSocket(unsigned short port, SocketState& state) +{ + struct sockaddr_in server; + + init_winsock (); + + SOCKET sock = WSASocket (AF_INET, SOCK_STREAM, AF_UNSPEC, 0, 0 +#if defined (WSA_FLAG_NO_HANDLE_INHERIT) + , WSA_FLAG_NO_HANDLE_INHERIT +#else + , 0 +#endif + ); + + if (sock == INVALID_OS_SOCKET_VALUE) + goto error; + + server.sin_family = AF_INET; + server.sin_addr.s_addr = htonl(INADDR_ANY); + server.sin_port = htons(port); + + if (bind(sock, reinterpret_cast<struct sockaddr*>(&server), sizeof(server)) + != 0) + goto error; + + if (::listen(sock, 10) != 0) + goto error; + + state = ok; + return to_log4cplus_socket (sock); + +error: + int eno = WSAGetLastError (); + + if (sock != INVALID_OS_SOCKET_VALUE) + ::closesocket (sock); + + set_last_socket_error (eno); + return INVALID_SOCKET_VALUE; +} + + +SOCKET_TYPE +connectSocket(const tstring& hostn, unsigned short port, bool udp, SocketState& state) +{ + struct hostent * hp; + struct sockaddr_in insock; + int retval; + + init_winsock (); + + SOCKET sock = WSASocket (AF_INET, (udp ? SOCK_DGRAM : SOCK_STREAM), + AF_UNSPEC, 0, 0 +#if defined (WSA_FLAG_NO_HANDLE_INHERIT) + , WSA_FLAG_NO_HANDLE_INHERIT +#else + , 0 +#endif + ); + if (sock == INVALID_OS_SOCKET_VALUE) + goto error; + + hp = ::gethostbyname( LOG4CPLUS_TSTRING_TO_STRING(hostn).c_str() ); + if (hp == 0 || hp->h_addrtype != AF_INET) + { + insock.sin_family = AF_INET; + INT insock_size = sizeof (insock); + INT ret = WSAStringToAddress (const_cast<LPTSTR>(hostn.c_str ()), + AF_INET, 0, reinterpret_cast<struct sockaddr *>(&insock), + &insock_size); + if (ret == SOCKET_ERROR || insock_size != sizeof (insock)) + { + state = bad_address; + goto error; + } + } + else + std::memcpy (&insock.sin_addr, hp->h_addr_list[0], + sizeof (insock.sin_addr)); + + insock.sin_port = htons(port); + insock.sin_family = AF_INET; + + while( (retval = ::connect(sock, (struct sockaddr*)&insock, sizeof(insock))) == -1 + && (WSAGetLastError() == WSAEINTR)) + ; + if (retval == SOCKET_ERROR) + goto error; + + state = ok; + return to_log4cplus_socket (sock); + +error: + int eno = WSAGetLastError (); + + if (sock != INVALID_OS_SOCKET_VALUE) + ::closesocket (sock); + + set_last_socket_error (eno); + return INVALID_SOCKET_VALUE; +} + + +SOCKET_TYPE +acceptSocket(SOCKET_TYPE sock, SocketState & state) +{ + init_winsock (); + + SOCKET connected_socket = ::accept (to_os_socket (sock), NULL, NULL); + + if (connected_socket != INVALID_OS_SOCKET_VALUE) + state = ok; + + return to_log4cplus_socket (connected_socket); +} + + + +int +closeSocket(SOCKET_TYPE sock) +{ + return ::closesocket (to_os_socket (sock)); +} + + + +long +read(SOCKET_TYPE sock, SocketBuffer& buffer) +{ + long res, read = 0; + + do + { + res = ::recv(to_os_socket (sock), + buffer.getBuffer() + read, + static_cast<int>(buffer.getMaxSize() - read), + 0); + if (res == SOCKET_ERROR) + { + set_last_socket_error (WSAGetLastError ()); + return res; + } + read += res; + } + while (read < static_cast<long>(buffer.getMaxSize())); + + return read; +} + + + +long +write(SOCKET_TYPE sock, const SocketBuffer& buffer) +{ + long ret = ::send (to_os_socket (sock), buffer.getBuffer(), + static_cast<int>(buffer.getSize()), 0); + if (ret == SOCKET_ERROR) + set_last_socket_error (WSAGetLastError ()); + return ret; +} + + +long +write(SOCKET_TYPE sock, const std::string & buffer) +{ + long ret = ::send (to_os_socket (sock), buffer.c_str (), + static_cast<int>(buffer.size ()), 0); + if (ret == SOCKET_ERROR) + set_last_socket_error (WSAGetLastError ()); + return ret; +} + + +tstring +getHostname (bool fqdn) +{ + char const * hostname = "unknown"; + int ret; + std::vector<char> hn (1024, 0); + + while (true) + { + ret = ::gethostname (&hn[0], static_cast<int>(hn.size ()) - 1); + if (ret == 0) + { + hostname = &hn[0]; + break; + } + else if (ret != 0 && WSAGetLastError () == WSAEFAULT) + // Out buffer was too short. Retry with buffer twice the size. + hn.resize (hn.size () * 2, 0); + else + break; + } + + if (ret != 0 || (ret == 0 && ! fqdn)) + return LOG4CPLUS_STRING_TO_TSTRING (hostname); + + struct ::hostent * hp = ::gethostbyname (hostname); + if (hp) + hostname = hp->h_name; + + return LOG4CPLUS_STRING_TO_TSTRING (hostname); +} + + +int +setTCPNoDelay (SOCKET_TYPE sock, bool val) +{ + int result; + int enabled = static_cast<int>(val); + if ((result = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, + reinterpret_cast<char*>(&enabled),sizeof(enabled))) != 0) + { + int eno = WSAGetLastError (); + set_last_socket_error (eno); + } + + return result; +} + + +} } // namespace log4cplus { namespace helpers { + +#endif // LOG4CPLUS_USE_WINSOCK diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socket.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socket.cxx new file mode 100644 index 000000000..c5e5de783 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socket.cxx @@ -0,0 +1,238 @@ +// Module: Log4CPLUS +// File: socket-win32.cxx +// Created: 4/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/internal/socket.h> + + +namespace log4cplus { namespace helpers { + + +extern LOG4CPLUS_EXPORT SOCKET_TYPE const INVALID_SOCKET_VALUE +#if defined(_WIN32) + = static_cast<SOCKET_TYPE>(INVALID_SOCKET); +#else + = static_cast<SOCKET_TYPE>(-1); +#endif + + +////////////////////////////////////////////////////////////////////////////// +// AbstractSocket ctors and dtor +////////////////////////////////////////////////////////////////////////////// + +AbstractSocket::AbstractSocket() +: sock(INVALID_SOCKET_VALUE), + state(not_opened), + err(0) +{ +} + + + +AbstractSocket::AbstractSocket(SOCKET_TYPE sock_, + SocketState state_, int err_) +: sock(sock_), + state(state_), + err(err_) +{ +} + + + +AbstractSocket::AbstractSocket(const AbstractSocket& rhs) +{ + copy(rhs); +} + + +AbstractSocket::~AbstractSocket() +{ + close(); +} + + + +////////////////////////////////////////////////////////////////////////////// +// AbstractSocket methods +////////////////////////////////////////////////////////////////////////////// + +void +AbstractSocket::close() +{ + if(sock != INVALID_SOCKET_VALUE) { + closeSocket(sock); + sock = INVALID_SOCKET_VALUE; + } +} + + + +bool +AbstractSocket::isOpen() const +{ + return sock != INVALID_SOCKET_VALUE; +} + + + + +AbstractSocket& +AbstractSocket::operator=(const AbstractSocket& rhs) +{ + if(&rhs != this) { + close(); + copy(rhs); + } + + return *this; +} + + + +void +AbstractSocket::copy(const AbstractSocket& r) +{ + AbstractSocket& rhs = const_cast<AbstractSocket&>(r); + sock = rhs.sock; + state = rhs.state; + err = rhs.err; + rhs.sock = INVALID_SOCKET_VALUE; + rhs.state = not_opened; + rhs.err = 0; +} + + + +////////////////////////////////////////////////////////////////////////////// +// Socket ctors and dtor +////////////////////////////////////////////////////////////////////////////// + +Socket::Socket() + : AbstractSocket() +{ } + + +Socket::Socket(const tstring& address, unsigned short port, bool udp /*= false*/) + : AbstractSocket() +{ + sock = connectSocket(address, port, udp, state); + if (sock == INVALID_SOCKET_VALUE) + goto error; + + if (! udp && setTCPNoDelay (sock, true) != 0) + goto error; + + return; + +error: + err = get_last_socket_error (); +} + + +Socket::Socket(SOCKET_TYPE sock_, SocketState state_, int err_) + : AbstractSocket(sock_, state_, err_) +{ } + + +Socket::~Socket() +{ } + + + +////////////////////////////////////////////////////////////////////////////// +// Socket methods +////////////////////////////////////////////////////////////////////////////// + +bool +Socket::read(SocketBuffer& buffer) +{ + long retval = helpers::read(sock, buffer); + if(retval <= 0) { + close(); + } + else { + buffer.setSize(retval); + } + + return (retval > 0); +} + + + +bool +Socket::write(const SocketBuffer& buffer) +{ + long retval = helpers::write(sock, buffer); + if(retval <= 0) { + close(); + } + + return (retval > 0); +} + + +bool +Socket::write(const std::string & buffer) +{ + long retval = helpers::write (sock, buffer); + if (retval <= 0) + close(); + + return retval > 0; +} + + + + + +////////////////////////////////////////////////////////////////////////////// +// ServerSocket ctor and dtor +////////////////////////////////////////////////////////////////////////////// + +ServerSocket::ServerSocket(unsigned short port) +{ + sock = openSocket(port, state); + if(sock == INVALID_SOCKET_VALUE) { + err = get_last_socket_error (); + } +} + + + +ServerSocket::~ServerSocket() +{ +} + + + +////////////////////////////////////////////////////////////////////////////// +// ServerSocket methods +////////////////////////////////////////////////////////////////////////////// + +Socket +ServerSocket::accept() +{ + SocketState st = not_opened; + SOCKET_TYPE clientSock = acceptSocket(sock, st); + return Socket(clientSock, st, 0); +} + + +} } // namespace log4cplus { namespace helpers { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socketappender.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socketappender.cxx new file mode 100644 index 000000000..cd06440cb --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socketappender.cxx @@ -0,0 +1,328 @@ +// Module: Log4CPLUS +// File: socketappender.cxx +// Created: 5/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <cstdlib> +#include <log4cplus/socketappender.h> +#include <log4cplus/layout.h> +#include <log4cplus/spi/loggingevent.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/sleep.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/thread/syncprims-pub-impl.h> + + +namespace log4cplus { + +int const LOG4CPLUS_MESSAGE_VERSION = 3; + + +#if ! defined (LOG4CPLUS_SINGLE_THREADED) +SocketAppender::ConnectorThread::ConnectorThread ( + SocketAppender & socket_appender) + : sa (socket_appender) + , exit_flag (false) +{ } + + +SocketAppender::ConnectorThread::~ConnectorThread () +{ } + + +void +SocketAppender::ConnectorThread::run () +{ + while (true) + { + trigger_ev.timed_wait (30 * 1000); + + helpers::getLogLog().debug ( + LOG4CPLUS_TEXT("SocketAppender::ConnectorThread::run()") + LOG4CPLUS_TEXT("- running...")); + + // Check exit condition as the very first thing. + + { + thread::MutexGuard guard (access_mutex); + if (exit_flag) + return; + trigger_ev.reset (); + } + + // Do not try to re-open already open socket. + + { + thread::MutexGuard guard (sa.access_mutex); + if (sa.socket.isOpen ()) + continue; + } + + // The socket is not open, try to reconnect. + + helpers::Socket new_socket (sa.host, + static_cast<unsigned short>(sa.port)); + if (! new_socket.isOpen ()) + { + helpers::getLogLog().error( + LOG4CPLUS_TEXT("SocketAppender::ConnectorThread::run()") + LOG4CPLUS_TEXT("- Cannot connect to server")); + + // Sleep for a short while after unsuccessful connection attempt + // so that we do not try to reconnect after each logging attempt + // which could be many times per second. + helpers::sleep (5); + + continue; + } + + // Connection was successful, move the socket into SocketAppender. + + { + thread::MutexGuard guard (sa.access_mutex); + sa.socket = new_socket; + sa.connected = true; + } + } +} + + +void +SocketAppender::ConnectorThread::terminate () +{ + { + thread::MutexGuard guard (access_mutex); + exit_flag = true; + trigger_ev.signal (); + } + join (); +} + + +void +SocketAppender::ConnectorThread::trigger () +{ + trigger_ev.signal (); +} + +#endif + + +////////////////////////////////////////////////////////////////////////////// +// SocketAppender ctors and dtor +////////////////////////////////////////////////////////////////////////////// + +SocketAppender::SocketAppender(const tstring& host_, + unsigned short port_, const tstring& serverName_) +: host(host_), + port(port_), + serverName(serverName_) +{ + openSocket(); + initConnector (); +} + + + +SocketAppender::SocketAppender(const helpers::Properties & properties) + : Appender(properties), + port(9998) +{ + host = properties.getProperty( LOG4CPLUS_TEXT("host") ); + properties.getUInt (port, LOG4CPLUS_TEXT("port")); + serverName = properties.getProperty( LOG4CPLUS_TEXT("ServerName") ); + + openSocket(); + initConnector (); +} + + + +SocketAppender::~SocketAppender() +{ +#if ! defined (LOG4CPLUS_SINGLE_THREADED) + connector->terminate (); +#endif + + destructorImpl(); +} + + + +////////////////////////////////////////////////////////////////////////////// +// SocketAppender public methods +////////////////////////////////////////////////////////////////////////////// + +void +SocketAppender::close() +{ + helpers::getLogLog().debug( + LOG4CPLUS_TEXT("Entering SocketAppender::close()...")); + +#if ! defined (LOG4CPLUS_SINGLE_THREADED) + connector->terminate (); +#endif + + socket.close(); + closed = true; +} + + + +////////////////////////////////////////////////////////////////////////////// +// SocketAppender protected methods +////////////////////////////////////////////////////////////////////////////// + +void +SocketAppender::openSocket() +{ + if(!socket.isOpen()) { + socket = helpers::Socket(host, static_cast<unsigned short>(port)); + } +} + + +void +SocketAppender::initConnector () +{ +#if ! defined (LOG4CPLUS_SINGLE_THREADED) + connected = true; + connector = new ConnectorThread (*this); + connector->start (); +#endif +} + + +void +SocketAppender::append(const spi::InternalLoggingEvent& event) +{ +#if ! defined (LOG4CPLUS_SINGLE_THREADED) + if (! connected) + { + connector->trigger (); + return; + } + +#else + if(!socket.isOpen()) { + openSocket(); + if(!socket.isOpen()) { + helpers::getLogLog().error( + LOG4CPLUS_TEXT( + "SocketAppender::append()- Cannot connect to server")); + return; + } + } +#endif + + helpers::SocketBuffer buffer(LOG4CPLUS_MAX_MESSAGE_SIZE - sizeof(unsigned int)); + convertToBuffer (buffer, event, serverName); + helpers::SocketBuffer msgBuffer(LOG4CPLUS_MAX_MESSAGE_SIZE); + + msgBuffer.appendInt(static_cast<unsigned>(buffer.getSize())); + msgBuffer.appendBuffer(buffer); + + bool ret = socket.write(msgBuffer); + if (! ret) + { +#if ! defined (LOG4CPLUS_SINGLE_THREADED) + connected = false; + connector->trigger (); +#endif + } +} + + +///////////////////////////////////////////////////////////////////////////// +// namespace helpers methods +///////////////////////////////////////////////////////////////////////////// + +namespace helpers +{ + + +void +convertToBuffer(SocketBuffer & buffer, + const spi::InternalLoggingEvent& event, + const tstring& serverName) +{ + buffer.appendByte(LOG4CPLUS_MESSAGE_VERSION); +#ifndef UNICODE + buffer.appendByte(1); +#else + buffer.appendByte(2); +#endif + + buffer.appendString(serverName); + buffer.appendString(event.getLoggerName()); + buffer.appendInt(event.getLogLevel()); + buffer.appendString(event.getNDC()); + buffer.appendString(event.getMessage()); + buffer.appendString(event.getThread()); + buffer.appendInt( static_cast<unsigned int>(event.getTimestamp().sec()) ); + buffer.appendInt( static_cast<unsigned int>(event.getTimestamp().usec()) ); + buffer.appendString(event.getFile()); + buffer.appendInt(event.getLine()); + buffer.appendString(event.getFunction()); +} + + +spi::InternalLoggingEvent +readFromBuffer(SocketBuffer& buffer) +{ + unsigned char msgVersion = buffer.readByte(); + if(msgVersion != LOG4CPLUS_MESSAGE_VERSION) { + LogLog * loglog = LogLog::getLogLog(); + loglog->warn(LOG4CPLUS_TEXT("readFromBuffer() received socket message with an invalid version")); + } + + unsigned char sizeOfChar = buffer.readByte(); + + tstring serverName = buffer.readString(sizeOfChar); + tstring loggerName = buffer.readString(sizeOfChar); + LogLevel ll = buffer.readInt(); + tstring ndc = buffer.readString(sizeOfChar); + if(! serverName.empty ()) { + if(ndc.empty ()) { + ndc = serverName; + } + else { + ndc = serverName + LOG4CPLUS_TEXT(" - ") + ndc; + } + } + tstring message = buffer.readString(sizeOfChar); + tstring thread = buffer.readString(sizeOfChar); + long sec = buffer.readInt(); + long usec = buffer.readInt(); + tstring file = buffer.readString(sizeOfChar); + int line = buffer.readInt(); + tstring function = buffer.readString(sizeOfChar); + + // TODO: Pass MDC through. + spi::InternalLoggingEvent ev (loggerName, ll, ndc, + MappedDiagnosticContextMap (), message, thread, Time(sec, usec), file, + line); + ev.setFunction (function); + return ev; +} + + +} // namespace helpers + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socketbuffer.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socketbuffer.cxx new file mode 100644 index 000000000..fe8f61ec2 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/socketbuffer.cxx @@ -0,0 +1,275 @@ +// Module: Log4CPLUS +// File: socketbuffer.cxx +// Created: 5/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <cstring> +#include <limits> +#include <log4cplus/helpers/socketbuffer.h> +#include <log4cplus/helpers/loglog.h> + +#if !defined(_WIN32) +# include <netdb.h> +#else +# include <log4cplus/config/windowsh-inc.h> +#endif + +#if defined (LOG4CPLUS_HAVE_NETINET_IN_H) +#include <netinet/in.h> +#endif + + +namespace log4cplus { namespace helpers { + + +////////////////////////////////////////////////////////////////////////////// +// SocketBuffer ctors and dtor +////////////////////////////////////////////////////////////////////////////// + +SocketBuffer::SocketBuffer(std::size_t maxsize_) +: maxsize(maxsize_), + size(0), + pos(0), + buffer(new char[maxsize]) +{ +} + + +SocketBuffer::~SocketBuffer() +{ + delete [] buffer; +} + + +////////////////////////////////////////////////////////////////////////////// +// SocketBuffer methods +////////////////////////////////////////////////////////////////////////////// + +unsigned char +SocketBuffer::readByte() +{ + if(pos >= maxsize) { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::readByte()- end of buffer reached")); + return 0; + } + else if((pos + sizeof(unsigned char)) > maxsize) { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::readByte()- Attempt to read beyond end of buffer")); + return 0; + } + + unsigned char ret = static_cast<unsigned char>(buffer[pos]); + pos += sizeof(unsigned char); + + return ret; +} + + + +unsigned short +SocketBuffer::readShort() +{ + if(pos >= maxsize) { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::readShort()- end of buffer reached")); + return 0; + } + else if((pos + sizeof(unsigned short)) > maxsize) { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::readShort()- Attempt to read beyond end of buffer")); + return 0; + } + + unsigned short ret; + std::memcpy(&ret, buffer + pos, sizeof(ret)); + ret = ntohs(ret); + pos += sizeof(unsigned short); + + return ret; +} + + + +unsigned int +SocketBuffer::readInt() +{ + if(pos >= maxsize) { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::readInt()- end of buffer reached")); + return 0; + } + else if((pos + sizeof(unsigned int)) > maxsize) { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::readInt()- Attempt to read beyond end of buffer")); + return 0; + } + + unsigned int ret; + std::memcpy (&ret, buffer + pos, sizeof(ret)); + ret = ntohl(ret); + pos += sizeof(unsigned int); + + return ret; +} + + +tstring +SocketBuffer::readString(unsigned char sizeOfChar) +{ + std::size_t strlen = readInt(); + std::size_t bufferLen = strlen * sizeOfChar; + + if(strlen == 0) { + return tstring(); + } + if(pos > maxsize) { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::readString()- end of buffer reached")); + return tstring(); + } + + if((pos + bufferLen) > maxsize) { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::readString()- Attempt to read beyond end of buffer")); + bufferLen = (maxsize - 1) - pos; + strlen = bufferLen / sizeOfChar; + } + +#ifndef UNICODE + if(sizeOfChar == 1) { + tstring ret(&buffer[pos], strlen); + pos += strlen; + return ret; + } + else if(sizeOfChar == 2) { + tstring ret; + for(tstring::size_type i=0; i<strlen; ++i) { + unsigned short tmp = readShort(); + ret += static_cast<char>(tmp < 256 ? tmp : ' '); + } + return ret; + } + else { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::readString()- Invalid sizeOfChar!!!!")); + } + +#else /* UNICODE */ + if(sizeOfChar == 1) { + std::string ret(&buffer[pos], strlen); + pos += strlen; + return towstring(ret); + } + else if(sizeOfChar == 2) { + tstring ret; + for(tstring::size_type i=0; i<strlen; ++i) { + ret += static_cast<tchar>(readShort()); + } + return ret; + } + else { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::readString()- Invalid sizeOfChar!!!!")); + } +#endif + + return tstring(); +} + + + +void +SocketBuffer::appendByte(unsigned char val) +{ + if((pos + sizeof(unsigned char)) > maxsize) { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::appendByte()- Attempt to write beyond end of buffer")); + return; + } + + buffer[pos] = static_cast<char>(val); + pos += sizeof(unsigned char); + size = pos; +} + + + +void +SocketBuffer::appendShort(unsigned short val) +{ + if((pos + sizeof(unsigned short)) > maxsize) { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::appendShort()- Attempt to write beyond end of buffer")); + return; + } + + unsigned short s = htons(val); + std::memcpy(buffer + pos, &s, sizeof (s)); + pos += sizeof(s); + size = pos; +} + + + +void +SocketBuffer::appendInt(unsigned int val) +{ + if((pos + sizeof(unsigned int)) > maxsize) { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::appendInt()- Attempt to write beyond end of buffer")); + return; + } + + int i = htonl(val); + std::memcpy(buffer + pos, &i, sizeof (i)); + pos += sizeof(i); + size = pos; +} + + + +void +SocketBuffer::appendString(const tstring& str) +{ + std::size_t const strlen = str.length(); + static std::size_t const sizeOfChar = sizeof (tchar) == 1 ? 1 : 2; + + if((pos + sizeof(unsigned int) + strlen * sizeOfChar) > maxsize) + { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::appendString()-") + LOG4CPLUS_TEXT(" Attempt to write beyond end of buffer")); + return; + } + + appendInt(static_cast<unsigned>(strlen)); +#ifndef UNICODE + std::memcpy(&buffer[pos], str.data(), strlen); + pos += strlen; + size = pos; +#else + for(tstring::size_type i=0; i<str.length(); ++i) { + appendShort(static_cast<unsigned short>(str[i])); + } +#endif +} + + + +void +SocketBuffer::appendBuffer(const SocketBuffer& buf) +{ + if((pos + buf.getSize()) > maxsize) { + getLogLog().error(LOG4CPLUS_TEXT("SocketBuffer::appendBuffer()- Attempt to write beyond end of buffer")); + return; + } + + std::memcpy(&buffer[pos], buf.buffer, buf.getSize()); + pos += buf.getSize(); + size = pos; +} + + +} } // namespace log4cplus { namespace helpers { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/stringhelper-clocale.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/stringhelper-clocale.cxx new file mode 100644 index 000000000..24b58ac3c --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/stringhelper-clocale.cxx @@ -0,0 +1,153 @@ +// Copyright (C) 2010, Vaclav Haisman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/helpers/loglog.h> + +#include <cstdlib> +#include <cstring> +#include <cwchar> +#include <cassert> +#include <vector> + + +namespace log4cplus +{ + +namespace helpers +{ + + +void clear_mbstate (std::mbstate_t & mbs); + + +#if defined (LOG4CPLUS_WORKING_C_LOCALE) + +static +void +tostring_internal (std::string & result, wchar_t const * src, std::size_t size) +{ + std::vector<char> result_buf (MB_CUR_MAX); + + wchar_t const * src_it = src; + wchar_t const * const src_end_it = src + size; + + std::mbstate_t mbs; + clear_mbstate (mbs); + + result.clear (); + result.reserve (size + size / 3 + 1); + + while (src_it != src_end_it) + { + std::size_t ret = std::wcrtomb (&result_buf[0], *src_it, &mbs); + if (ret == static_cast<std::size_t>(-1)) + { + result.push_back ('?'); + clear_mbstate (mbs); + ++src_it; + } + else + { + result.append (result_buf.begin (), result_buf.begin () + ret); + ++src_it; + } + } +} + + +std::string +tostring (const std::wstring & src) +{ + std::string ret; + tostring_internal (ret, src.c_str (), src.size ()); + return ret; +} + + +std::string +tostring (wchar_t const * src) +{ + assert (src); + std::string ret; + tostring_internal (ret, src, std::wcslen (src)); + return ret; +} + + +static +void +towstring_internal (std::wstring & result, char const * src, std::size_t size) +{ + char const * src_it = src; + char const * const src_end_it = src + size; + + std::mbstate_t mbs; + clear_mbstate (mbs); + + result.clear (); + result.reserve (size); + + while (src_it != src_end_it) + { + std::size_t const n = size - (src - src_it); + wchar_t result_char; + std::size_t ret = std::mbrtowc (&result_char, src_it, n, &mbs); + if (ret > 0) + { + result.push_back (result_char); + src_it += ret; + } + else + { + result.push_back (ret == 0 ? L'\0' : L'?') ; + clear_mbstate (mbs); + ++src_it; + } + } +} + + +std::wstring +towstring (const std::string& src) +{ + std::wstring ret; + towstring_internal (ret, src.c_str (), src.size ()); + return ret; +} + + +std::wstring +towstring (char const * src) +{ + assert (src); + std::wstring ret; + towstring_internal (ret, src, std::strlen (src)); + return ret; +} + +#endif // LOG4CPLUS_WORKING_C_LOCALE + +} // namespace helpers + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/stringhelper-cxxlocale.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/stringhelper-cxxlocale.cxx new file mode 100644 index 000000000..579a1c54b --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/stringhelper-cxxlocale.cxx @@ -0,0 +1,230 @@ +// Copyright (C) 2010, Vaclav Haisman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/streams.h> + +#include <locale> +#include <iterator> +#include <algorithm> +#include <cstring> +#include <cwchar> +#include <cwctype> +#include <cctype> + +#include <cassert> +#include <vector> + + +namespace log4cplus +{ + +namespace helpers +{ + +void clear_mbstate (std::mbstate_t &); + +#ifdef LOG4CPLUS_WORKING_LOCALE + +static +void +towstring_internal (std::wstring & outstr, const char * src, std::size_t size, + std::locale const & loc) +{ + if (size == 0) + { + outstr.clear (); + return; + } + + typedef std::codecvt<wchar_t, char, std::mbstate_t> CodeCvt; + const CodeCvt & cdcvt = std::use_facet<CodeCvt>(loc); + std::mbstate_t state; + clear_mbstate (state); + + char const * from_first = src; + std::size_t const from_size = size; + char const * const from_last = from_first + from_size; + char const * from_next = from_first; + + std::vector<wchar_t> dest (from_size); + + wchar_t * to_first = &dest.front (); + std::size_t to_size = dest.size (); + wchar_t * to_last = to_first + to_size; + wchar_t * to_next = to_first; + + CodeCvt::result result; + std::size_t converted = 0; + while (true) + { + result = cdcvt.in ( + state, from_first, from_last, + from_next, to_first, to_last, + to_next); + // XXX: Even if only half of the input has been converted the + // in() method returns CodeCvt::ok. I think it should return + // CodeCvt::partial. + if ((result == CodeCvt::partial || result == CodeCvt::ok) + && from_next != from_last) + { + to_size = dest.size () * 2; + dest.resize (to_size); + converted = to_next - to_first; + to_first = &dest.front (); + to_last = to_first + to_size; + to_next = to_first + converted; + continue; + } + else if (result == CodeCvt::ok && from_next == from_last) + break; + else if (result == CodeCvt::error + && to_next != to_last && from_next != from_last) + { + clear_mbstate (state); + ++from_next; + from_first = from_next; + *to_next = L'?'; + ++to_next; + to_first = to_next; + } + else + break; + } + converted = to_next - &dest[0]; + + outstr.assign (dest.begin (), dest.begin () + converted); +} + + +std::wstring +towstring(const std::string& src) +{ + std::wstring ret; + towstring_internal (ret, src.c_str (), src.size (), std::locale ()); + return ret; +} + + +std::wstring +towstring(char const * src) +{ + std::wstring ret; + towstring_internal (ret, src, std::strlen (src), std::locale ()); + return ret; +} + + +static +void +tostring_internal (std::string & outstr, const wchar_t * src, std::size_t size, + std::locale const & loc) +{ + if (size == 0) + { + outstr.clear (); + return; + } + + typedef std::codecvt<wchar_t, char, std::mbstate_t> CodeCvt; + const CodeCvt & cdcvt = std::use_facet<CodeCvt>(loc); + std::mbstate_t state; + clear_mbstate (state); + + wchar_t const * from_first = src; + std::size_t const from_size = size; + wchar_t const * const from_last = from_first + from_size; + wchar_t const * from_next = from_first; + + std::vector<char> dest (from_size); + + char * to_first = &dest.front (); + std::size_t to_size = dest.size (); + char * to_last = to_first + to_size; + char * to_next = to_first; + + CodeCvt::result result; + std::size_t converted = 0; + while (from_next != from_last) + { + result = cdcvt.out ( + state, from_first, from_last, + from_next, to_first, to_last, + to_next); + // XXX: Even if only half of the input has been converted the + // in() method returns CodeCvt::ok with VC8. I think it should + // return CodeCvt::partial. + if ((result == CodeCvt::partial || result == CodeCvt::ok) + && from_next != from_last) + { + to_size = dest.size () * 2; + dest.resize (to_size); + converted = to_next - to_first; + to_first = &dest.front (); + to_last = to_first + to_size; + to_next = to_first + converted; + } + else if (result == CodeCvt::ok && from_next == from_last) + break; + else if (result == CodeCvt::error + && to_next != to_last && from_next != from_last) + { + clear_mbstate (state); + ++from_next; + from_first = from_next; + *to_next = '?'; + ++to_next; + to_first = to_next; + } + else + break; + } + converted = to_next - &dest[0]; + + outstr.assign (dest.begin (), dest.begin () + converted); +} + + +std::string +tostring(const std::wstring& src) +{ + std::string ret; + tostring_internal (ret, src.c_str (), src.size (), std::locale ()); + return ret; +} + + +std::string +tostring(wchar_t const * src) +{ + std::string ret; + tostring_internal (ret, src, std::wcslen (src), std::locale ()); + return ret; +} + + +#endif // LOG4CPLUS_WORKING_LOCALE + +} // namespace helpers + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/stringhelper-iconv.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/stringhelper-iconv.cxx new file mode 100644 index 000000000..ddc08ca1d --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/stringhelper-iconv.cxx @@ -0,0 +1,266 @@ +// Copyright (C) 2010, Vaclav Haisman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +#include <log4cplus/helpers/stringhelper.h> + +#if defined (LOG4CPLUS_WITH_ICONV) + +#ifdef LOG4CPLUS_HAVE_ICONV_H +#include <iconv.h> +#endif + +#include <stdexcept> +#include <iostream> +#include <sstream> +#include <cassert> +#include <cerrno> +#include <cstring> + + +// This is here because some compilers (Sun CC) think that there is a +// difference if the typedefs are not in an extern "C" block. +extern "C" +{ + + //! SUSv3 iconv() type. + typedef size_t (& iconv_func_type_1) (iconv_t cd, char * * inbuf, + size_t * inbytesleft, char * * outbuf, size_t * outbytesleft); + + + //! GNU iconv() type. + typedef size_t (& iconv_func_type_2) (iconv_t cd, const char * * inbuf, + size_t * inbytesleft, char * * outbuf, size_t * outbytesleft); + +} // extern "C" + + +namespace log4cplus +{ + +namespace helpers +{ + +namespace +{ + + +static iconv_t const iconv_error_handle = reinterpret_cast<iconv_t>(-1); + + +struct iconv_handle +{ + iconv_handle (char const * to, char const * from) + : handle (iconv_open (to, from)) + { + if (handle == iconv_error_handle) + { + std::ostringstream oss; + oss << "iconv_open failed: " << errno; + std::cerr << oss.str () << std::endl; + throw std::runtime_error (oss.str ().c_str ()); + } + } + + ~iconv_handle () + { + if (handle != iconv_error_handle) + { + int ret = iconv_close (handle); + if (ret == -1) + { + std::ostringstream oss; + oss << "iconv_close failed: " << errno; + std::cerr << oss.str () << std::endl; + throw std::runtime_error (oss.str ().c_str ()); + } + } + } + + size_t + call_iconv (iconv_func_type_1 iconv_func, char * * inbuf, + size_t * inbytesleft, char * * outbuf, size_t * outbytesleft) + { + return iconv_func (handle, inbuf, inbytesleft, outbuf, outbytesleft); + } + + size_t + call_iconv (iconv_func_type_2 iconv_func, char * * inbuf, + size_t * inbytesleft, char * * outbuf, size_t * outbytesleft) + { + return iconv_func (handle, const_cast<const char * *>(inbuf), + inbytesleft, outbuf, outbytesleft); + } + + size_t + do_iconv (char * * inbuf, size_t * inbytesleft, char * * outbuf, + size_t * outbytesleft) + { + return call_iconv (iconv, inbuf, inbytesleft, outbuf, outbytesleft); + } + + iconv_t handle; +}; + + +template <typename T> +struct question_mark; + + +template <> +struct question_mark<char> +{ + static char const value = '?'; +}; + + +template <> +struct question_mark<wchar_t> +{ + static wchar_t const value = L'?'; +}; + + +char const question_mark<char>::value; + + +wchar_t const question_mark<wchar_t>::value; + + +template <typename DestType, typename SrcType> +static +void +iconv_conv (std::basic_string<DestType> & result, char const * destenc, + SrcType const * src, std::size_t size, char const * srcenc) +{ + iconv_handle cvt (destenc, srcenc); + if (cvt.handle == iconv_error_handle) + { + // TODO: Better error handling. + result.resize (0); + return; + } + + typedef DestType outbuf_type; + typedef SrcType inbuf_type; + + std::size_t result_size = size + size / 3 + 1; + result.resize (result_size); + + char * inbuf = const_cast<char *>(reinterpret_cast<char const *>(src)); + std::size_t inbytesleft = size * sizeof (inbuf_type); + + char * outbuf = reinterpret_cast<char *>(&result[0]); + std::size_t outbytesleft = result_size * sizeof (outbuf_type); + + std::size_t res; + std::size_t const error_retval = static_cast<std::size_t>(-1); + + while (inbytesleft != 0) + { + res = cvt.do_iconv (&inbuf, &inbytesleft, &outbuf, &outbytesleft); + if (res == error_retval) + { + switch (errno) + { + case EILSEQ: + case EINVAL: + if (outbytesleft >= sizeof (outbuf_type)) + { + if (inbytesleft > 0) + { + ++inbuf; + inbytesleft -= sizeof (inbuf_type); + } + + *outbuf = question_mark<outbuf_type>::value; + ++outbuf; + outbytesleft -= sizeof (outbuf_type); + + continue; + } + + // Fall through. + + case E2BIG:; + // Fall through. + } + + std::size_t const outbuf_index = result_size; + result_size *= 2; + result.resize (result_size); + outbuf = reinterpret_cast<char *>(&result[0] + outbuf_index); + outbytesleft = (result_size - outbuf_index) * sizeof (outbuf_type); + } + else + result.resize (result_size - outbytesleft / sizeof (outbuf_type)); + } +} + + +} // namespace + + +std::string +tostring (const std::wstring & src) +{ + std::string ret; + iconv_conv (ret, "UTF-8", src.c_str (), src.size (), "WCHAR_T"); + return ret; +} + + +std::string +tostring (wchar_t const * src) +{ + assert (src); + std::string ret; + iconv_conv (ret, "UTF-8", src, std::wcslen (src), "WCHAR_T"); + return ret; +} + + +std::wstring +towstring (const std::string& src) +{ + std::wstring ret; + iconv_conv (ret, "WCHAR_T", src.c_str (), src.size (), "UTF-8"); + return ret; +} + + +std::wstring +towstring (char const * src) +{ + assert (src); + std::wstring ret; + iconv_conv (ret, "WCHAR_T", src, std::strlen (src), "UTF-8"); + return ret; +} + + +} // namespace helpers + +} // namespace log4cplus + +#endif // LOG4CPLUS_WITH_ICONV diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/stringhelper.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/stringhelper.cxx new file mode 100644 index 000000000..219e957da --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/stringhelper.cxx @@ -0,0 +1,216 @@ +// Module: Log4CPLUS +// File: stringhelper.cxx +// Created: 4/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/streams.h> +#include <log4cplus/internal/internal.h> + +#include <iterator> +#include <algorithm> +#include <cstring> +#include <cwchar> +#include <cwctype> +#include <cctype> +#include <cassert> + + +namespace log4cplus +{ + +namespace internal +{ + +log4cplus::tstring const empty_str; + +} // namespace internal + +} // namespace log4cplus + + +////////////////////////////////////////////////////////////////////////////// +// Global Methods +////////////////////////////////////////////////////////////////////////////// + +#if defined (UNICODE) && defined (LOG4CPLUS_ENABLE_GLOBAL_C_STRING_STREAM_INSERTER) + +log4cplus::tostream& +operator <<(log4cplus::tostream& stream, const char* str) +{ + return (stream << log4cplus::helpers::towstring(str)); +} + +#endif + + +namespace log4cplus +{ + +namespace helpers +{ + + +void +clear_mbstate (std::mbstate_t & mbs) +{ + // Initialize/clear mbstate_t type. + // XXX: This is just a hack that works. The shape of mbstate_t varies + // from single unsigned to char[128]. Without some sort of initialization + // the codecvt::in/out methods randomly fail because the initial state is + // random/invalid. + std::memset (&mbs, 0, sizeof (std::mbstate_t)); +} + + +#if defined (LOG4CPLUS_POOR_MANS_CHCONV) + +static +void +tostring_internal (std::string & ret, wchar_t const * src, std::size_t size) +{ + ret.resize(size); + for (std::size_t i = 0; i < size; ++i) + { + std::char_traits<wchar_t>::int_type src_int + = std::char_traits<wchar_t>::to_int_type (src[i]); + ret[i] = src_int <= 127 + ? std::char_traits<char>::to_char_type (src_int) + : '?'; + } +} + + +std::string +tostring(const std::wstring& src) +{ + std::string ret; + tostring_internal (ret, src.c_str (), src.size ()); + return ret; +} + + +std::string +tostring(wchar_t const * src) +{ + assert (src); + std::string ret; + tostring_internal (ret, src, std::wcslen (src)); + return ret; +} + + +static +void +towstring_internal (std::wstring & ret, char const * src, std::size_t size) +{ + ret.resize(size); + for (std::size_t i = 0; i < size; ++i) + { + std::char_traits<char>::int_type src_int + = std::char_traits<char>::to_int_type (src[i]); + ret[i] = src_int <= 127 + ? std::char_traits<wchar_t>::to_char_type (src_int) + : L'?'; + } +} + + +std::wstring +towstring(const std::string& src) +{ + std::wstring ret; + towstring_internal (ret, src.c_str (), src.size ()); + return ret; +} + + +std::wstring +towstring(char const * src) +{ + assert (src); + std::wstring ret; + towstring_internal (ret, src, std::strlen (src)); + return ret; +} + +#endif // LOG4CPLUS_POOR_MANS_CHCONV + + +namespace +{ + + +struct toupper_func +{ + tchar + operator () (tchar ch) const + { + return std::char_traits<tchar>::to_char_type ( +#ifdef UNICODE + std::towupper +#else + std::toupper +#endif + (std::char_traits<tchar>::to_int_type (ch))); + } +}; + + +struct tolower_func +{ + tchar + operator () (tchar ch) const + { + return std::char_traits<tchar>::to_char_type ( +#ifdef UNICODE + std::towlower +#else + std::tolower +#endif + (std::char_traits<tchar>::to_int_type (ch))); + } +}; + + +} // namespace + + +tstring +toUpper(const tstring& s) +{ + tstring ret; + std::transform(s.begin(), s.end(), std::back_inserter (ret), + toupper_func ()); + return ret; +} + + +tstring +toLower(const tstring& s) +{ + tstring ret; + std::transform(s.begin(), s.end(), std::back_inserter (ret), + tolower_func ()); + return ret; +} + + +} // namespace helpers + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/syncprims.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/syncprims.cxx new file mode 100644 index 000000000..b81af85da --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/syncprims.cxx @@ -0,0 +1,51 @@ +// Copyright (C) 2009-2010, Vaclav Haisman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <sstream> +#include <stdexcept> +#define LOG4CPLUS_ENABLE_SYNCPRIMS_PUB_IMPL +#include <log4cplus/thread/syncprims-pub-impl.h> + + +namespace log4cplus { namespace thread { + + +namespace impl +{ + + +LOG4CPLUS_EXPORT +void +syncprims_throw_exception (char const * const msg, char const * const file, + int line) +{ + std::ostringstream oss; + oss << file << ":" << line << msg; + throw std::runtime_error (oss.str ()); +} + + +} + + +} } // namespace log4cplus { namespace thread namespace impl { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/syslogappender.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/syslogappender.cxx new file mode 100644 index 000000000..6343df53c --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/syslogappender.cxx @@ -0,0 +1,425 @@ +// Module: Log4CPLUS +// File: syslogappender.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// Copyright 2001-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/syslogappender.h> +#include <log4cplus/streams.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/spi/loggingevent.h> +#include <log4cplus/internal/internal.h> +#include <log4cplus/internal/env.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <cstring> + +#if defined (LOG4CPLUS_HAVE_SYSLOG_H) +#include <syslog.h> + +#else // LOG4CPLUS_HAVE_SYSLOG_H + +// The following bits were derived from SUSv4 documentation and +// RFC5424 document. + +// priority codes +#define LOG_EMERG 0 +#define LOG_ALERT 1 +#define LOG_CRIT 2 +#define LOG_ERR 3 +#define LOG_WARNING 4 +#define LOG_NOTICE 5 +#define LOG_INFO 6 +#define LOG_DEBUG 7 + +// facility codes +#define LOG_KERN (0 << 3) +#define LOG_USER (1 << 3) +#define LOG_MAIL (2 << 3) +#define LOG_DAEMON (3 << 3) +#define LOG_AUTH (4 << 3) +#define LOG_SYSLOG (5 << 3) +#define LOG_LPR (6 << 3) +#define LOG_NEWS (7 << 3) +#define LOG_UUCP (8 << 3) +#define LOG_CRON (9 << 3) +#define LOG_AUTHPRIV (10 << 3) +#define LOG_FTP (11 << 3) +#define LOG_NTP (12 << 3) +#define LOG_SECURITY (13 << 3) +#define LOG_CONSOLE (14 << 3) +// (15 << 3) is missing here +#define LOG_LOCAL0 (16 << 3) +#define LOG_LOCAL1 (17 << 3) +#define LOG_LOCAL2 (18 << 3) +#define LOG_LOCAL3 (19 << 3) +#define LOG_LOCAL4 (20 << 3) +#define LOG_LOCAL5 (21 << 3) +#define LOG_LOCAL6 (22 << 3) +#define LOG_LOCAL7 (23 << 3) + +#endif // LOG4CPLUS_HAVE_SYSLOG_H + + +namespace log4cplus +{ + +namespace +{ + +static +const char* +useIdent (const std::string& string) +{ + if (string.empty ()) + return 0; + else + return string.c_str (); +} + + +#ifdef LOG_USER +int const fallback_facility = LOG_USER; + +#else +int const fallback_facility = 0; + +#endif + + +static +int +parseFacility (const tstring& text) +{ + if (text.empty ()) + return fallback_facility; +#ifdef LOG_AUTH + else if (text == LOG4CPLUS_TEXT ("auth")) + return LOG_AUTH; +#endif +#ifdef LOG_AUTHPRIV + else if (text == LOG4CPLUS_TEXT ("authpriv")) + return LOG_AUTHPRIV; +#endif +#ifdef LOG_CONSOLE + else if (text == LOG4CPLUS_TEXT ("console")) + return LOG_CONSOLE; +#endif +#ifdef LOG_CRON + else if (text == LOG4CPLUS_TEXT ("cron")) + return LOG_CRON; +#endif +#ifdef LOG_DAEMON + else if (text == LOG4CPLUS_TEXT ("daemon")) + return LOG_DAEMON; +#endif +#ifdef LOG_FTP + else if (text == LOG4CPLUS_TEXT ("ftp")) + return LOG_FTP; +#endif +#ifdef LOG_KERN + else if (text == LOG4CPLUS_TEXT ("kern")) + return LOG_KERN; +#endif +#ifdef LOG_LOCAL0 + else if (text == LOG4CPLUS_TEXT ("local0")) + return LOG_LOCAL0; +#endif +#ifdef LOG_LOCAL1 + else if (text == LOG4CPLUS_TEXT ("local1")) + return LOG_LOCAL1; +#endif +#ifdef LOG_LOCAL2 + else if (text == LOG4CPLUS_TEXT ("local2")) + return LOG_LOCAL2; +#endif +#ifdef LOG_LOCAL3 + else if (text == LOG4CPLUS_TEXT ("local3")) + return LOG_LOCAL3; +#endif +#ifdef LOG_LOCAL4 + else if (text == LOG4CPLUS_TEXT ("local4")) + return LOG_LOCAL4; +#endif +#ifdef LOG_LOCAL5 + else if (text == LOG4CPLUS_TEXT ("local5")) + return LOG_LOCAL5; +#endif +#ifdef LOG_LOCAL6 + else if (text == LOG4CPLUS_TEXT ("local6")) + return LOG_LOCAL6; +#endif +#ifdef LOG_LOCAL7 + else if (text == LOG4CPLUS_TEXT ("local7")) + return LOG_LOCAL7; +#endif +#ifdef LOG_LPR + else if (text == LOG4CPLUS_TEXT ("lpr")) + return LOG_LPR; +#endif +#ifdef LOG_MAIL + else if (text == LOG4CPLUS_TEXT ("mail")) + return LOG_MAIL; +#endif +#ifdef LOG_NEWS + else if (text == LOG4CPLUS_TEXT ("news")) + return LOG_NEWS; +#endif +#ifdef LOG_NTP + else if (text == LOG4CPLUS_TEXT ("ntp")) + return LOG_NTP; +#endif +#ifdef LOG_SECURITY + else if (text == LOG4CPLUS_TEXT ("security")) + return LOG_SECURITY; +#endif +#ifdef LOG_SYSLOG + else if (text == LOG4CPLUS_TEXT ("syslog")) + return LOG_SYSLOG; +#endif +#ifdef LOG_USER + else if (text == LOG4CPLUS_TEXT ("user")) + return LOG_USER; +#endif +#ifdef LOG_UUCP + else if (text == LOG4CPLUS_TEXT ("uucp")) + return LOG_UUCP; +#endif + else + { + // Unknown facility. + tstring msg (LOG4CPLUS_TEXT ("Unknown syslog facility: ")); + msg += text; + helpers::getLogLog ().error (msg); + + return fallback_facility; + } +} + + +} // namespace + + +/////////////////////////////////////////////////////////////////////////////// +// SysLogAppender ctors and dtor +/////////////////////////////////////////////////////////////////////////////// + +#if defined (LOG4CPLUS_HAVE_SYSLOG_H) +SysLogAppender::SysLogAppender(const tstring& id) + : ident(id) + , facility (0) + , appendFunc (&SysLogAppender::appendLocal) + , port (0) + // Store std::string form of ident as member of SysLogAppender so + // the address of the c_str() result remains stable for openlog & + // co to use even if we use wstrings. + , identStr(LOG4CPLUS_TSTRING_TO_STRING (id) ) + , hostname (helpers::getHostname (true)) +{ + ::openlog(useIdent(identStr), 0, 0); +} + +#endif + + +SysLogAppender::SysLogAppender(const helpers::Properties & properties) + : Appender(properties) + , facility (0) + , appendFunc (0) + , port (0) + , hostname (helpers::getHostname (true)) +{ + ident = properties.getProperty( LOG4CPLUS_TEXT("ident") ); + facility = parseFacility ( + helpers::toLower ( + properties.getProperty (LOG4CPLUS_TEXT ("facility")))); + identStr = LOG4CPLUS_TSTRING_TO_STRING (ident); + + host = properties.getProperty (LOG4CPLUS_TEXT ("host")); + if (host.empty ()) + { +#if defined (LOG4CPLUS_HAVE_SYSLOG_H) + appendFunc = &SysLogAppender::appendLocal; + ::openlog(useIdent(identStr), 0, 0); + +#else + helpers::getLogLog ().error ( + LOG4CPLUS_TEXT ("SysLogAppender") + LOG4CPLUS_TEXT ("- local syslog not available"), true); + +#endif + } + else + { + if (! properties.getInt (port, LOG4CPLUS_TEXT ("port"))) + port = 514; + + appendFunc = &SysLogAppender::appendRemote; + syslogSocket = helpers::Socket (host, port, true); + } +} + + +SysLogAppender::SysLogAppender(const tstring& id, const tstring & h, + int p, const tstring & f) + : ident (id) + , facility (parseFacility (helpers::toLower (f))) + , appendFunc (&SysLogAppender::appendRemote) + , host (h) + , port (p) + , syslogSocket (host, port, true) + // Store std::string form of ident as member of SysLogAppender so + // the address of the c_str() result remains stable for openlog & + // co to use even if we use wstrings. + , identStr(LOG4CPLUS_TSTRING_TO_STRING (id) ) + , hostname (helpers::getHostname (true)) +{ } + + +SysLogAppender::~SysLogAppender() +{ + destructorImpl(); +} + + + +/////////////////////////////////////////////////////////////////////////////// +// SysLogAppender public methods +/////////////////////////////////////////////////////////////////////////////// + +void +SysLogAppender::close() +{ + helpers::getLogLog().debug( + LOG4CPLUS_TEXT("Entering SysLogAppender::close()...")); + thread::MutexGuard guard (access_mutex); + + if (host.empty ()) + { +#if defined (LOG4CPLUS_HAVE_SYSLOG_H) + ::closelog(); +#endif + } + else + syslogSocket.close (); + + closed = true; +} + + + +/////////////////////////////////////////////////////////////////////////////// +// SysLogAppender protected methods +/////////////////////////////////////////////////////////////////////////////// + +int +SysLogAppender::getSysLogLevel(const LogLevel& ll) const +{ + if(ll < INFO_LOG_LEVEL /* || ll < DEBUG_LOG_LEVEL*/) { + return LOG_DEBUG; + } + else if(ll < WARN_LOG_LEVEL) { + return LOG_INFO; + } + else if(ll < ERROR_LOG_LEVEL) { + return LOG_WARNING; + } + else if(ll < FATAL_LOG_LEVEL) { + return LOG_ERR; + } + else if(ll == FATAL_LOG_LEVEL) { + return LOG_CRIT; + } + + return LOG_ALERT; // ll > FATAL_LOG_LEVEL +} + + +// This method does not need to be locked since it is called by +// doAppend() which performs the locking +void +SysLogAppender::append(const spi::InternalLoggingEvent& event) +{ + (this->*appendFunc) (event); +} + + +#if defined (LOG4CPLUS_HAVE_SYSLOG_H) +void +SysLogAppender::appendLocal(const spi::InternalLoggingEvent& event) +{ + int const level = getSysLogLevel(event.getLogLevel()); + internal::appender_sratch_pad & appender_sp = internal::get_appender_sp (); + detail::clear_tostringstream (appender_sp.oss); + layout->formatAndAppend(appender_sp.oss, event); + appender_sp.str = appender_sp.oss.str (); + ::syslog(facility | level, "%s", + LOG4CPLUS_TSTRING_TO_STRING(appender_sp.str).c_str()); +} + +#endif + + +tstring const SysLogAppender::remoteTimeFormat ( + LOG4CPLUS_TEXT ("%Y-%m-%dT%H:%M:%S.%qZ")); + + +void +SysLogAppender::appendRemote(const spi::InternalLoggingEvent& event) +{ + int const level = getSysLogLevel(event.getLogLevel()); + internal::appender_sratch_pad & appender_sp = internal::get_appender_sp (); + detail::clear_tostringstream (appender_sp.oss); + + appender_sp.oss + // PRI + << LOG4CPLUS_TEXT ('<') << (level | facility) << LOG4CPLUS_TEXT ('>') + // VERSION + << 1 + // TIMESTAMP + << LOG4CPLUS_TEXT (' ') + << event.getTimestamp ().getFormattedTime (remoteTimeFormat, true) + // HOSTNAME + << LOG4CPLUS_TEXT (' ') << hostname + // APP-NAME + << LOG4CPLUS_TEXT (' ') << ident + // PROCID + << LOG4CPLUS_TEXT (' ') << internal::get_process_id () + // MSGID + << LOG4CPLUS_TEXT (' ') << event.getLoggerName () + // STRUCTURED-DATA + // no structured data, it could be whole MDC + << LOG4CPLUS_TEXT (" - "); + + // MSG + layout->formatAndAppend (appender_sp.oss, event); + + LOG4CPLUS_TSTRING_TO_STRING (appender_sp.oss.str ()) + .swap (appender_sp.chstr); + + bool ret = syslogSocket.write (appender_sp.chstr); + if (! ret) + { + helpers::getLogLog ().warn ( + LOG4CPLUS_TEXT ("SysLogAppender::appendRemote") + LOG4CPLUS_TEXT ("- socket write failed")); + syslogSocket = helpers::Socket (host, port, true); + } +} + + +} // namespace log4cplus diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/threads.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/threads.cxx new file mode 100644 index 000000000..3e77ea069 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/threads.cxx @@ -0,0 +1,431 @@ +// Module: Log4CPLUS +// File: threads.cxx +// Created: 6/2001 +// Author: Tad E. Smith +// +// +// Copyright 2001-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/config.hxx> + +#include <exception> +#include <ostream> +#include <cerrno> + +#ifdef LOG4CPLUS_HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif + +#ifdef LOG4CPLUS_HAVE_SYS_SYSCALL_H +#include <sys/syscall.h> +#endif + +#ifdef LOG4CPLUS_HAVE_ERRNO_H +#include <errno.h> +#endif + +#ifdef LOG4CPLUS_HAVE_UNISTD_H +#include <unistd.h> +#endif + +#if defined(LOG4CPLUS_USE_PTHREADS) +# include <pthread.h> +# include <sched.h> +# include <signal.h> +#elif defined (LOG4CPLUS_USE_WIN32_THREADS) +# include <process.h> +#endif +#include <log4cplus/config/windowsh-inc.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <log4cplus/tstring.h> +#include <log4cplus/internal/cygwin-win32.h> +#include <log4cplus/streams.h> + +#ifndef LOG4CPLUS_SINGLE_THREADED + +#include <log4cplus/thread/threads.h> +#include <log4cplus/thread/impl/threads-impl.h> +#include <log4cplus/thread/impl/tls.h> +#include <log4cplus/ndc.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/helpers/timehelper.h> +#include <log4cplus/internal/internal.h> + +#endif // LOG4CPLUS_SINGLE_THREADED + + +namespace log4cplus { namespace thread { + +LOG4CPLUS_EXPORT +void +blockAllSignals() +{ +#if defined (LOG4CPLUS_USE_PTHREADS) + // Block all signals. + sigset_t signal_set; + sigfillset (&signal_set); + pthread_sigmask (SIG_BLOCK, &signal_set, 0); +#endif +} + + +LOG4CPLUS_EXPORT +void +yield() +{ +#if defined(LOG4CPLUS_USE_PTHREADS) + sched_yield(); +#elif defined(_WIN32) + if (! SwitchToThread ()) + Sleep (0); +#endif +} + + +LOG4CPLUS_EXPORT +log4cplus::tstring const & +getCurrentThreadName() +{ +#if ! defined (LOG4CPLUS_SINGLE_THREADED) + log4cplus::tstring & name = log4cplus::internal::get_thread_name_str (); + if (name.empty ()) + { + log4cplus::tostringstream tmp; + tmp << impl::getCurrentThreadId (); + tmp.str ().swap (name); + } +#else + static log4cplus::tstring const name (LOG4CPLUS_TEXT ("single")); +#endif + + return name; +} + + +namespace +{ + + +static +bool +get_current_thread_name_alt (log4cplus::tostream * s) +{ + log4cplus::tostream & os = *s; + +#if defined (LOG4CPLUS_USE_PTHREADS) && defined (__linux__) \ + && defined (LOG4CPLUS_HAVE_GETTID) + pid_t tid = syscall (SYS_gettid); + os << tid; + +#elif defined (__CYGWIN__) + unsigned long tid = cygwin::get_current_win32_thread_id (); + os << tid; + +#else + os << getCurrentThreadName (); + +#endif + + return true; +} + + +} // namespace + + +LOG4CPLUS_EXPORT +log4cplus::tstring const & +getCurrentThreadName2() +{ +#if ! defined (LOG4CPLUS_SINGLE_THREADED) + log4cplus::tstring & name = log4cplus::internal::get_thread_name2_str (); + if (name.empty ()) + { + log4cplus::tostringstream tmp; + get_current_thread_name_alt (&tmp); + tmp.str ().swap (name); + } + +#else + static log4cplus::tstring const name (getCurrentThreadName ()); + +#endif + + return name; +} + + +} } // namespace log4cplus { namespace thread { + + +#ifndef LOG4CPLUS_SINGLE_THREADED + +namespace +{ + +# ifdef LOG4CPLUS_USE_PTHREADS +extern "C" void* threadStartFunc(void * param) +# elif defined(LOG4CPLUS_USE_WIN32_THREADS) +static unsigned WINAPI threadStartFunc(void * param) +# endif +{ + return log4cplus::thread::impl::ThreadStart::threadStartFuncWorker (param); +} + +} // namespace + + +namespace log4cplus { namespace thread { namespace impl { + + +#if defined(LOG4CPLUS_USE_PTHREADS) +void* +ThreadStart::threadStartFuncWorker(void * arg) +#elif defined(LOG4CPLUS_USE_WIN32_THREADS) +unsigned +ThreadStart::threadStartFuncWorker(void * arg) +#endif +{ + blockAllSignals (); + helpers::LogLog * loglog = helpers::LogLog::getLogLog(); + if (! arg) + loglog->error(LOG4CPLUS_TEXT("threadStartFunc()- arg is NULL")); + else + { + Thread * ptr = static_cast<Thread *>(arg); + ThreadPtr thread(ptr); + + // Decrease reference count increased by Thread::start(). + ptr->removeReference (); + + try + { + thread->run(); + } + catch(std::exception const & e) + { + tstring err = LOG4CPLUS_TEXT("threadStartFunc()- run() terminated with an exception: "); + err += LOG4CPLUS_C_STR_TO_TSTRING(e.what()); + loglog->warn(err); + } + catch(...) + { + loglog->warn(LOG4CPLUS_TEXT("threadStartFunc()- run() terminated with an exception.")); + } + + thread::MutexGuard guard (thread->access_mutex); + thread->flags &= ~Thread::fRUNNING; + } + + threadCleanup (); + + return 0; +} + + +Thread::Thread() + : flags (0) +#if defined(LOG4CPLUS_USE_WIN32_THREADS) + , handle (INVALID_HANDLE_VALUE) + , thread_id (0) +#else + , handle () +#endif +{ +} + + +Thread::~Thread() +{ +#if defined(LOG4CPLUS_USE_PTHREADS) + if ((flags & fJOINED) == 0) + pthread_detach (handle); + +#elif defined(LOG4CPLUS_USE_WIN32_THREADS) + if (handle != INVALID_HANDLE_VALUE) + ::CloseHandle (handle); + +#endif +} + + +void +Thread::start() +{ + flags |= fRUNNING; + + // Increase reference count here. It will be lowered by the running + // thread itself. + addReference (); + +#if defined(LOG4CPLUS_USE_PTHREADS) + if (pthread_create(&handle, NULL, threadStartFunc, this) ) + { + removeReference (); + flags &= ~fRUNNING; + log4cplus::helpers::LogLog::getLogLog ()->error ( + LOG4CPLUS_TEXT ("Thread creation was not successful"), true); + } +#elif defined(LOG4CPLUS_USE_WIN32_THREADS) + HANDLE h = InterlockedExchangePointer (&handle, INVALID_HANDLE_VALUE); + if (h != INVALID_HANDLE_VALUE) + ::CloseHandle (h); + + h = reinterpret_cast<HANDLE>( + ::_beginthreadex (0, 0, threadStartFunc, this, 0, &thread_id)); + if (! h) + { + removeReference (); + flags &= ~fRUNNING; + log4cplus::helpers::LogLog::getLogLog ()->error ( + LOG4CPLUS_TEXT ("Thread creation was not successful"), true); + } + h = InterlockedExchangePointer (&handle, h); + assert (h == INVALID_HANDLE_VALUE); +#endif +} + + +bool +Thread::isRunning() const +{ + thread::MutexGuard guard (access_mutex); + return (flags & fRUNNING) != 0; +} + + +os_id_type +Thread::getThreadId () const +{ +#if defined(LOG4CPLUS_USE_PTHREADS) + return handle; +#elif defined(LOG4CPLUS_USE_WIN32_THREADS) + return thread_id; +#endif +} + + +os_handle_type +Thread::getThreadHandle () const +{ + return handle; +} + + +void +Thread::join () +{ +#if defined(LOG4CPLUS_USE_PTHREADS) + pthread_join (handle, 0); +#elif defined(LOG4CPLUS_USE_WIN32_THREADS) + ::WaitForSingleObject (handle, INFINITE); +#endif + flags |= fJOINED; +} + + +} // namespace impl { + + +// +// +// + +ThreadImplBase::~ThreadImplBase () +{ } + + +// +// +// + + +namespace +{ + + +class ThreadImpl + : public impl::Thread +{ +public: + ThreadImpl () + : abs_thread (0) + { } + + virtual ~ThreadImpl () + { } + + virtual + void + run () + { + abs_thread->run (); + } + + void + set_abs_thread (AbstractThread * at) + { + abs_thread = at; + } + +protected: + AbstractThread * abs_thread; +}; + + +} // namespace + + +// +// +// + +AbstractThread::AbstractThread () + : thread (new ThreadImpl) +{ + static_cast<ThreadImpl *>(thread.get ())->set_abs_thread (this); +} + + +bool +AbstractThread::isRunning() const +{ + return static_cast<ThreadImpl *>(thread.get ())->isRunning (); +} + + +void +AbstractThread::start() +{ + static_cast<ThreadImpl *>(thread.get ())->start (); +} + + +void +AbstractThread::join () const +{ + static_cast<ThreadImpl *>(thread.get ())->join (); +} + + +AbstractThread::~AbstractThread() +{ } + + +} } // namespace log4cplus { namespace thread { + + +#endif // LOG4CPLUS_SINGLE_THREADED diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/timehelper.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/timehelper.cxx new file mode 100644 index 000000000..e19d7778e --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/timehelper.cxx @@ -0,0 +1,524 @@ +// Module: Log4CPLUS +// File: timehelper.cxx +// Created: 4/2003 +// Author: Tad E. Smith +// +// +// Copyright 2003-2010 Tad E. Smith +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/helpers/timehelper.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/streams.h> +#include <log4cplus/helpers/stringhelper.h> +#include <log4cplus/internal/internal.h> + +#include <algorithm> +#include <vector> +#include <iomanip> +#include <cassert> +#include <cerrno> +#if defined (UNICODE) +#include <cwchar> +#endif + +#if defined (LOG4CPLUS_HAVE_SYS_TYPES_H) +#include <sys/types.h> +#endif + +#if defined(LOG4CPLUS_HAVE_SYS_TIME_H) +#include <sys/time.h> +#endif + +#if defined (LOG4CPLUS_HAVE_SYS_TIMEB_H) +#include <sys/timeb.h> +#endif + +#if defined(LOG4CPLUS_HAVE_GMTIME_R) && !defined(LOG4CPLUS_SINGLE_THREADED) +#define LOG4CPLUS_NEED_GMTIME_R +#endif + +#if defined(LOG4CPLUS_HAVE_LOCALTIME_R) && !defined(LOG4CPLUS_SINGLE_THREADED) +#define LOG4CPLUS_NEED_LOCALTIME_R +#endif + + +namespace log4cplus { namespace helpers { + +const int ONE_SEC_IN_USEC = 1000000; + +using std::mktime; +using std::gmtime; +using std::localtime; +#if defined (UNICODE) +using std::wcsftime; +#else +using std::strftime; +#endif + + +////////////////////////////////////////////////////////////////////////////// +// Time ctors +////////////////////////////////////////////////////////////////////////////// + +Time::Time() + : tv_sec(0) + , tv_usec(0) +{ +} + + +Time::Time(time_t tv_sec_, long tv_usec_) + : tv_sec(tv_sec_) + , tv_usec(tv_usec_) +{ + assert (tv_usec < ONE_SEC_IN_USEC); +} + + +Time::Time(time_t time) + : tv_sec(time) + , tv_usec(0) +{ +} + + +Time +Time::gettimeofday() +{ +#if defined (LOG4CPLUS_HAVE_CLOCK_GETTIME) + struct timespec ts; + int res = clock_gettime (CLOCK_REALTIME, &ts); + assert (res == 0); + if (res != 0) + LogLog::getLogLog ()->error ( + LOG4CPLUS_TEXT("clock_gettime() has failed"), true); + + return Time (ts.tv_sec, ts.tv_nsec / 1000); + +#elif defined(LOG4CPLUS_HAVE_GETTIMEOFDAY) + struct timeval tp; + ::gettimeofday(&tp, 0); + + return Time(tp.tv_sec, tp.tv_usec); + +#elif defined (_WIN32) + FILETIME ft; + GetSystemTimeAsFileTime (&ft); + + typedef unsigned __int64 uint64_type; + uint64_type st100ns + = uint64_type (ft.dwHighDateTime) << 32 + | ft.dwLowDateTime; + + // Number of 100-ns intervals between UNIX epoch and Windows system time + // is 116444736000000000. + uint64_type const offset = uint64_type (116444736) * 1000 * 1000 * 1000; + uint64_type fixed_time = st100ns - offset; + + return Time (fixed_time / (10 * 1000 * 1000), + fixed_time % (10 * 1000 * 1000) / 10); + +#elif defined(LOG4CPLUS_HAVE_FTIME) + struct timeb tp; + ftime(&tp); + + return Time(tp.time, tp.millitm * 1000); + +#else +#warning "Time::gettimeofday()- low resolution timer: gettimeofday and ftime unavailable" + return Time(::time(0), 0); +#endif +} + + +////////////////////////////////////////////////////////////////////////////// +// Time methods +////////////////////////////////////////////////////////////////////////////// + +time_t +Time::setTime(tm* t) +{ + time_t time = helpers::mktime(t); + if (time != -1) + tv_sec = time; + + return time; +} + + +time_t +Time::getTime() const +{ + return tv_sec; +} + + +void +Time::gmtime(tm* t) const +{ + time_t clock = tv_sec; +#if defined (LOG4CPLUS_HAVE_GMTIME_S) && defined (_MSC_VER) + gmtime_s (t, &clock); +#elif defined (LOG4CPLUS_HAVE_GMTIME_S) && defined (__BORLANDC__) + gmtime_s (&clock, t); +#elif defined (LOG4CPLUS_NEED_GMTIME_R) + gmtime_r (&clock, t); +#else + tm* tmp = helpers::gmtime(&clock); + *t = *tmp; +#endif +} + + +void +Time::localtime(tm* t) const +{ + time_t clock = tv_sec; +#ifdef LOG4CPLUS_NEED_LOCALTIME_R + ::localtime_r(&clock, t); +#else + tm* tmp = helpers::localtime(&clock); + *t = *tmp; +#endif +} + + +namespace +{ + + +static log4cplus::tstring const padding_zeros[4] = +{ + log4cplus::tstring (LOG4CPLUS_TEXT("000")), + log4cplus::tstring (LOG4CPLUS_TEXT("00")), + log4cplus::tstring (LOG4CPLUS_TEXT("0")), + log4cplus::tstring (LOG4CPLUS_TEXT("")) +}; + + +static log4cplus::tstring const uc_q_padding_zeros[4] = +{ + log4cplus::tstring (LOG4CPLUS_TEXT(".000")), + log4cplus::tstring (LOG4CPLUS_TEXT(".00")), + log4cplus::tstring (LOG4CPLUS_TEXT(".0")), + log4cplus::tstring (LOG4CPLUS_TEXT(".")) +}; + + +static +void +build_q_value (log4cplus::tstring & q_str, long tv_usec) +{ + convertIntegerToString(q_str, tv_usec / 1000); + std::size_t const len = q_str.length(); + if (len <= 2) + q_str.insert (0, padding_zeros[q_str.length()]); +} + + +static +void +build_uc_q_value (log4cplus::tstring & uc_q_str, long tv_usec, + log4cplus::tstring & tmp) +{ + build_q_value (uc_q_str, tv_usec); + + convertIntegerToString(tmp, tv_usec % 1000); + std::size_t const usecs_len = tmp.length(); + tmp.insert (0, usecs_len <= 3 + ? uc_q_padding_zeros[usecs_len] : uc_q_padding_zeros[3]); + uc_q_str.append (tmp); +} + + +} // namespace + + +log4cplus::tstring +Time::getFormattedTime(const log4cplus::tstring& fmt_orig, bool use_gmtime) const +{ + if (fmt_orig.empty () || fmt_orig[0] == 0) + return log4cplus::tstring (); + + tm time; + + if (use_gmtime) + gmtime(&time); + else + localtime(&time); + + enum State + { + TEXT, + PERCENT_SIGN + }; + + internal::gft_scratch_pad & gft_sp = internal::get_gft_scratch_pad (); + gft_sp.reset (); + + gft_sp.fmt.assign (fmt_orig); + gft_sp.ret.reserve (static_cast<std::size_t>(gft_sp.fmt.size () * 1.35)); + State state = TEXT; + + // Walk the format string and process all occurences of %q and %Q. + + for (log4cplus::tstring::const_iterator fmt_it = gft_sp.fmt.begin (); + fmt_it != gft_sp.fmt.end (); ++fmt_it) + { + switch (state) + { + case TEXT: + { + if (*fmt_it == LOG4CPLUS_TEXT ('%')) + state = PERCENT_SIGN; + else + gft_sp.ret.push_back (*fmt_it); + } + break; + + case PERCENT_SIGN: + { + switch (*fmt_it) + { + case LOG4CPLUS_TEXT ('q'): + { + if (! gft_sp.q_str_valid) + { + build_q_value (gft_sp.q_str, tv_usec); + gft_sp.q_str_valid = true; + } + gft_sp.ret.append (gft_sp.q_str); + state = TEXT; + } + break; + + case LOG4CPLUS_TEXT ('Q'): + { + if (! gft_sp.uc_q_str_valid) + { + build_uc_q_value (gft_sp.uc_q_str, tv_usec, gft_sp.tmp); + gft_sp.uc_q_str_valid = true; + } + gft_sp.ret.append (gft_sp.uc_q_str); + state = TEXT; + } + break; + + // Windows do not support %s format specifier + // (seconds since epoch). + case LOG4CPLUS_TEXT ('s'): + { + if (! gft_sp.s_str_valid) + { + convertIntegerToString (gft_sp.s_str, tv_sec); + gft_sp.s_str_valid = true; + } + gft_sp.ret.append (gft_sp.s_str); + state = TEXT; + } + break; + + default: + { + gft_sp.ret.push_back (LOG4CPLUS_TEXT ('%')); + gft_sp.ret.push_back (*fmt_it); + state = TEXT; + } + } + } + break; + } + } + + // Finally call strftime/wcsftime to format the rest of the string. + + gft_sp.ret.swap (gft_sp.fmt); + std::size_t buffer_size = gft_sp.fmt.size () + 1; + std::size_t len; + + // Limit how far can the buffer grow. This is necessary so that we + // catch bad format string. Some implementations of strftime() signal + // both too small buffer and invalid format string by returning 0 + // without changing errno. + std::size_t const buffer_size_max + = (std::max) (static_cast<std::size_t>(1024), buffer_size * 16); + + do + { + gft_sp.buffer.resize (buffer_size); + errno = 0; +#ifdef UNICODE + len = helpers::wcsftime(&gft_sp.buffer[0], buffer_size, + gft_sp.fmt.c_str(), &time); +#else + len = helpers::strftime(&gft_sp.buffer[0], buffer_size, + gft_sp.fmt.c_str(), &time); +#endif + if (len == 0) + { + int const eno = errno; + buffer_size *= 2; + if (buffer_size > buffer_size_max) + { + LogLog::getLogLog ()->error ( + LOG4CPLUS_TEXT("Error in strftime(): ") + + convertIntegerToString (eno), true); + } + } + } + while (len == 0); + + return tstring (gft_sp.buffer.begin (), gft_sp.buffer.begin () + len); +} + + +Time& +Time::operator+=(const Time& rhs) +{ + tv_sec += rhs.tv_sec; + tv_usec += rhs.tv_usec; + + if(tv_usec > ONE_SEC_IN_USEC) { + ++tv_sec; + tv_usec -= ONE_SEC_IN_USEC; + } + + return *this; +} + + +Time& +Time::operator-=(const Time& rhs) +{ + tv_sec -= rhs.tv_sec; + tv_usec -= rhs.tv_usec; + + if(tv_usec < 0) { + --tv_sec; + tv_usec += ONE_SEC_IN_USEC; + } + + return *this; +} + + +Time& +Time::operator/=(long rhs) +{ + long rem_secs = static_cast<long>(tv_sec % rhs); + tv_sec /= rhs; + + tv_usec /= rhs; + tv_usec += static_cast<long>((rem_secs * ONE_SEC_IN_USEC) / rhs); + + return *this; +} + + +Time& +Time::operator*=(long rhs) +{ + long new_usec = tv_usec * rhs; + long overflow_sec = new_usec / ONE_SEC_IN_USEC; + tv_usec = new_usec % ONE_SEC_IN_USEC; + + tv_sec *= rhs; + tv_sec += overflow_sec; + + return *this; +} + + +////////////////////////////////////////////////////////////////////////////// +// Time globals +////////////////////////////////////////////////////////////////////////////// + + +const Time +operator+(const Time& lhs, const Time& rhs) +{ + return Time(lhs) += rhs; +} + + +const Time +operator-(const Time& lhs, const Time& rhs) +{ + return Time(lhs) -= rhs; +} + + +const Time +operator/(const Time& lhs, long rhs) +{ + return Time(lhs) /= rhs; +} + + +const Time +operator*(const Time& lhs, long rhs) +{ + return Time(lhs) *= rhs; +} + + +bool +operator<(const Time& lhs, const Time& rhs) +{ + return ( (lhs.sec() < rhs.sec()) + || ( (lhs.sec() == rhs.sec()) + && (lhs.usec() < rhs.usec())) ); +} + + +bool +operator<=(const Time& lhs, const Time& rhs) +{ + return ((lhs < rhs) || (lhs == rhs)); +} + + +bool +operator>(const Time& lhs, const Time& rhs) +{ + return ( (lhs.sec() > rhs.sec()) + || ( (lhs.sec() == rhs.sec()) + && (lhs.usec() > rhs.usec())) ); +} + + +bool +operator>=(const Time& lhs, const Time& rhs) +{ + return ((lhs > rhs) || (lhs == rhs)); +} + + +bool +operator==(const Time& lhs, const Time& rhs) +{ + return ( lhs.sec() == rhs.sec() + && lhs.usec() == rhs.usec()); +} + + +bool +operator!=(const Time& lhs, const Time& rhs) +{ + return !(lhs == rhs); +} + + +} } // namespace log4cplus { namespace helpers { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/tls.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/tls.cxx new file mode 100644 index 000000000..2f8bc017d --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/tls.cxx @@ -0,0 +1,40 @@ +// Copyright (C) 2010, Vaclav Haisman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <log4cplus/thread/impl/tls.h> + + +namespace log4cplus { namespace thread { namespace impl { + + +#if defined (LOG4CPLUS_SINGLE_THREADED) + +//! This is intentionally allocated using freestore and leaked. The +//! amount is small (so far only 1 length vector). This is to avoid +//! initialization order fiasco. +std::vector<tls_value_type> * tls_single_threaded_values; + +#endif + + +} } } // namespace log4cplus { namespace thread { namespace impl { diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/version.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/version.cxx new file mode 100644 index 000000000..8f848d717 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/version.cxx @@ -0,0 +1,37 @@ +// Copyright (C) 2010, Vaclav Haisman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <log4cplus/version.h> + + +namespace log4cplus +{ + +#if ! defined (LOG4CPLUS_VERSION_STR_SUFFIX) +#define LOG4CPLUS_VERSION_STR_SUFFIX "-RC5" +#endif + +unsigned const version = LOG4CPLUS_VERSION; +char const versionStr[] = LOG4CPLUS_VERSION_STR LOG4CPLUS_VERSION_STR_SUFFIX; + +} diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/win32consoleappender.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/win32consoleappender.cxx new file mode 100644 index 000000000..8afbd43b3 --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/win32consoleappender.cxx @@ -0,0 +1,182 @@ +// Copyright (C) 2009-2010, Vaclav Haisman. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modifica- +// tion, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- +// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +#include <log4cplus/config.hxx> + +#if defined(_WIN32) && defined (LOG4CPLUS_HAVE_WIN32_CONSOLE) +#include <log4cplus/config/windowsh-inc.h> +#include <log4cplus/win32consoleappender.h> +#include <log4cplus/helpers/loglog.h> +#include <log4cplus/helpers/property.h> +#include <log4cplus/thread/syncprims-pub-impl.h> +#include <log4cplus/streams.h> +#include <sstream> + + +namespace log4cplus +{ + + +Win32ConsoleAppender::Win32ConsoleAppender (bool allocConsole) + : alloc_console (allocConsole) +{ } + + +Win32ConsoleAppender::Win32ConsoleAppender ( + helpers::Properties const & properties) + : Appender (properties) + , alloc_console (true) +{ + properties.getBool (alloc_console, LOG4CPLUS_TEXT ("AllocConsole")); +} + + +Win32ConsoleAppender::~Win32ConsoleAppender () +{ + destructorImpl(); +} + + +void +Win32ConsoleAppender::close () +{ + closed = true; +} + + +void +Win32ConsoleAppender::append (spi::InternalLoggingEvent const & event) +{ + if (alloc_console) + // We ignore the return value here. If we already have a console, + // it will fail. + AllocConsole (); + + HANDLE const console_out = GetStdHandle (STD_OUTPUT_HANDLE); + if (console_out == INVALID_HANDLE_VALUE) + { + helpers::getLogLog ().error ( + LOG4CPLUS_TEXT ("Win32ConsoleAppender::append") + LOG4CPLUS_TEXT ("- Unable to get STD_OUTPUT_HANDLE.")); + return; + } + + DWORD const handle_type = GetFileType (console_out); + if (handle_type == FILE_TYPE_UNKNOWN && GetLastError () != NO_ERROR) + { + helpers::getLogLog ().error ( + LOG4CPLUS_TEXT ("Win32ConsoleAppender::append") + LOG4CPLUS_TEXT ("- Error retrieving handle type.")); + return; + } + + tstring & str = formatEvent (event); + std::size_t const str_len = str.size (); + const tchar * s = str.c_str (); + DWORD mode; + + if (handle_type == FILE_TYPE_CHAR && GetConsoleMode (console_out, &mode)) + // It seems that we have real console handle here. We can use + // WriteConsole() directly. + write_console (console_out, s, str_len); + else + // It seems that console is redirected. + write_handle (console_out, s, str_len); +} + + +void +Win32ConsoleAppender::write_handle (void * outvoid, tchar const * s, + std::size_t str_len) +{ + HANDLE out = static_cast<HANDLE>(outvoid); +#if defined (UNICODE) + std::wstring wstr (s, str_len); + std::string str (helpers::tostring (wstr)); + str_len = str.size (); + char const * const cstr = str.c_str (); + +#else + char const * const cstr = s; + +#endif + + DWORD const total_to_write = static_cast<DWORD>(str_len); + DWORD total_written = 0; + + do + { + DWORD const to_write = total_to_write - total_written; + DWORD written = 0; + + BOOL ret = WriteFile (out, cstr + total_written, to_write, &written, + 0); + if (! ret) + { + helpers::getLogLog ().error ( + LOG4CPLUS_TEXT ("Win32ConsoleAppender::write_handle") + LOG4CPLUS_TEXT ("- WriteFile has failed.")); + return; + } + + total_written += written; + } + while (total_written != total_to_write); +} + + +void +Win32ConsoleAppender::write_console (void * console_void, tchar const * s, + std::size_t str_len) +{ + HANDLE console_out = static_cast<HANDLE>(console_void); + DWORD const total_to_write = static_cast<DWORD>(str_len); + DWORD total_written = 0; + + do + { + DWORD const to_write + = (std::min<DWORD>) (64*1024 - 1, total_to_write - total_written); + DWORD written = 0; + + BOOL ret = WriteConsole (console_out, s + total_written, to_write, + &written, 0); + if (! ret) + { + helpers::getLogLog ().error ( + LOG4CPLUS_TEXT ("Win32ConsoleAppender::write_console") + LOG4CPLUS_TEXT ("- WriteConsole has failed.")); + return; + } + + total_written += written; + } + while (total_written != total_to_write); +} + + + +} // namespace log4cplus + +#endif diff --git a/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/win32debugappender.cxx b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/win32debugappender.cxx new file mode 100644 index 000000000..b83e0f6be --- /dev/null +++ b/SDL_Core/src/thirdPartyLibs/logger/log4cplus-1.1.0/src/win32debugappender.cxx @@ -0,0 +1,87 @@ +// Module: Log4CPLUS +// File: win32debugappender.cxx +// Created: 12/2003 +// Author: Eduardo Francos, Odalio SARL +// +// +// Copyright 2003-2010 Odalio SARL +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <log4cplus/config.hxx> +#if defined (LOG4CPLUS_HAVE_OUTPUTDEBUGSTRING) + +#include <log4cplus/config/windowsh-inc.h> +#include <log4cplus/win32debugappender.h> +#include <log4cplus/internal/internal.h> +#include <log4cplus/thread/syncprims-pub-impl.h> + + +namespace log4cplus +{ + + +/////////////////////////////////////////////////////////////////////////////// +// Win32DebugAppender ctors and dtor +/////////////////////////////////////////////////////////////////////////////// + +Win32DebugAppender::Win32DebugAppender() +{ +} + + +Win32DebugAppender::Win32DebugAppender( + const helpers::Properties& properties) + : Appender(properties) +{ +} + + + +Win32DebugAppender::~Win32DebugAppender() +{ + destructorImpl(); +} + + + +/////////////////////////////////////////////////////////////////////////////// +// Win32DebugAppender public methods +/////////////////////////////////////////////////////////////////////////////// + +void +Win32DebugAppender::close() +{ + closed = true; +} + + + +/////////////////////////////////////////////////////////////////////////////// +// Win32DebugAppender protected methods +/////////////////////////////////////////////////////////////////////////////// + +// This method does not need to be locked since it is called by +// doAppend() which performs the locking +void +Win32DebugAppender::append(const spi::InternalLoggingEvent& event) +{ + const tchar * s = formatEvent (event).c_str(); + ::OutputDebugString(s); +} + + +} // namespace log4cplus + + +#endif // LOG4CPLUS_HAVE_OUTPUTDEBUGSTRING |