Browse Source

[3513] added static getVersion for log

Francis Dupont 10 years ago
parent
commit
e6586db00d

+ 7 - 1
src/lib/log/logger.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011, 2015  Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -50,6 +50,12 @@ Logger::~Logger() {
     loggerptr_ = 0;
 }
 
+// Get Version
+std::string
+Logger::getVersion() {
+    return (LoggerImpl::getVersion());
+}
+
 // Get Name of Logger
 
 std::string

+ 4 - 1
src/lib/log/logger.h

@@ -1,4 +1,4 @@
-// Copyright (C) 2011, 2014  Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011, 2014, 2015  Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -200,6 +200,9 @@ public:
     /// \brief Destructor
     virtual ~Logger();
 
+    /// \brief Version
+    static std::string getVersion();
+
     /// \brief The formatter used to replace placeholders
     typedef isc::log::Formatter<Logger> Formatter;
 

+ 12 - 1
src/lib/log/logger_impl.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2011,2014-2015  Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011, 2014-2015  Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -19,10 +19,12 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <cstring>
+#include <sstream>
 #include <boost/lexical_cast.hpp>
 #include <boost/static_assert.hpp>
 #include <boost/algorithm/string.hpp>
 
+#include <log4cplus/version.h>
 #include <log4cplus/configurator.h>
 #include <log4cplus/loggingmacros.h>
 
@@ -84,6 +86,15 @@ LoggerImpl::~LoggerImpl() {
     delete sync_;
 }
 
+/// \brief Version
+std::string
+LoggerImpl::getVersion() {
+    std::ostringstream ver;
+    ver << "log4plus ";
+    ver << log4cplus::versionStr;
+    return (ver.str());
+}
+
 // Set the severity for logging.
 void
 LoggerImpl::setSeverity(isc::log::Severity severity, int dbglevel) {

+ 5 - 1
src/lib/log/logger_impl.h

@@ -1,4 +1,4 @@
-// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011, 2015  Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -77,6 +77,10 @@ public:
     virtual ~LoggerImpl();
 
 
+    /// \brief Version
+    static std::string getVersion();
+
+
     /// \brief Get the full name of the logger (including the root name)
     virtual std::string getName() {
         return (name_);

+ 5 - 0
src/lib/log/tests/logger_unittest.cc

@@ -48,6 +48,11 @@ public:
     }
 };
 
+// Check version
+
+TEST_F(LoggerTest, Version) {
+    EXPECT_NO_THROW(Logger::getVersion());
+}
 
 // Checks that the logger is named correctly.