From 5b54cb385ae426fca9ef38153a40b0036eba6f4f Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Thu, 29 Jan 2015 10:17:10 +0100 Subject: [PATCH] Move logging and macros to utils Just moves code. I will think about appling this. Change-Id: I6e6e21a9144f548697acc0f959e7aa2338831121 --- src/signature/CMakeLists.txt | 2 ++ src/signature/logging.h | 30 ---------------- src/signature/signature_data.h | 2 +- src/signature/signature_parser.cc | 4 +-- src/signature/signature_parser.h | 2 +- src/signature/signature_validator.cc | 2 +- src/signature/signature_validator.h | 2 +- src/signature/signature_xmlsec_adaptor.cc | 2 +- src/utils/logging.h | 55 ++++++++++++++++++++++++++++++ src/{signature/marcos.h => utils/macros.h} | 6 ++-- 10 files changed, 67 insertions(+), 40 deletions(-) delete mode 100644 src/signature/logging.h create mode 100644 src/utils/logging.h rename src/{signature/marcos.h => utils/macros.h} (79%) diff --git a/src/signature/CMakeLists.txt b/src/signature/CMakeLists.txt index 6ef981c..a8fbdc1 100644 --- a/src/signature/CMakeLists.txt +++ b/src/signature/CMakeLists.txt @@ -15,6 +15,8 @@ APPLY_PKG_CONFIG(${TARGET_LIBNAME_SIGNATURE} PUBLIC XMLSEC1_DEPS Boost ) +# Target in-package deps +TARGET_LINK_LIBRARIES(${TARGET_LIBNAME_SIGNATURE} PUBLIC ${TARGET_LIBNAME_UTILS}) # Extra SET_TARGET_PROPERTIES(${TARGET_LIBNAME_SIGNATURE} PROPERTIES VERSION ${VERSION}) diff --git a/src/signature/logging.h b/src/signature/logging.h deleted file mode 100644 index 199a14f..0000000 --- a/src/signature/logging.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef SIGNATURE_LOGGING_H_ -#define SIGNATURE_LOGGING_H_ - -#include -#include - -// TODO(tiwanek): Logging... - -namespace detail { - -class LogCatcher { - public: - LogCatcher() { } - void operator&(const std::ostream& str) const { - // TODO(tiwanek): this cast is error-prone - fix it - std::cerr << static_cast(&str)->str() - << std::endl; - } -}; - -} // namespace detail - -#define LOG(LEVEL) \ - ::detail::LogCatcher() & std::ostringstream() << "[" << #LEVEL << "] " \ - -#endif // SIGNATURE_LOGGING_H_ diff --git a/src/signature/signature_data.h b/src/signature/signature_data.h index 3046008..b6c5430 100644 --- a/src/signature/signature_data.h +++ b/src/signature/signature_data.h @@ -16,7 +16,7 @@ #include #include -#include "signature/marcos.h" +#include "utils/macros.h" namespace common_installer { namespace signature { diff --git a/src/signature/signature_parser.cc b/src/signature/signature_parser.cc index 749c0c8..cf3bdf6 100644 --- a/src/signature/signature_parser.cc +++ b/src/signature/signature_parser.cc @@ -21,8 +21,8 @@ #include #include -#include "signature/logging.h" -#include "signature/marcos.h" +#include "utils/logging.h" +#include "utils/macros.h" namespace { const char kExpectedXmlns[] = "http://www.w3.org/2000/09/xmldsig#"; diff --git a/src/signature/signature_parser.h b/src/signature/signature_parser.h index 96bad1d..299e945 100644 --- a/src/signature/signature_parser.h +++ b/src/signature/signature_parser.h @@ -12,7 +12,7 @@ #include -#include "signature/marcos.h" +#include "utils/macros.h" #include "signature/signature_data.h" namespace common_installer { diff --git a/src/signature/signature_validator.cc b/src/signature/signature_validator.cc index 2b30d28..882d800 100644 --- a/src/signature/signature_validator.cc +++ b/src/signature/signature_validator.cc @@ -16,7 +16,7 @@ #include #include -#include "signature/logging.h" +#include "utils/logging.h" #include "signature/signature_data.h" #include "signature/signature_parser.h" #include "signature/signature_xmlsec_adaptor.h" diff --git a/src/signature/signature_validator.h b/src/signature/signature_validator.h index de292bd..824951c 100644 --- a/src/signature/signature_validator.h +++ b/src/signature/signature_validator.h @@ -12,7 +12,7 @@ #include -#include "signature/marcos.h" +#include "utils/macros.h" namespace common_installer { namespace signature { diff --git a/src/signature/signature_xmlsec_adaptor.cc b/src/signature/signature_xmlsec_adaptor.cc index e905fad..4e37960 100644 --- a/src/signature/signature_xmlsec_adaptor.cc +++ b/src/signature/signature_xmlsec_adaptor.cc @@ -34,7 +34,7 @@ #include #include -#include "signature/logging.h" +#include "utils/logging.h" namespace bai = boost::archive::iterators; namespace bf = boost::filesystem; diff --git a/src/utils/logging.h b/src/utils/logging.h new file mode 100644 index 0000000..58c254d --- /dev/null +++ b/src/utils/logging.h @@ -0,0 +1,55 @@ +// Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#ifndef UTILS_LOGGING_H_ +#define UTILS_LOGGING_H_ + +#include +#include +#include + +namespace utils { + +enum class LogLevel { + LOG_ERROR, + LOG_WARNING, + LOG_INFO, + LOG_DEBUG, +}; + +template struct LogTag; +template<> struct LogTag { + static constexpr const char* value = "\033[0;31m[ERROR] \033[0m"; +}; +template<> struct LogTag { + static constexpr const char* value = "\033[0;33m[WARNING]\033[0m"; +}; +template<> struct LogTag { + static constexpr const char* value = "\033[0;32m[INFO] \033[0m"; +}; +template<> struct LogTag { + static constexpr const char* value = "\033[0m[DEBUG] \033[0m"; +}; + +class LogCatcher { + public: + LogCatcher() { } + void operator&(const std::ostream& str) const { + // TODO(tiwanek): this cast is error-prone - fix it + std::cerr << static_cast(&str)->str() + << std::endl; + } +}; + +} // namespace utils + +// Simple logging macro of following usage: +// LOG(LEVEL) << object_1 << object_2 << object_n; +// where: +// LEVEL = ERROR | WARNING | INFO | DEBUG +#define LOG(LEVEL) \ + ::utils::LogCatcher() & std::ostringstream() \ + << ::utils::LogTag<::utils::LogLevel::LOG_##LEVEL>::value \ + +#endif // UTILS_LOGGING_H_ diff --git a/src/signature/marcos.h b/src/utils/macros.h similarity index 79% rename from src/signature/marcos.h rename to src/utils/macros.h index f9a0ccf..c2e558d 100644 --- a/src/signature/marcos.h +++ b/src/utils/macros.h @@ -2,11 +2,11 @@ // Use of this source code is governed by a apache 2.0 license that can be // found in the LICENSE file. -#ifndef SIGNATURE_MARCOS_H_ -#define SIGNATURE_MARCOS_H_ +#ifndef UTILS_MACROS_H_ +#define UTILS_MACROS_H_ #define DISALLOW_COPY_AND_ASSIGN(CLASS) \ CLASS(const CLASS&) = delete; \ CLASS& operator=(const CLASS&) = delete \ -#endif // SIGNATURE_MARCOS_H_ +#endif // UTILS_MACROS_H_ -- 2.7.4