AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/manager MANAGER_SRCS)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/common/socket SOCKET_SRCS)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/common/parcel PARCEL_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/utils UTIL_SRCS)
ADD_LIBRARY(pkgmgr-info SHARED
${SRCS}
${SOCKET_SRCS}
${PARCEL_SRCS}
${MANAGER_SRCS}
+ ${UTIL_SRCS}
)
## Compile flags
#include "parcelable_factory.hh"
#include "system_locale.hh"
#include "ready_checker.hh"
+#include "utils/logging.hh"
+
#include "pkgmgrinfo_debug.h"
#include "pkgmgrinfo_private.h"
bool PkgInfoClient::SendRequest() {
static pkgmgr_common::ReadyChecker check_server(SERVER_READY);
if (socket_ == nullptr) {
- LOGE("Socket is not ready");
+ LOG(ERROR) << "Socket is not ready";
return false;
}
}
if (!check_server.IsReady()) {
- LOGW("Server is not ready, try to direct access");
+ LOG(WARNING) << "Server is not ready, try to direct access";
is_offline_ = true;
return RequestHandlerDirectAccess();
}
if (!socket_->Connect()) {
- LOGE("Failed to connect client socket, try to direct access");
+ LOG(ERROR) << "Failed to connect client socket, try to direct access";
is_offline_ = true;
return RequestHandlerDirectAccess();
}
if (socket_->SendData(&req_type_, sizeof(req_type_)) != 0) {
- LOGE("fail to send data");
+ LOG(ERROR) << "fail to send data";
return false;
}
int len = raw.size();
if (socket_->SendData(&len, sizeof(len)) != 0) {
- LOGE("fail to send data");
+ LOG(ERROR) << "fail to send data";
return false;
}
if (socket_->SendData(&raw[0], len) != 0) {
- LOGE("Fail to send data");
+ LOG(ERROR) << "Fail to send data";
return false;
}
return result_parcel_;
if (socket_ == nullptr) {
- LOGE("Socket is not ready");
+ LOG(ERROR) << "Socket is not ready";
return nullptr;
}
int len = 0;
if (socket_->ReceiveData(&len, sizeof(len)) != 0 || len <= 0) {
- LOGE("Fail to receive data");
+ LOG(ERROR) << "Fail to receive data";
return nullptr;
}
unsigned char* raw = new (std::nothrow) unsigned char[len];
if (raw == nullptr) {
- LOGE("Out of memory");
+ LOG(ERROR) << "Out of memory";
return nullptr;
}
if (socket_->ReceiveData(raw, len) != 0) {
- LOGE("Fail to receive data");
+ LOG(ERROR) << "Fail to receive data";
delete[] raw;
return nullptr;
}
if (handle == nullptr) {
handle = dlopen(LIBPKGMGR_INFO, RTLD_LOCAL | RTLD_LAZY);
if (!handle) {
- LOGE("Failed to open library: %s (%s)", LIBPKGMGR_INFO, dlerror());
+ LOG(ERROR) << "Failed to open library: " << LIBPKGMGR_INFO
+ << ", : " << dlerror();
return false;
}
dl_func = reinterpret_cast<void* (*)(int, unsigned char*, int, const char *)>(
dlsym(handle, DIRECT_ACCESS_FUNC));
if (dl_func == nullptr) {
- LOGE("cannot find %s symbol in (%s)", DIRECT_ACCESS_FUNC, LIBPKGMGR_INFO);
+ LOG(ERROR) << "cannot find " << DIRECT_ACCESS_FUNC << " symbol in "
+ << LIBPKGMGR_INFO;
dlclose(handle);
handle = nullptr;
return false;
#include <utility>
+#include "utils/logging.hh"
+
#include "pkgmgrinfo_debug.h"
#undef LOG_TAG
ready_checker->ready_file_ != event->name)
continue;
- _LOGI("server is ready (%s)", ready_checker->ready_file_.c_str());
+ LOG(INFO) << "server is ready : " << ready_checker->ready_file_;
ready_checker->ready_ = true;
ready_checker->Dispose();
return G_SOURCE_CONTINUE;
auto it = ready_path.find_last_of("/");
if (it == ready_path.npos) {
- _LOGE("Invalid path %s", ready_path.c_str());
+ LOG(ERROR) << "Invalid path: " << ready_path;
disposed_ = true;
return;
}
fd_ = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
if (fd_ == -1) {
- _LOGE("Failed to inotify_init. errno(%d)", errno);
+ LOG(ERROR) << "Failed to inotify_init. errno: " << errno;
disposed_ = true;
return;
}
ready_file_ = ready_path.substr(it + 1);
wd_ = inotify_add_watch(fd_, ready_path_.c_str(), IN_CREATE);
if (wd_ == -1) {
- _LOGE("Failed to inotify_add_watch. errno(%d)", errno);
+ LOG(ERROR) << "Failed to inotify_add_watch. errno: " << errno;
Dispose();
return;
}
channel_ = g_io_channel_unix_new(fd_);
if (channel_ == nullptr) {
- _LOGE("Failed to create GIO channel");
+ LOG(ERROR) << "Failed to create GIO channel";
Dispose();
return;
}
tag_ = g_io_add_watch(channel_, G_IO_IN, OnReceiveEvent, this);
if (tag_ == 0) {
- _LOGE("Failed to add watch");
+ LOG(ERROR) << "Failed to add watch";
Dispose();
return;
}
* limitations under the License.
*/
+#include "abstract_socket.hh"
+
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <sys/types.h>
#include <unistd.h>
+#include "utils/logging.hh"
+
#include "pkgmgrinfo_debug.h"
-#include "abstract_socket.hh"
namespace pkgmgr_common {
namespace socket {
while (left) {
ssize_t send_byte = send(fd_, buffer, left, MSG_NOSIGNAL);
if (send_byte < 0) {
- LOGE("send() is failed. fd(%d), errno(%d)", fd_, errno);
+ LOG(ERROR) << "send() is failed. fd: " << fd_ << ", errno:" << errno;
return -ECOMM;
}
while (left) {
ssize_t recv_byte = recv(fd_, buffer, left, 0);
if (recv_byte == 0) {
- LOGW("Socket was disconnected. fd(%d), errno(%d)", fd_, errno);
+ LOG(WARNING) << "Socket was disconnected. fd: " << fd_
+ << ", errno: " << errno;
return -errno;
} else if (recv_byte < 0) {
if (errno == EINTR) {
continue;
} else if (errno == EAGAIN) {
if (is_blocking) {
- LOGE("Timed out. fd(%d), errno(%d)", fd_, errno);
+ LOG(ERROR) << "Timed out. fd: " << fd_ << ", errno: " << errno;
return -errno;
}
continue;
}
- LOGE("recv() is failed. fd(%d), errno(%d)", fd_, errno);
+ LOG(ERROR) << "recv() is failed. fd: " << fd_ << ", errno: " << errno;
return -ECOMM;
}
int ret = setsockopt(fd_, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
if (ret < 0) {
- LOGE("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
+ LOG(ERROR) << "setsockopt() is failed. fd: " << fd_
+ << ", errno: " << errno;
return;
}
ret = setsockopt(fd_, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
- if (ret < 0) LOGE("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
+ if (ret < 0)
+ LOG(ERROR) << "setsockopt() is failed. fd: " << fd_
+ << ", errno: " << errno;
}
int AbstractSocket::Create() {
fd_ = ::socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (fd_ < 0) {
- LOGE("socket() is failed. errno(%d)", errno);
+ LOG(ERROR) << "socket() is failed. errno: " << errno;
return fd_;
}
r = getsockopt(fd_, SOL_SOCKET, SO_PEERCRED, &cred, &len);
if (r < 0) {
- LOGE("getsockopt has failed, errno[%d]", errno);
+ LOG(ERROR) << "getsockopt has failed, errno: " << errno;
return;
}
#include <unistd.h>
#include "client_socket.hh"
+#include "utils/logging.hh"
+
#include "pkgmgrinfo_debug.h"
namespace pkgmgr_common {
timeout_msec = 5000;
if (timeout_msec < 0) {
- LOGE("Invalid timeout_msec parameter");
+ LOG(ERROR) << "Invalid timeout_msec parameter";
return;
}
int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, &timeout,
sizeof(timeout));
if (ret < 0)
- LOGE("setsockopt() is failed. fd(%d), errno(%d)", fd_, errno);
+ LOG(ERROR) << "setsockopt() is failed. fd: " << fd_
+ << ", errno: " << errno;
}
bool ClientSocket::Connect() {
if (ret == 0) {
break;
} else if (ret < -1) {
- LOGE("Maybe peer not launched or peer dead. path(%s), fd(%d)",
- GetPath().c_str(), GetFd());
+ LOG(ERROR) << "Maybe peer not launched or peer dead. path: " << GetPath()
+ << ", fd: " << GetFd();
if (getuid() == 0) {
// If requester is root, don't wait
return false;
usleep(100 * 1000);
--retry_cnt;
} else if (ret < 0) {
- LOGE("Failed to connect to socket(%s), fd(%d)", GetPath().c_str(),
- GetFd());
+ LOG(ERROR) << "Failed to connect to socket: " << GetPath()
+ << ", fd: " << GetFd();
return false;
}
} while (retry_cnt > 0);
int flags = fcntl(fd_, F_GETFL, 0);
if (fcntl(fd_, F_SETFL, flags | O_NONBLOCK) != 0) {
- LOGE("Failed to set flags(%d) on fd(%d), errno(%d)",
- flags | O_NONBLOCK, fd_, errno);
+ LOG(ERROR) << "Failed to set flags: " << (flags | O_NONBLOCK) << " on fd: "
+ << fd_ << ", errno: " << errno;
return -1;
}
int ret =
connect(fd_, reinterpret_cast<struct sockaddr*>(&addr_), sizeof(addr_));
if (fcntl(fd_, F_SETFL, flags) != 0) {
- LOGE("Failed to set flags(%d) on fd(%d), errno(%d)",
- flags, fd_, errno);
+ LOG(ERROR) << "Failed to set flags: " << flags << " on fd: " << fd_
+ << ", errno: " << errno;
return -1;
}
if (ret < 0) {
* limitations under the License.
*/
+#include "server_socket.hh"
+
#include <fcntl.h>
#include <string.h>
#include <systemd/sd-daemon.h>
#include <sys/un.h>
#include <unistd.h>
+#include "utils/logging.hh"
+
#include "pkgmgrinfo_debug.h"
-#include "server_socket.hh"
namespace pkgmgr_common {
namespace socket {
if (fd_ == -1) {
if (Create() < 0) {
- LOGE("Fail to create server socket. errno(%d)", errno);
+ LOG(ERROR) << "Fail to create server socket. errno: " << errno;
return;
}
addr_.sun_family = AF_UNIX;
snprintf(addr_.sun_path, sizeof(addr_.sun_path), "%s", path_.c_str());
if (access(path_.c_str(), F_OK) == 0) {
- LOGW("socket(%s) is already used", path_.c_str());
+ LOG(WARNING) << "socket is already used : " << path_;
unlink(path_.c_str());
}
if (Bind() < 0) {
- LOGE("Fail to Bind server socket. errno(%d)", errno);
+ LOG(ERROR) << "Fail to Bind server socket. errno: " << errno;
return;
}
if (Listen() < 0) {
- LOGE("Fail to Listen server socket. errno(%d)", errno);
+ LOG(ERROR) << "Fail to Listen server socket. errno: " << errno;
return;
}
}
int flag = fcntl(fd_, F_GETFL, 0);
fcntl(fd_, F_SETFL, flag | O_NONBLOCK);
- LOGD("Server socket is created(%s)", path_.c_str());
+ LOG(DEBUG) << "Server socket is created: " << path_;
}
int ServerSocket::Bind() {
+++ /dev/null
-// Copyright (c) 2021 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 "logging.hh"
-
-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 utils
+++ /dev/null
-// Copyright (c) 2021 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 LOGGING_HH_
-#define LOGGING_HH_
-
-#include <dlog.h>
-
-#ifndef PROJECT_TAG
-#define PROJECT_TAG "PKGMGR_INFO"
-#endif
-
-#ifdef LOG
-#undef LOG
-#endif
-
-#include <cassert>
-#include <climits>
-#include <cstdio>
-#include <cstring>
-#include <iomanip>
-#include <iostream>
-#include <memory>
-#include <sstream>
-#include <string>
-#include <vector>
-
-#ifndef __FILENAME__
-#define __FILENAME__ \
- (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
-#endif
-
-namespace utils {
-
-enum class LogLevel {
- LOG_ERROR,
- LOG_WARNING,
- LOG_INFO,
- 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";
-};
-template<> struct LogTag<LogLevel::LOG_WARNING> {
- static constexpr const char* value = "\033[1;33m| WARNING |\033[0m";
-};
-template<> struct LogTag<LogLevel::LOG_INFO> {
- static constexpr const char* value = "\033[1;32m| INFO |\033[0m";
-};
-template<> struct LogTag<LogLevel::LOG_DEBUG> {
- 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;
- }
-};
-
-// Interface class for logging backends. The custom LogBackend which wants
-// log using LOG() macro should be implement following interface.
-class ILogBackend {
- public:
- virtual void WriteLog(LogLevel level, const std::string& tag,
- const std::string& logstr) = 0;
-};
-
-class DLogBackend : public ILogBackend {
- public:
- void WriteLog(LogLevel level, const std::string& tag,
- const std::string& logstr) override {
- dlog_print(LogLevelToPriority(level), tag.c_str(), "%s",
- Escape(logstr).c_str());
- }
-
- private:
- // Since LogCatcher passes input to dlog_print(), the input which contains
- // format string(such as %d, %n) can cause unexpected result.
- // This is simple function to escape '%'.
- // NOTE: Is there any gorgeous way instead of this?
- std::string Escape(const std::string& str) const {
- std::string escaped = std::string(str);
- size_t start_pos = 0;
- std::string from = "%";
- std::string to = "%%";
- while ((start_pos = escaped.find(from, start_pos)) != std::string::npos) {
- escaped.replace(start_pos, from.length(), to);
- start_pos += to.length();
- }
- return escaped;
- }
-};
-
-class LogCore {
- public:
- // Do not call this function at destructor of global object
- static LogCore& GetCore() {
- static LogCore core;
- return core;
- }
-
- void AddLogBackend(std::shared_ptr<ILogBackend> backend) {
- backend_list_.emplace_back(backend);
- }
-
- void Log(LogLevel level, const std::string& tag, const std::string& log) {
- for (auto& backend : backend_list_)
- backend->WriteLog(level, tag, log);
- }
-
- private:
- LogCore() {
- // add default dlog backend
- AddLogBackend(std::shared_ptr<ILogBackend>(new DLogBackend()));
- }
- ~LogCore() = default;
- LogCore(const LogCore&) = delete;
- LogCore& operator=(const LogCore&) = delete;
-
- std::vector<std::shared_ptr<ILogBackend>> backend_list_;
-};
-
-class LogCatcher {
- public:
- LogCatcher(LogLevel level, const char* tag)
- : level_(level), tag_(tag) { }
-
- void operator&(const StringStream<char>& str) const {
- LogCore::GetCore().Log(level_, tag_, str.str());
- }
-
- 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) \
- inline static const constexpr char* __tag_for_logging() { \
- return #TAG; \
- } \
-
-// 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( \
- ::utils::LogLevel::LOG_ ## LEVEL, __tag_for_project()) \
- & ::utils::StringStream<char>() \
- << std::string(::utils::LogTag<::utils::LogLevel::LOG_ ## LEVEL>::value) \
- << " " << std::setw(25) << std::left << __tag_for_logging() \
- << " : " << std::setw(36) \
- << (std::string(__FILENAME__) + ":" + std::to_string(__LINE__)).c_str() \
- << std::setw(0) << " : " \
-
-#endif // LOGGING_HH_
#include "common/parcel/pkginfo_parcelable.hh"
#include "common/parcel/query_parcelable.hh"
#include "common/parcel/result_parcelable.hh"
-#include "logging.hh"
+#include "utils/logging.hh"
#include "pkg_write_type.hh"
#include "db_type.hh"
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/cynara_checker CYNARA_CHECKER_SRCS)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/database DATABASE_SRCS)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/request_handler REQUEST_HANDLER_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src/utils/ UTIL_SRCS)
ADD_LIBRARY(pkgmgr-info-server SHARED
${CYNARA_CHECKER_SRCS}
${SERVER_SRCS}
${DATABASE_SRCS}
${REQUEST_HANDLER_SRCS}
+ ${UTIL_SRCS}
)
ADD_DEFINITIONS("-DSYSCONFDIR=\"${SYSCONFDIR}\"")
* limitations under the License.
*/
+#include "cynara_checker.hh"
+
#include <cynara-creds-socket.h>
#include <cynara-session.h>
#include <dlog.h>
#include <memory>
#include <mutex>
-#include "cynara_checker.hh"
+#include "utils/logging.hh"
+
#include "pkgmgrinfo_private.h"
namespace pkgmgr_server {
if (resp == CYNARA_API_ACCESS_ALLOWED) {
auto it = inst.cynara_id_map_.find(id);
if (it == inst.cynara_id_map_.end()) {
- LOGE("Invalid request");
+ LOG(ERROR) << "Invalid request";
break;
}
- LOGD("Allowed request");
+ LOG(DEBUG) << "Allowed request";
runner->QueueRequest(it->second);
inst.cynara_id_map_.erase(it);
}
case CYNARA_CALL_CAUSE_FINISH:
case CYNARA_CALL_CAUSE_SERVICE_NOT_AVAILABLE:
default:
- LOGE("Cynara: resp: not answer");
+ LOG(ERROR) << "Cynara: resp: not answer";
break;
}
}
int ret = cynara_async_process(inst.cynara_);
if (ret != CYNARA_API_SUCCESS)
- LOGE("process error %d", ret);
+ LOG(ERROR) << "process error " << ret;
return G_SOURCE_CONTINUE;
}
const std::shared_ptr<PkgRequest>& req,
const std::vector<std::string>& privileges) {
if (privileges.empty() || req->GetSenderUID() < REGULAR_USER) {
- LOGD("Allowed request");
+ LOG(DEBUG) << "Allowed request";
runner->QueueRequest(req);
return;
}
if (cynara_ == nullptr) {
ret = cynara_async_initialize(&cynara_, nullptr, StatusCb, nullptr);
if (ret != CYNARA_API_SUCCESS) {
- LOGE("Failed to initialize cynara_");
+ LOG(ERROR) << "Failed to initialize cynara_";
return;
}
}
ret = cynara_creds_socket_get_client(req->GetFd(), CLIENT_METHOD_SMACK,
&smack_label);
if (ret != CYNARA_API_SUCCESS) {
- LOGE("Failed to get smack label");
+ LOG(ERROR) << "Failed to get smack label";
return;
}
std::unique_ptr<char, decltype(std::free)*> lblPtr(smack_label, std::free);
char* session = cynara_session_from_pid(req->GetSenderPID());
if (session == nullptr) {
- LOGE("Failed to get client session (pid:%d)", req->GetSenderPID());
+ LOG(ERROR) << "Failed to get client session for pid:"
+ << req->GetSenderPID();
return;
}
std::unique_ptr<char, decltype(std::free)*> sessPtr(session, std::free);
#include <vector>
#include "db_handle_provider.hh"
+#include "utils/logging.hh"
+
#include "pkgmgr-info.h"
#include "pkgmgrinfo_debug.h"
#include "pkgmgrinfo_private.h"
ret = sqlite3_busy_handler(*db, __readdb_busy_handler, NULL);
if (ret != SQLITE_OK) {
- _LOGE("failed to register busy handler: %s",
- sqlite3_errmsg(*db));
+ LOG(ERROR) << "failed to register busy handler:" << sqlite3_errmsg(*db);
sqlite3_close_v2(*db);
return ret;
}
ret = sqlite3_busy_handler(*db, __writedb_busy_handler,
reinterpret_cast<void*>(const_cast<char*>(path)));
if (ret != SQLITE_OK) {
- _LOGE("failed to register busy handler: %s",
- sqlite3_errmsg(*db));
+ LOG(ERROR) << "failed to register busy handler:" << sqlite3_errmsg(*db);
sqlite3_close_v2(*db);
return ret;
}
ret = sqlite3_exec(*db, "PRAGMA foreign_keys=ON", NULL, NULL, NULL);
if (ret != SQLITE_OK) {
- _LOGE("failed to enable foreign key support: %s",
- sqlite3_errmsg(*db));
+ LOG(ERROR) << "failed to enable foreign key support:"
+ << sqlite3_errmsg(*db);
sqlite3_close_v2(*db);
return ret;
}
ret = sqlite3_busy_handler(*db, __writedb_busy_handler,
reinterpret_cast<void*>(const_cast<char*>(path)));
if (ret != SQLITE_OK) {
- _LOGE("failed to register busy handler: %s",
- sqlite3_errmsg(*db));
+ LOG(ERROR) << "failed to register busy handler:" << sqlite3_errmsg(*db);
sqlite3_close_v2(*db);
return ret;
}
bool AbstractDBHandler::Connect() {
if (db_type_ == pkgmgr_common::DBType::DB_TYPE_NONE ||
op_type_ == pkgmgr_common::DBOperationType::OPERATION_TYPE_NONE) {
- _LOGE("Invalid parameter");
+ LOG(ERROR) << "Invalid parameter";
return false;
}
auto dbpath_list = GetDBPath();
continue;
if (access(dbpath.first.c_str(), F_OK) != -1) {
- _LOGE("Database for user %d is already exists", uid_);
+ LOG(ERROR) << "Database for user " << uid_ << " is already exists";
return false;
}
ret = __open_create_db(uid_, dbpath.first.c_str(), &db);
#include <vector>
#include <shared_mutex>
+#include "utils/logging.hh"
+
#include "pkgmgrinfo_basic.h"
#include "pkgmgrinfo_debug.h"
#include "pkgmgrinfo_internal.h"
ret = appinfo_internal_filter_get_list(conn.first, filter_, conn.second,
uid_, GetLocale().c_str(), list);
if (ret == PMINFO_R_ERROR) {
- _LOGD("Failed to appinfo_internal_filter_get_list (%d)", ret);
+ LOG(DEBUG) << "Failed to appinfo_internal_filter_get_list: " << ret;
break;
}
}
#include <shared_mutex>
#include <vector>
+#include "utils/logging.hh"
+
#include "pkgmgrinfo_debug.h"
#include "pkgmgrinfo_internal.h"
SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_CERTDB);
if (!Connect()) {
- _LOGE("Failed to connect database");
+ LOG(ERROR) << "Failed to connect database";
return PMINFO_R_ERROR;
}
#include <vector>
#include "db_handle_provider.hh"
+#include "utils/logging.hh"
#include "pkgmgrinfo_debug.h"
#include "pkgmgrinfo_internal.h"
std::unique_lock<std::shared_timed_mutex> u(lock_);
if (CreateParserDB() < 0) {
- LOGE("Failed to create parser db for uid [%d]", GetUID());
+ LOG(ERROR) << "Failed to create parser db for uid : " << GetUID();
return PMINFO_R_ERROR;
}
if (GetUID() == GLOBAL_USER || GetUID() == OWNER_ROOT) {
if (CreateCertDB() < 0) {
- LOGE("Failed to create cert db for uid [%d]", GetUID());
+ LOG(ERROR) << "Failed to create cert db";
return PMINFO_R_ERROR;
}
}
#include <string>
#include <vector>
+#include "utils/logging.hh"
+
#include "pkgmgrinfo_debug.h"
#include "pkgmgr-info.h"
return false;
bool ret = true;
- LOGD("Check process count : %zu", pid_list_.size());
+ LOG(DEBUG) << "Check process count : " << pid_list_.size();
std::vector<pid_t> remove_pids;
for (pid_t pid : pid_list_) {
std::string status_path = "/proc/" + std::to_string(pid) + "/status";
int fd = open(status_path.c_str(), O_RDONLY);
if (fd < 0) {
- LOGE("Process is crashed (%d)", pid);
+ LOG(ERROR) << "Process is crashed : " << pid;
remove_pids.push_back(pid);
} else {
ret = false;
}
if (db_path_list.size() == 1) {
- LOGD("global db path : %s", db_path_list[0].first.c_str());
+ LOG(DEBUG) << "global db path : " << db_path_list[0].first;
} else {
- LOGD("local db path : %s", db_path_list[0].first.c_str());
- LOGD("global db path : %s", db_path_list[1].first.c_str());
+ LOG(DEBUG) << "local db path : " << db_path_list[0].first;
+ LOG(DEBUG) << "global db path : " << db_path_list[1].first;
}
return db_path_list;
int ret = sqlite3_open_v2(memorydb_path.c_str(), &memorydb,
SQLITE_OPEN_READONLY | SQLITE_OPEN_URI, nullptr);
if (ret != SQLITE_OK) {
- LOGE("Failed to open memory DB %d(%s)", ret, memorydb_path.c_str());
+ LOG(ERROR) << "Failed to open memory DB " << ret << ": " << memorydb_path;
return nullptr;
}
ret = sqlite3_open_v2(filedb_path.c_str(), &filedb,
SQLITE_OPEN_READONLY, nullptr);
if (ret != SQLITE_OK) {
- LOGE("Failed to open file DB %d(%s)", ret, filedb_path.c_str());
+ LOG(ERROR) << "Failed to open file DB " << ret << ": " << filedb_path;
sqlite3_close_v2(memorydb);
return nullptr;
}
sqlite3_backup* backup = sqlite3_backup_init(memorydb, "main",
filedb, "main");
if (backup == nullptr) {
- LOGE("Failed to backup for memory DB");
+ LOG(ERROR) << "Failed to backup for memory DB";
sqlite3_close_v2(memorydb);
sqlite3_close_v2(filedb);
return nullptr;
is_memory_ = true;
is_memory_global_ = true;
- LOGD("Set Memory mode : Memory");
+ LOG(DEBUG) << "Set Memory mode : Memory";
}
void DBHandleProvider::UnsetMemoryMode(pid_t pid) {
if (it != pid_list_.end())
pid_list_.erase(it);
else
- LOGE("Given pid is not exists in pid list : %d", pid);
+ LOG(ERROR) << "Given pid is not exists in pid list : " << pid;
is_memory_ = false;
is_memory_global_ = false;
- LOGD("Set Memory mode : File");
+ LOG(DEBUG) << "Set Memory mode : File";
}
bool DBHandleProvider::IsMemoryDBActive(pid_t pid, bool write) {
#include <shared_mutex>
#include <vector>
+#include "utils/logging.hh"
+
#include "pkgmgrinfo_debug.h"
#include "pkgmgrinfo_internal.h"
SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
if (!Connect()) {
- _LOGE("Failed to connect database");
+ LOG(ERROR) << "Failed to connect database";
return PMINFO_R_ERROR;
}
GList* list = nullptr;
#include <shared_mutex>
#include <vector>
+#include "utils/logging.hh"
+
#include "pkgmgrinfo_debug.h"
#include "pkgmgrinfo_internal.h"
SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_READ);
SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
if (!Connect()) {
- _LOGE("Failed to connect database");
+ LOG(ERROR) << "Failed to connect database";
return PMINFO_R_ERROR;
}
ret = pkginfo_internal_filter_get_list(conn.first, filter_, conn.second,
GetLocale().c_str(), list);
if (ret == PMINFO_R_ERROR) {
- _LOGE("Failed to pkginfo_internal_filter_get_list (%d)", ret);
+ LOG(ERROR) << "Failed to pkginfo_internal_filter_get_list : " << ret;
break;
}
}
#include <vector>
#include "db_handle_provider.hh"
+#include "utils/logging.hh"
#include "pkgmgrinfo_debug.h"
#include "pkgmgrinfo_internal.h"
else if (write_type_ == pkgmgr_common::PkgWriteType::Delete)
ret = pkgmgr_parser_delete_pkg_info(conn, package_->package, uid_);
else
- _LOGE("Unknown db write type");
+ LOG(ERROR) << "Unknown db write type";
if (ret != PM_PARSER_R_OK)
return ret;
#include <shared_mutex>
#include <vector>
+#include "utils/logging.hh"
+
#include "pkgmgrinfo_debug.h"
#include "pkgmgrinfo_internal.h"
#include "pkgmgr_query_index.h"
int QueryHandler::Execute() {
std::shared_lock<std::shared_timed_mutex> s(lock_);
if (!Connect()) {
- _LOGE("Failed to connect database");
+ LOG(ERROR) << "Failed to connect database";
return PMINFO_R_ERROR;
}
for (auto& i : query_args_) {
const char* query = __query_maker.GetQuery(i.first);
if (query == nullptr) {
- _LOGE("Failed to get query");
+ LOG(ERROR) << "Failed to get query";
__free_query_list(queries, args_list);
return PMINFO_R_ERROR;
}
queries = g_list_append(queries, (gpointer)query);
query_args* arg = (query_args*)calloc(1, sizeof(query_args));
if (arg == nullptr) {
- _LOGE("Out of memory");
+ LOG(ERROR) << "Out of memory";
__free_query_list(queries, args_list);
return PMINFO_R_ERROR;
}
ret = get_query_result(conn.first, (const char *)queries->data,
params->argument, &list, &row, &col);
if (ret == PMINFO_R_ERROR) {
- _LOGE("Failed to execute query");
+ LOG(ERROR) << "Failed to execute query";
__free_query_list(queries, args_list);
return ret;
}
for (auto& conn : conn_list) {
ret = execute_write_queries(conn.first, queries, args_list);
if (ret != PMINFO_R_OK) {
- _LOGE("Failed to execute");
+ LOG(ERROR) << "Failed to execute";
break;
}
}
*/
#include "pkg_request.hh"
+
+#include "utils/logging.hh"
+
#include "pkgmgrinfo_debug.h"
namespace pkgmgr_server {
socket_ = std::unique_ptr<pkgmgr_common::socket::DataSocket>(
new (std::nothrow) pkgmgr_common::socket::DataSocket(fd));
if (socket_ == nullptr)
- LOGE("Out of memory");
+ LOG(ERROR) << "Out of memory";
}
PkgRequest::~PkgRequest() {
bool PkgRequest::ReceiveData() {
int ret = socket_->ReceiveData(&request_type_, sizeof(request_type_));
if (ret < 0 || request_type_ == pkgmgr_common::REQ_TYPE_NONE) {
- LOGE("Failed to ReceiveData");
+ LOG(ERROR) << "Failed to ReceiveData";
return false;
}
ret = socket_->ReceiveData(&data_size_, sizeof(data_size_));
if (ret < 0) {
- LOGE("Failed to ReceiveData");
+ LOG(ERROR) << "Failed to ReceiveData";
request_type_ = pkgmgr_common::REQ_TYPE_NONE;
return false;
}
if (data_size_ <= 0) {
- LOGE("Invalid data");
+ LOG(ERROR) << "Invalid data";
request_type_ = pkgmgr_common::REQ_TYPE_NONE;
return false;
}
data_ = new (std::nothrow) unsigned char[data_size_];
if (data_ == nullptr) {
- LOGE("Out of memory");
+ LOG(ERROR) << "Out of memory";
request_type_ = pkgmgr_common::REQ_TYPE_NONE;
return false;
}
ret = socket_->ReceiveData(reinterpret_cast<void*>(data_), data_size_);
if (ret < 0) {
- LOGE("Failed to ReceiveData");
+ LOG(ERROR) << "Failed to ReceiveData";
delete[] data_;
data_ = nullptr;
request_type_ = pkgmgr_common::REQ_TYPE_NONE;
#include "db_handle_provider.hh"
#include "parcelable_factory.hh"
#include "pkginfo_parcelable.hh"
+#include "utils/logging.hh"
#include "pkgmgrinfo_debug.h"
#include "pkgmgrinfo_type.h"
if (abstract_parcel == nullptr ||
abstract_parcel->GetType() != pcp::ParcelableType::Command) {
- _LOGE("Invalid parcel or type");
+ LOG(ERROR) << "Invalid parcel or type";
result_ = std::make_shared<pcp::ResultParcelable>(
PMINFO_R_ERROR, std::vector<pcp::StrArgs>{});
return false;
auto* parcel = dynamic_cast<pcp::CommandParcelable*>(abstract_parcel.get());
if (parcel == nullptr) {
- _LOGE("Parcel is empty");
+ LOG(ERROR) << "Parcel is empty";
result_ = std::make_shared<pcp::ResultParcelable>(
PMINFO_R_ERROR, std::vector<pcp::StrArgs>{});
return false;
#include <string>
-#include "parcelable_factory.hh"
#include "create_db_parcelable.hh"
#include "create_db_handler.hh"
#include "db_type.hh"
+#include "parcelable_factory.hh"
+#include "utils/logging.hh"
#include "pkgmgr_parser.h"
if (abstract_parcel == nullptr ||
abstract_parcel->GetType() != pcp::ParcelableType::CreateDB) {
- _LOGE("Invalid parcel or type");
+ LOG(ERROR) << "Invalid parcel or type";
result_ = std::make_shared<pcp::ResultParcelable>(
PM_PARSER_R_ERROR, std::vector<pcp::StrArgs>{});
return false;
auto* parcel = dynamic_cast<pcp::CreateDBParcelable*>(abstract_parcel.get());
if (parcel == nullptr) {
- _LOGE("Parcel is empty");
+ LOG(ERROR) << "Parcel is empty";
result_ = std::make_shared<pcp::ResultParcelable>(
PM_PARSER_R_ERROR, std::vector<pcp::StrArgs>{});
return false;
#include <string>
-#include "parcelable_factory.hh"
-#include "filter_parcelable.hh"
#include "appinfo_db_handler.hh"
+#include "filter_parcelable.hh"
+#include "parcelable_factory.hh"
+#include "utils/logging.hh"
#include "pkgmgrinfo_debug.h"
if (abstract_parcel == nullptr ||
abstract_parcel->GetType() != pcp::ParcelableType::Filter) {
- _LOGE("Invalid parcel or type");
+ LOG(ERROR) << "Invalid parcel or type";
result_ = std::make_shared<pcp::AppInfoParcelable>(
PMINFO_R_ERROR, std::vector<application_x*>{});
return false;
auto* parcel = dynamic_cast<pcp::FilterParcelable*>(abstract_parcel.get());
if (parcel == nullptr) {
- _LOGE("Parcel is empty");
+ LOG(ERROR) << "Parcel is empty";
result_ = std::make_shared<pcp::AppInfoParcelable>(
PMINFO_R_ERROR, std::vector<application_x*>{});
return false;
#include "database/cert_get_db_handler.hh"
#include "parcelable_factory.hh"
+#include "utils/logging.hh"
#include "pkgmgrinfo_debug.h"
if (abstract_parcel == nullptr ||
abstract_parcel->GetType() != pcp::ParcelableType::CertInfo) {
- _LOGE("Invalid parcel or type");
+ LOG(ERROR) << "Invalid parcel or type";
result_ = std::make_shared<pcp::CertInfoParcelable>(
PMINFO_R_ERROR, nullptr);
return false;
auto* parcel = dynamic_cast<pcp::CertInfoParcelable*>(abstract_parcel.get());
if (parcel == nullptr) {
- _LOGE("Parcel is empty");
+ LOG(ERROR) << "Parcel is empty";
result_ = std::make_shared<pcp::CertInfoParcelable>(
PMINFO_R_ERROR, nullptr);
return false;
#include "depinfo_db_handler.hh"
#include "depinfo_parcelable.hh"
#include "parcelable_factory.hh"
+#include "utils/logging.hh"
#include "pkgmgrinfo_debug.h"
if (abstract_parcel == nullptr ||
abstract_parcel->GetType() != pcp::ParcelableType::DepInfo) {
- _LOGE("Invalid parcel or type");
+ LOG(ERROR) << "Invalid parcel or type";
result_ = std::make_shared<pcp::DepInfoParcelable>(
PMINFO_R_ERROR, std::vector<dependency_x*>{});
return false;
auto* parcel = dynamic_cast<pcp::DepInfoParcelable*>(abstract_parcel.get());
if (parcel == nullptr) {
- _LOGE("Parcel is empty");
+ LOG(ERROR) << "Parcel is empty";
result_ = std::make_shared<pcp::DepInfoParcelable>(
PMINFO_R_ERROR, std::vector<dependency_x*>{});
return false;
#include <string>
+#include "filter_parcelable.hh"
#include "parcelable_factory.hh"
#include "pkg_get_db_handler.hh"
-#include "filter_parcelable.hh"
+#include "utils/logging.hh"
#include "pkgmgrinfo_debug.h"
if (abstract_parcel == nullptr ||
abstract_parcel->GetType() != pcp::ParcelableType::Filter) {
- _LOGE("Invalid parcel or type");
+ LOG(ERROR) << "Invalid parcel or type";
result_ = std::make_shared<pcp::PkgInfoParcelable>(
PMINFO_R_ERROR, std::vector<package_x*>{});
return false;
auto* parcel = dynamic_cast<pcp::FilterParcelable*>(abstract_parcel.get());
if (parcel == nullptr) {
- _LOGE("Parcel is empty");
+ LOG(ERROR) << "Parcel is empty";
result_ = std::make_shared<pcp::PkgInfoParcelable>(
PMINFO_R_ERROR, std::vector<package_x*>{});
return false;
#include "parcelable_factory.hh"
#include "query_handler.hh"
#include "query_parcelable.hh"
+#include "utils/logging.hh"
#include "pkgmgrinfo_debug.h"
if (abstract_parcel == nullptr ||
abstract_parcel->GetType() != pcp::ParcelableType::Query) {
- _LOGE("Invalid parcel or type");
+ LOG(ERROR) << "Invalid parcel or type";
result_ = std::make_shared<pcp::ResultParcelable>(
PMINFO_R_ERROR, std::vector<pcp::StrArgs>{});
return false;
auto* parcel = dynamic_cast<pcp::QueryParcelable*>(abstract_parcel.get());
if (parcel == nullptr) {
- _LOGE("Parcel is empty");
+ LOG(ERROR) << "Parcel is empty";
result_ = std::make_shared<pcp::ResultParcelable>(
PMINFO_R_ERROR, std::vector<pcp::StrArgs>{});
return false;
#include "query_request_handler.hh"
#include "set_cert_request_handler.hh"
#include "set_pkginfo_request_handler.hh"
+#include "utils/logging.hh"
#ifdef EXPORT_API
#undef EXPORT_API
}
if (handler == nullptr) {
- _LOGE("Can't reset handler with type[%d]", req_type);
+ LOG(ERROR) << "Can't reset handler with type : " << req_type;
return nullptr;
}
if (!handler->HandleRequest(data, size, locale)) {
- LOGE("Failed to handle request");
+ LOG(ERROR) << "Failed to handle request";
return nullptr;
}
auto result = handler->ExtractResult();
if (result.size() == 0) {
- _LOGE("Fail to extract result");
+ LOG(ERROR) << "Fail to extract result";
return nullptr;
}
#include "certinfo_parcelable.hh"
#include "cert_set_db_handler.hh"
+#include "utils/logging.hh"
#include "parcelable_factory.hh"
#include "pkgmgrinfo_debug.h"
if (abstract_parcel == nullptr ||
abstract_parcel->GetType() != pcp::ParcelableType::CertInfo) {
- _LOGE("Invalid parcel");
+ LOG(ERROR) << "Invalid parcel";
result_ = std::make_shared<pcp::ResultParcelable>(
PMINFO_R_ERROR, std::vector<pcp::StrArgs>{});
return false;
auto* parcel = dynamic_cast<pcp::CertInfoParcelable*>(abstract_parcel.get());
if (parcel == nullptr) {
- _LOGE("Parcel is empty");
+ LOG(ERROR) << "Parcel is empty";
result_ = std::make_shared<pcp::ResultParcelable>(
PMINFO_R_ERROR, std::vector<pcp::StrArgs>{});
return false;
#include "parcelable_factory.hh"
#include "pkginfo_parcelable.hh"
#include "pkg_set_db_handler.hh"
+#include "utils/logging.hh"
#include "pkgmgr_parser.h"
if (abstract_parcel == nullptr ||
abstract_parcel->GetType() != pcp::ParcelableType::PkgInfo) {
- _LOGE("Invalid parcel or type");
+ LOG(ERROR) << "Invalid parcel or type";
result_ = std::make_shared<pcp::ResultParcelable>(
PM_PARSER_R_ERROR, std::vector<pcp::StrArgs>{});
return false;
auto* parcel = dynamic_cast<pcp::PkgInfoParcelable*>(abstract_parcel.get());
if (parcel == nullptr) {
- _LOGE("Parcel is empty");
+ LOG(ERROR) << "Parcel is empty";
result_ = std::make_shared<pcp::ResultParcelable>(
PM_PARSER_R_ERROR, std::vector<pcp::StrArgs>{});
return false;
db.SetPkgInfo(i);
ret = db.Execute();
if (ret != PM_PARSER_R_OK) {
- _LOGE("Failed to set pkginfo");
+ LOG(ERROR) << "Failed to set pkginfo";
break;
}
}
#include "cynara_checker.hh"
#include "pkg_request.hh"
#include "runner.hh"
+#include "utils/logging.hh"
+
#include "pkgmgrinfo_debug.h"
#include "pkgmgrinfo_private.h"
int Runner::OnReceiveRequest(int fd, GIOCondition cond, void* user_data) {
if (static_cast<int>(cond) & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
- LOGE("Invalid condition fd(%d) condition(%d)", fd, static_cast<int>(cond));
+ LOG(ERROR) << "Invalid condition fd:" << fd
+ << ", condition:" << static_cast<int>(cond);
abort();
return G_SOURCE_REMOVE;
}
auto runner = static_cast<Runner*>(user_data);
int client_fd = runner->server_->Accept();
if (client_fd < 0) {
- LOGE("Failed to Accept. errno(%d)", errno);
+ LOG(ERROR) << "Failed to Accept. errno:" << errno;
return G_SOURCE_CONTINUE;
}
* limitations under the License.
*/
+#include "worker_thread.hh"
+
#include <sqlite3.h>
#include <malloc.h>
-#include "worker_thread.hh"
+#include "abstract_parcelable.hh"
+#include "command_request_handler.hh"
+#include "create_db_request_handler.hh"
#include "db_handle_provider.hh"
-
-#include "pkgmgrinfo_debug.h"
#include "get_appinfo_request_handler.hh"
#include "get_cert_request_handler.hh"
-#include "get_pkginfo_request_handler.hh"
#include "get_depinfo_request_handler.hh"
-#include "create_db_request_handler.hh"
+#include "get_pkginfo_request_handler.hh"
#include "query_request_handler.hh"
#include "set_cert_request_handler.hh"
#include "set_pkginfo_request_handler.hh"
-#include "abstract_parcelable.hh"
-#include "command_request_handler.hh"
+#include "utils/logging.hh"
+
+#include "pkgmgrinfo_debug.h"
#ifdef LOG_TAG
#undef LOG_TAG
for (unsigned int i = 0; i < num; ++i)
threads_.emplace_back([this]() -> void { this->Run(); });
- LOGD("%d Worker threads are created", num);
+ LOG(DEBUG) << num << " Worker threads are created";
}
WorkerThread::~WorkerThread() {
handler[pkgmgr_common::ReqType::CREATE_DB].reset(
new request_handler::CreateDBRequestHandler());
- LOGD("Initialize request handlers");
+ LOG(DEBUG) << "Initialize request handlers";
while (true) {
std::shared_ptr<PkgRequest> req;
{
}
pkgmgr_common::ReqType type = req->GetRequestType();
- LOGW("Request type(%s), pid(%d)",
- pkgmgr_common::ReqTypeToString(type), req->GetSenderPID());
+ LOG(WARNING) << "Request type: " << pkgmgr_common::ReqTypeToString(type)
+ << " pid: " << req->GetSenderPID();
if (type <= pkgmgr_common::ReqType::REQ_TYPE_NONE
|| type >= pkgmgr_common::ReqType::MAX) {
- LOGE("Request type is invalid (%d) pid(%d)", static_cast<int>(type),
- req->GetSenderPID());
+ LOG(ERROR) << "Request type is invalid: " << static_cast<int>(type)
+ << ", pid:" << req->GetSenderPID();
pkgmgr_common::parcel::AbstractParcelable parcelable(
0, pkgmgr_common::parcel::ParcelableType::Unknown, PMINFO_R_ERROR);
handler[type]->SetPID(req->GetSenderPID());
if (!handler[type]->HandleRequest(req->GetData(), req->GetSize(),
locale_.GetObject()))
- LOGE("Failed to handle request");
+ LOG(ERROR) << "Failed to handle request";
} catch (const std::exception& err) {
- LOGE("Exception occurred (%s) pid(%d)", err.what(), req->GetSenderPID());
+ LOG(ERROR) << "Exception occurred: " << err.what()
+ << ", pid: " << req->GetSenderPID();
pkgmgr_common::parcel::AbstractParcelable parcelable(
0, pkgmgr_common::parcel::ParcelableType::Unknown, PMINFO_R_ERROR);
tizen_base::Parcel p;
req->SendData(&raw[0], raw.size());
continue;
} catch (...) {
- LOGE("Exception occurred pid(%d)", req->GetSenderPID());
+ LOG(ERROR) << "Exception occurred pid: " << req->GetSenderPID();
pkgmgr_common::parcel::AbstractParcelable parcelable(
0, pkgmgr_common::parcel::ParcelableType::Unknown, PMINFO_R_ERROR);
tizen_base::Parcel p;
std::vector<uint8_t> result_data = handler[type]->ExtractResult();
if (req->SendData(result_data.data(), result_data.size()) == false) {
- LOGE("Failed to send response pid(%d)", req->GetSenderPID());
+ LOG(ERROR) << "Failed to send response pid: " << req->GetSenderPID();
continue;
}
- LOGW("Success response pid(%d)", req->GetSenderPID());
+ LOG(WARNING) << "Success response pid: " << req->GetSenderPID();
}
}
}
gboolean WorkerThread::TrimMemory(void* data) {
- LOGD("Trim memory");
+ LOG(DEBUG) << "Trim memory";
guint* timer = static_cast<guint*>(data);
sqlite3_release_memory(-1);
malloc_trim(0);
}
void WorkerThread::SetLocale(std::string locale) {
- LOGD("Change locale (%s) -> (%s)", locale_.GetObject().c_str(),
- locale.c_str());
+ LOG(DEBUG) << "Change locale : " << locale_.GetObject()
+ << " -> " << locale;
locale_.SetObject(std::move(locale));
}
--- /dev/null
+// Copyright (c) 2021 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 "logging.hh"
+
+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 utils
--- /dev/null
+// Copyright (c) 2021 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 LOGGING_HH_
+#define LOGGING_HH_
+
+#include <dlog.h>
+
+#ifndef PROJECT_TAG
+#define PROJECT_TAG "PKGMGR_INFO"
+#endif
+
+#ifdef LOG
+#undef LOG
+#endif
+
+#include <cassert>
+#include <climits>
+#include <cstdio>
+#include <cstring>
+#include <iomanip>
+#include <iostream>
+#include <memory>
+#include <sstream>
+#include <string>
+#include <vector>
+
+#ifndef __FILENAME__
+#define __FILENAME__ \
+ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
+#endif
+
+namespace utils {
+
+enum class LogLevel {
+ LOG_ERROR,
+ LOG_WARNING,
+ LOG_INFO,
+ 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";
+};
+template<> struct LogTag<LogLevel::LOG_WARNING> {
+ static constexpr const char* value = "\033[1;33m| WARNING |\033[0m";
+};
+template<> struct LogTag<LogLevel::LOG_INFO> {
+ static constexpr const char* value = "\033[1;32m| INFO |\033[0m";
+};
+template<> struct LogTag<LogLevel::LOG_DEBUG> {
+ 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;
+ }
+};
+
+// Interface class for logging backends. The custom LogBackend which wants
+// log using LOG() macro should be implement following interface.
+class ILogBackend {
+ public:
+ virtual void WriteLog(LogLevel level, const std::string& tag,
+ const std::string& logstr) = 0;
+};
+
+class DLogBackend : public ILogBackend {
+ public:
+ void WriteLog(LogLevel level, const std::string& tag,
+ const std::string& logstr) override {
+ dlog_print(LogLevelToPriority(level), tag.c_str(), "%s",
+ Escape(logstr).c_str());
+ }
+
+ private:
+ // Since LogCatcher passes input to dlog_print(), the input which contains
+ // format string(such as %d, %n) can cause unexpected result.
+ // This is simple function to escape '%'.
+ // NOTE: Is there any gorgeous way instead of this?
+ std::string Escape(const std::string& str) const {
+ std::string escaped = std::string(str);
+ size_t start_pos = 0;
+ std::string from = "%";
+ std::string to = "%%";
+ while ((start_pos = escaped.find(from, start_pos)) != std::string::npos) {
+ escaped.replace(start_pos, from.length(), to);
+ start_pos += to.length();
+ }
+ return escaped;
+ }
+};
+
+class LogCore {
+ public:
+ // Do not call this function at destructor of global object
+ static LogCore& GetCore() {
+ static LogCore core;
+ return core;
+ }
+
+ void AddLogBackend(std::shared_ptr<ILogBackend> backend) {
+ backend_list_.emplace_back(backend);
+ }
+
+ void Log(LogLevel level, const std::string& tag, const std::string& log) {
+ for (auto& backend : backend_list_)
+ backend->WriteLog(level, tag, log);
+ }
+
+ private:
+ LogCore() {
+ // add default dlog backend
+ AddLogBackend(std::shared_ptr<ILogBackend>(new DLogBackend()));
+ }
+ ~LogCore() = default;
+ LogCore(const LogCore&) = delete;
+ LogCore& operator=(const LogCore&) = delete;
+
+ std::vector<std::shared_ptr<ILogBackend>> backend_list_;
+};
+
+class LogCatcher {
+ public:
+ LogCatcher(LogLevel level, const char* tag)
+ : level_(level), tag_(tag) { }
+
+ void operator&(const StringStream<char>& str) const {
+ LogCore::GetCore().Log(level_, tag_, str.str());
+ }
+
+ 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) \
+ inline static const constexpr char* __tag_for_logging() { \
+ return #TAG; \
+ } \
+
+// 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( \
+ ::utils::LogLevel::LOG_ ## LEVEL, __tag_for_project()) \
+ & ::utils::StringStream<char>() \
+ << std::string(::utils::LogTag<::utils::LogLevel::LOG_ ## LEVEL>::value) \
+ << " " << std::setw(25) << std::left << __tag_for_logging() \
+ << " : " << std::setw(36) \
+ << (std::string(__FILENAME__) + ":" + std::to_string(__LINE__)).c_str() \
+ << std::setw(0) << " : " \
+
+#endif // LOGGING_HH_
FILE(GLOB_RECURSE UNIT_TESTS_SRCS *.cc *.c)
FILE(GLOB_RECURSE SERVER_SRCS ${CMAKE_SOURCE_DIR}/src/server/*.cc ${CMAKE_SOURCE_DIR}/src/server/*.c)
+FILE(GLOB_RECURSE UTIL_SRCS ${CMAKE_SOURCE_DIR}/src/utils/*)
LIST(FILTER SERVER_SRCS EXCLUDE REGEX main.cc)
ADD_EXECUTABLE(${TARGET_PKGMGR_INFO_UNIT_TEST}
${UNIT_TESTS_SRCS}
${SERVER_SRCS}
+ ${UTIL_SRCS}
)
ADD_DEFINITIONS("-DSYSCONFDIR=\"${SYSCONFDIR}\"")