]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- removed blocxx (fate #313242)
authorArvin Schnell <aschnell@suse.de>
Tue, 12 Jun 2012 08:17:23 +0000 (10:17 +0200)
committerArvin Schnell <aschnell@suse.de>
Tue, 12 Jun 2012 08:17:23 +0000 (10:17 +0200)
LIBVERSION
VERSION
configure.in
package/snapper.changes
snapper.spec.in
snapper/Log.cc
snapper/Log.h
snapper/Logger.cc [new file with mode: 0644]
snapper/Logger.h [new file with mode: 0644]
snapper/Makefile.am

index bc80560fad66ca670bdfbd1e5c973a024d4d0325..dc1e644a1014338ad0ca67b5c0bfbd2402e761ee 100644 (file)
@@ -1 +1 @@
-1.5.0
+1.6.0
diff --git a/VERSION b/VERSION
index 7c1886bb9f472af88c02b1f7e1d940132bdf5795..2cfabea2f1e6e353e6999e9b2508d971fdbbef0f 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.0.10
+0.0.11
index 44c4d77268c14f50abde9ac37e63fe8a8e24e2a2..0852183818eb70e736d86acea820250e15754960 100644 (file)
@@ -25,12 +25,6 @@ AM_PATH_PYTHON
 
 AC_PREFIX_DEFAULT(/usr)
 
-dnl Check for blocxx
-AC_CHECK_LIB(blocxx, main,
-  AC_SUBST([LIBBLOCXX], ["-lblocxx"])
-    AC_DEFINE([HAVE_LIBBLOCXX], [1],
-      [Define if you have libblocxx]))
-
 dnl Automake 1.11 enables silent compilation
 dnl Disable it by "configure --disable-silent-rules" or "make V=1"
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
index aa0044914580d9d265a7dd464d127482b32b780b..92b9a4cf87b69f4daa51ab662ef805a66ab87075 100644 (file)
@@ -1,3 +1,9 @@
+-------------------------------------------------------------------
+Tue Jun 12 10:07:08 CEST 2012 - aschnell@suse.de
+
+- removed blocxx (fate #313242)
+- 0.0.11
+
 -------------------------------------------------------------------
 Thu Mar 15 10:56:40 CET 2012 - aschnell@suse.de
 
index 03c50a51d601661a2b31750dc3cf7d10f83c501b..3e45e424075125b518705ca808ca8613ee2a950c 100644 (file)
@@ -27,12 +27,9 @@ Patch1:              no-readonly.diff
 Prefix:                /usr
 BuildRequires: boost-devel doxygen gcc-c++ libtool libxml2-devel
 BuildRequires: python-devel swig
-%if 0%{?suse_version}
-BuildRequires: libblocxx-devel
-%if 0%{?suse_version} >= 1210
+%if (0%{?suse_version} && 0%{?suse_version} >= 1210)
 BuildRequires: libzypp(plugin:commit)
 %endif
-%endif
 Requires:      libsnapper@LIBVERSION_MAJOR@ = %version
 %if 0%{?suse_version}
 Recommends:    cron logrotate snapper-zypp-plugin
@@ -140,9 +137,6 @@ Authors:
 %package -n libsnapper-devel
 Requires:      libsnapper@LIBVERSION_MAJOR@ = %version
 Requires:      gcc-c++ libstdc++-devel boost-devel libxml2-devel
-%if 0%{?suse_version}
-Requires:      blocxx-devel
-%endif
 Summary:       Header files and documentation for libsnapper
 Group:         Development/Languages/C and C++
 
index edaee4aa31eedcd6f97be51424385112a8e85555..66d4f5daf8c6cd66f1f3c6ec02f8c134b27d1835 100644 (file)
  */
 
 
-#include <pwd.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <libxml/tree.h>
-#include <string>
-
-#include "config.h"
-
-#ifdef HAVE_LIBBLOCXX
-#include <blocxx/AppenderLogger.hpp>
-#include <blocxx/FileAppender.hpp>
-#include <blocxx/Logger.hpp>
-#include <blocxx/LogMessage.hpp>
-#endif
-
 #include "snapper/Log.h"
 #include "snapper/AppUtil.h"
 
@@ -43,113 +28,11 @@ namespace snapper
 {
     using namespace std;
 
-#ifdef HAVE_LIBBLOCXX
-
-    using namespace blocxx;
-
-    static const String component = "libsnapper";
-
-#else
-
-    string filename;
-
-#endif
-
-
-    void createLogger(const string& name, const string& logpath, const string& logfile)
-    {
-#ifdef HAVE_LIBBLOCXX
-
-       try
-       {
-           if (logpath != "NULL" && logfile != "NULL")
-           {
-               String nm = name.c_str();
-               LoggerConfigMap configItems;
-               LogAppenderRef logApp;
-               if (logpath != "STDERR" && logfile != "STDERR" &&
-                   logpath != "SYSLOG" && logfile != "SYSLOG")
-               {
-                   String StrKey;
-                   String StrPath;
-                   StrKey.format("log.%s.location", name.c_str());
-                   StrPath = (logpath + "/" + logfile).c_str();
-                   configItems[StrKey] = StrPath;
-                   logApp =
-                       LogAppender::createLogAppender(nm, LogAppender::ALL_COMPONENTS,
-                                                      LogAppender::ALL_CATEGORIES,
-                                                      "%d %-5p %c(%P) %F(%M):%L - %m",
-                                                      LogAppender::TYPE_FILE,
-                                                      configItems);
-               }
-               else if (logpath == "STDERR" && logfile == "STDERR")
-               {
-                   logApp =
-                       LogAppender::createLogAppender(nm, LogAppender::ALL_COMPONENTS,
-                                                      LogAppender::ALL_CATEGORIES,
-                                                      "%d %-5p %c(%P) %F(%M):%L - %m",
-                                                      LogAppender::TYPE_STDERR,
-                                                      configItems);
-               }
-               else
-               {
-                   logApp =
-                       LogAppender::createLogAppender(nm, LogAppender::ALL_COMPONENTS,
-                                                      LogAppender::ALL_CATEGORIES,
-                                                      "%d %-5p %c(%P) %F(%M):%L - %m",
-                                                      LogAppender::TYPE_SYSLOG,
-                                                      configItems);
-               }
-
-               LogAppender::setDefaultLogAppender(logApp);
-           }
-       }
-       catch (const LoggerException& e)
-       {
-       }
-
-#else
-
-       filename = logpath + "/" + logfile;
-
-#endif
-    }
-
 
     bool
     testLogLevel(LogLevel level)
     {
-#ifdef HAVE_LIBBLOCXX
-
-       try
-       {
-           ELogLevel curLevel = LogAppender::getCurrentLogAppender()->getLogLevel();
-
-           switch (level)
-           {
-               case DEBUG:
-                   return false; // curLevel >= E_DEBUG_LEVEL;
-               case MILESTONE:
-                   return curLevel >= E_INFO_LEVEL;
-               case WARNING:
-                   return curLevel >= E_WARNING_LEVEL;
-               case ERROR:
-                   return curLevel >= E_ERROR_LEVEL;
-               default:
-                   return curLevel >= E_FATAL_ERROR_LEVEL;
-           }
-       }
-       catch (const LoggerException& e)
-       {
-       }
-
-       return false;
-
-#else
-
-       return level != DEBUG;
-
-#endif
+       return callLogQuery(level, "libsnapper");
     }
 
 
@@ -175,133 +58,8 @@ namespace snapper
     logStreamClose(LogLevel level, const char* file, unsigned line, const char* func,
                   ostringstream* stream)
     {
-#ifdef HAVE_LIBBLOCXX
-
-       ELogLevel curLevel = LogAppender::getCurrentLogAppender()->getLogLevel();
-       String category;
-
-       switch (level)
-       {
-           case DEBUG:
-               if (curLevel >= E_DEBUG_LEVEL)
-                   category = Logger::STR_DEBUG_CATEGORY;
-               break;
-           case MILESTONE:
-               if (curLevel >= E_INFO_LEVEL)
-                   category = Logger::STR_INFO_CATEGORY;
-               break;
-           case WARNING:
-               if (curLevel >= E_WARNING_LEVEL)
-                   category = Logger::STR_WARNING_CATEGORY;
-               break;
-           case ERROR:
-               if (curLevel >= E_ERROR_LEVEL)
-                   category = Logger::STR_ERROR_CATEGORY;
-               break;
-           default:
-               if (curLevel >= E_FATAL_ERROR_LEVEL)
-                   category = Logger::STR_FATAL_CATEGORY;
-               break;
-       }
-
-       if (!category.empty())
-       {
-           try
-           {
-               string tmp = stream->str();
-
-               string::size_type pos1 = 0;
-
-               while (true)
-               {
-                   string::size_type pos2 = tmp.find('\n', pos1);
-
-                   if (pos2 != string::npos || pos1 != tmp.length())
-                       LogAppender::getCurrentLogAppender()->logMessage(LogMessage(component, category,
-                                                                                   String(tmp.substr(pos1, pos2 - pos1)),
-                                                                                   file, line, func));
-
-                   if (pos2 == string::npos)
-                       break;
-
-                   pos1 = pos2 + 1;
-               }
-           }
-           catch (const LoggerException& e)
-           {
-           }
-       }
-
-#else
-
-       static const char* ln[4] = { "DEB", "MIL", "WAR", "ERR" };
-
-       string prefix = sformat("%s %s libsnapper(%d) %s(%s):%d", datetime(time(0), false, true).c_str(),
-                               ln[level], getpid(), file, func, line);
-
-       FILE* f = fopen(filename.c_str(), "a");
-
-       string tmp = stream->str();
-
-       string::size_type pos1 = 0;
-
-       while (true)
-       {
-           string::size_type pos2 = tmp.find('\n', pos1);
-
-           if (pos2 != string::npos || pos1 != tmp.length())
-               fprintf(f, "%s - %s\n", prefix.c_str(), tmp.substr(pos1, pos2 - pos1).c_str());
-
-           if (pos2 == string::npos)
-               break;
-
-           pos1 = pos2 + 1;
-       }
-
-       fclose(f);
-
-#endif
-
+       callLogDo(level, "libsnapper", file, line, func, stream->str());
        delete stream;
     }
 
-
-    void
-    xml_error_func(void* ctx, const char* msg, ...)
-    {
-    }
-
-    xmlGenericErrorFunc xml_error_func_ptr = &xml_error_func;
-
-
-    void initDefaultLogger()
-    {
-       string path;
-       string file;
-
-       if (geteuid())
-       {
-           struct passwd* pw = getpwuid(geteuid());
-           if (pw)
-           {
-               path = pw->pw_dir;
-               file = "snapper.log";
-           }
-           else
-           {
-               path = "/";
-               file = "snapper.log";
-           }
-       }
-       else
-       {
-           path = "/var/log";
-           file = "snapper.log";
-       }
-
-       createLogger("default", path, file);
-
-       initGenericErrorDefaultFunc(&xml_error_func_ptr);
-    }
-
 }
index 374ab5698f10a612f31b7a65c1f1b09629259a8a..9e41142878ed2124877fb72c692b465de9402612 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2004-2011] Novell, Inc.
+ * Copyright (c) [2004-2012] Novell, Inc.
  *
  * All Rights Reserved.
  *
@@ -24,7 +24,8 @@
 #define SNAPPER_LOG_H
 
 #include <sstream>
-#include <string>
+
+#include "Logger.h"
 
 
 namespace snapper
@@ -32,10 +33,6 @@ namespace snapper
     using std::string;
 
 
-    enum LogLevel { DEBUG, MILESTONE, WARNING, ERROR };
-
-    void createLogger(const string& name, const string& logpath, const string& logfile);
-
     bool testLogLevel(LogLevel level);
 
     void prepareLogStream(std::ostringstream& stream);
@@ -45,8 +42,6 @@ namespace snapper
     void logStreamClose(LogLevel level, const char* file, unsigned line,
                        const char* func, std::ostringstream*);
 
-    void initDefaultLogger();
-
 #define y2deb(op) y2log_op(snapper::DEBUG, __FILE__, __LINE__, __FUNCTION__, op)
 #define y2mil(op) y2log_op(snapper::MILESTONE, __FILE__, __LINE__, __FUNCTION__, op)
 #define y2war(op) y2log_op(snapper::WARNING, __FILE__, __LINE__, __FUNCTION__, op)
diff --git a/snapper/Logger.cc b/snapper/Logger.cc
new file mode 100644 (file)
index 0000000..3000a59
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) [2004-2012] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include <pwd.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <libxml/tree.h>
+#include <string>
+
+#include "config.h"
+
+#include "snapper/Log.h"
+#include "snapper/AppUtil.h"
+
+
+namespace snapper
+{
+    using namespace std;
+
+
+    string filename = "/var/log/snapper.log";
+
+    LogDo log_do = NULL;
+
+    LogQuery log_query = NULL;
+
+
+    void
+    setLogDo(LogDo new_log_do)
+    {
+       log_do = new_log_do;
+    }
+
+
+    void
+    setLogQuery(LogQuery new_log_query)
+    {
+       log_query = new_log_query;
+    }
+
+
+    static void
+    simple_log_do(LogLevel level, const char* component, const char* file, int line,
+                 const char* func, const string& text)
+    {
+       static const char* ln[4] = { "DEB", "MIL", "WAR", "ERR" };
+
+       string prefix = sformat("%s %s libsnapper(%d) %s(%s):%d", datetime(time(0), false, true).c_str(),
+                               ln[level], getpid(), file, func, line);
+
+       FILE* f = fopen(filename.c_str(), "a");
+       if (f)
+       {
+           string tmp = text;
+
+           string::size_type pos1 = 0;
+
+           while (true)
+           {
+               string::size_type pos2 = tmp.find('\n', pos1);
+
+               if (pos2 != string::npos || pos1 != tmp.length())
+                   fprintf(f, "%s - %s\n", prefix.c_str(), tmp.substr(pos1, pos2 - pos1).c_str());
+
+               if (pos2 == string::npos)
+                   break;
+
+               pos1 = pos2 + 1;
+           }
+
+           fclose(f);
+       }
+    }
+
+
+    static bool
+    simple_log_query(LogLevel level, const char* component)
+    {
+       return level != DEBUG;
+    }
+
+
+    void
+    callLogDo(LogLevel level, const char* component, const char* file, int line,
+             const char* func, const string& text)
+    {
+       if (log_do)
+           (log_do)(level, component, file, line, func, text);
+       else
+           simple_log_do(level, component, file, line, func, text);
+    }
+
+
+    bool
+    callLogQuery(LogLevel level, const char* component)
+    {
+       if (log_query)
+           return (log_query)(level, component);
+       else
+           return simple_log_query(level, component);
+    }
+
+
+    void
+    xml_error_func(void* ctx, const char* msg, ...)
+    {
+    }
+
+    xmlGenericErrorFunc xml_error_func_ptr = &xml_error_func;
+
+
+    void
+    initDefaultLogger()
+    {
+       filename = "/var/log/snapper.log";
+
+       if (geteuid())
+       {
+           struct passwd* pw = getpwuid(geteuid());
+           if (pw)
+           {
+               filename = string(pw->pw_dir) + "/.snapper.log";
+           }
+       }
+
+       initGenericErrorDefaultFunc(&xml_error_func_ptr);
+    }
+
+}
diff --git a/snapper/Logger.h b/snapper/Logger.h
new file mode 100644 (file)
index 0000000..99d10fc
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) [2011-2012] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef SNAPPER_LOGGER_H
+#define SNAPPER_LOGGER_H
+
+#include <string>
+
+
+namespace snapper
+{
+    using std::string;
+
+
+    enum LogLevel { DEBUG, MILESTONE, WARNING, ERROR };
+
+    /*
+     * Called function should be able to split content at newlines.
+     */
+    typedef void (*LogDo)(LogLevel level, const char* component, const char* file, int line,
+                         const char* func, const string& content);
+
+    typedef bool (*LogQuery)(LogLevel level, const char* component);
+
+    void setLogDo(LogDo log_do);
+
+    void setLogQuery(LogQuery log_query);
+
+    void callLogDo(LogLevel level, const char* component, const char* file, int line,
+                  const char* func, const string& text);
+
+    bool callLogQuery(LogLevel level, const char* component);
+
+    void initDefaultLogger();
+
+}
+
+#endif
index f6fd7a367320b40a20e817c984055802ddd58777..6a528fe31daba3ac7032cdc7974c7bbc9579f6e3 100644 (file)
@@ -17,6 +17,7 @@ libsnapper_la_SOURCES =                                       \
        Enum.cc                 Enum.h                  \
        AppUtil.cc              AppUtil.h               \
        Log.cc                  Log.h                   \
+       Logger.cc               Logger.h                \
        Compare.cc              Compare.h               \
        SystemCmd.cc            SystemCmd.h             \
        AsciiFile.cc            AsciiFile.h             \
@@ -27,7 +28,7 @@ libsnapper_la_SOURCES =                                       \
        SnapperDefines.h
 
 libsnapper_la_LDFLAGS = -version-info @LIBVERSION_INFO@
-libsnapper_la_LIBADD = @LIBBLOCXX@ -lxml2 -lz -lm
+libsnapper_la_LIBADD = -lxml2 -lz -lm
 
 pkgincludedir = $(includedir)/snapper
 
@@ -37,5 +38,6 @@ pkginclude_HEADERS =                                  \
        Snapshot.h                                      \
        File.h                                          \
        Comparison.h                                    \
-       Exception.h
+       Exception.h                                     \
+       Logger.h