--- /dev/null
+// Copyright (c) 2016 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.
+
+#include "manifest_parser/utils/logging.h"
+
+namespace utils {
+
+log_priority LogLevelToPriority(LogLevel level) {
+ switch (level) {
+ case LogLevel::LOG_ERROR:
+ return log_priority::DLOG_ERROR;
+ case LogLevel::LOG_WARNING:
+ return log_priority::DLOG_WARN;
+ case LogLevel::LOG_INFO:
+ return log_priority::DLOG_INFO;
+ case LogLevel::LOG_DEBUG:
+ return log_priority::DLOG_DEBUG;
+ default:
+ return log_priority::DLOG_UNKNOWN;
+ }
+}
+
+} // namespace utilschce
#ifndef MANIFEST_PARSER_UTILS_LOGGING_H_
#define MANIFEST_PARSER_UTILS_LOGGING_H_
+#include <dlog/dlog.h>
+
+#ifndef PROJECT_TAG
+#define PROJECT_TAG ""
+#endif
+
+#ifdef LOG
+#undef LOG
+#endif
+
#include <cassert>
#include <iomanip>
#include <iostream>
LOG_DEBUG,
};
+log_priority LogLevelToPriority(LogLevel level);
+
template<LogLevel> struct LogTag;
template<> struct LogTag<LogLevel::LOG_ERROR> {
static constexpr const char* value = "\033[1;31m| ERROR |\033[0m";
static constexpr const char* value = "\033[0m| DEBUG |\033[0m";
};
+template <class charT, class traits = std::char_traits<charT>>
+class StringStream : private std::basic_ostringstream<charT, traits> {
+ public:
+ using std::basic_ostringstream<charT, traits>::str;
+
+ template <class T>
+ StringStream& operator<<(const T& value) {
+ static_cast<std::basic_ostringstream<charT, traits> &>(*this) << value;
+ return *this;
+ }
+};
+
class LogCatcher {
public:
- LogCatcher() { }
- void operator&(const std::ostream& str) const {
- std::cerr << static_cast<const std::ostringstream*>(&str)->str()
- << std::endl;
+ LogCatcher(LogLevel level, const char* tag)
+ : level_(level), tag_(tag) { }
+
+ void operator&(const StringStream<char>& str) const {
+ dlog_print(LogLevelToPriority(level_), tag_.c_str(), str.str().c_str());
+
+ static const char* app_installer_log = getenv("APP_INSTALLERS_LOG");
+ if (level_ == LogLevel::LOG_ERROR || app_installer_log != nullptr) {
+ std::cerr << str.str()
+ << std::endl;
+ }
}
+ private:
+ LogLevel level_;
+ std::string tag_;
};
} // namespace utils
+
inline static const constexpr char* __tag_for_logging() {
return "";
}
+inline static const constexpr char* __tag_for_project() {
+ return PROJECT_TAG;
+}
+
// To be defined in class namespace if user want different log tag for given
// scope
#define SCOPE_LOG_TAG(TAG) \
// where:
// LEVEL = ERROR | WARNING | INFO | DEBUG
#define LOG(LEVEL) \
- ::utils::LogCatcher() & std::ostringstream() \
+ ::utils::LogCatcher( \
+ ::utils::LogLevel::LOG_ ## LEVEL, __tag_for_project()) \
+ & ::utils::StringStream<char>() \
<< std::string(::utils::LogTag<::utils::LogLevel::LOG_ ## LEVEL>::value) \
<< " " << std::setw(20) << std::left << __tag_for_logging() \
<< std::setw(0) << " : " \