diff options
author | Kyungwook Tak <k.tak@samsung.com> | 2016-06-22 18:42:59 +0900 |
---|---|---|
committer | Kyungwook Tak <k.tak@samsung.com> | 2016-06-22 18:42:59 +0900 |
commit | c24c15f05ec17e800dae331037541e089161daa7 (patch) | |
tree | 0c3455a451a5877e4fa8bf4dd0662f740944a2b4 | |
parent | 76193e65df7834e24459755ec7087e1bd26c0868 (diff) | |
download | csr-framework-c24c15f05ec17e800dae331037541e089161daa7.tar.gz csr-framework-c24c15f05ec17e800dae331037541e089161daa7.tar.bz2 csr-framework-c24c15f05ec17e800dae331037541e089161daa7.zip |
Make more log levels on exception
Change-Id: Idad383a7b0f757f263138efb7bf601d66d67b2b8
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
-rw-r--r-- | src/framework/client/async-logic.cpp | 2 | ||||
-rw-r--r-- | src/framework/common/audit/logger.h | 15 | ||||
-rw-r--r-- | src/framework/common/exception.cpp | 4 | ||||
-rw-r--r-- | src/framework/common/exception.h | 12 | ||||
-rw-r--r-- | src/framework/service/cs-loader.cpp | 4 | ||||
-rw-r--r-- | src/framework/service/cs-logic.cpp | 2 | ||||
-rw-r--r-- | src/framework/service/file-system.cpp | 6 | ||||
-rw-r--r-- | src/framework/service/server-service.cpp | 8 | ||||
-rw-r--r-- | src/framework/service/wp-loader.cpp | 4 |
9 files changed, 32 insertions, 25 deletions
diff --git a/src/framework/client/async-logic.cpp b/src/framework/client/async-logic.cpp index e6c18ab..42d417a 100644 --- a/src/framework/client/async-logic.cpp +++ b/src/framework/client/async-logic.cpp @@ -94,7 +94,7 @@ void AsyncLogic::scanFiles(const StrSet &fileSet) { for (const auto &file : fileSet) { if (this->m_handle->isStopped()) - ThrowExc(-999, "Async op cancelled!"); + ThrowExcInfo(-999, "Async op cancelled!"); auto ret = this->m_dispatcher->methodCall<std::pair<int, CsDetected *>>( CommandId::SCAN_FILE, this->m_ctx, file); diff --git a/src/framework/common/audit/logger.h b/src/framework/common/audit/logger.h index de4a71c..b19f84b 100644 --- a/src/framework/common/audit/logger.h +++ b/src/framework/common/audit/logger.h @@ -62,17 +62,16 @@ public: #define FORMAT(ITEMS) \ (static_cast<std::ostringstream &>(std::ostringstream() << ITEMS)).str() -#define LOG(LEVEL, MESSAGE) Csr::Audit::Logger::log( \ - Csr::Audit::LogLevel::LEVEL, __FILENAME__, __LINE__, __func__, \ - FORMAT(MESSAGE)) +#define LOG(LEVEL, MESSAGE) Csr::Audit::Logger::log( \ + LEVEL, __FILENAME__, __LINE__, __func__, FORMAT(MESSAGE)) \ -#define ERROR(MESSAGE) LOG(Error, MESSAGE) -#define WARN(MESSAGE) LOG(Warning, MESSAGE) -#define INFO(MESSAGE) LOG(Info, MESSAGE) +#define ERROR(MESSAGE) LOG(Csr::Audit::LogLevel::Error, MESSAGE) +#define WARN(MESSAGE) LOG(Csr::Audit::LogLevel::Warning, MESSAGE) +#define INFO(MESSAGE) LOG(Csr::Audit::LogLevel::Info, MESSAGE) #if !defined(NDEBUG) -#define DEBUG(MESSAGE) LOG(Debug, MESSAGE) -#define TRACE(MESSAGE) LOG(Trace, MESSAGE) +#define DEBUG(MESSAGE) LOG(Csr::Audit::LogLevel::Debug, MESSAGE) +#define TRACE(MESSAGE) LOG(Csr::Audit::LogLevel::Trace, MESSAGE) #else #define DEBUG(MESSAGE) do {} while (false) #define TRACE(MESSAGE) do {} while (false) diff --git a/src/framework/common/exception.cpp b/src/framework/common/exception.cpp index 1c77ffb..10abb9c 100644 --- a/src/framework/common/exception.cpp +++ b/src/framework/common/exception.cpp @@ -26,11 +26,11 @@ namespace Csr { Exception::Exception(int ec, const char *file, const char *function, unsigned int line, - const std::string &message) noexcept : + Audit::LogLevel level, const std::string &message) noexcept : m_ec(ec), m_message(FORMAT("[" << file << ":" << line << " " << function << "()]" << message)) { - ERROR(this->m_message); + LOG(level, this->m_message); } const char *Exception::what() const noexcept diff --git a/src/framework/common/exception.h b/src/framework/common/exception.h index 6879c28..86ed4ff 100644 --- a/src/framework/common/exception.h +++ b/src/framework/common/exception.h @@ -35,7 +35,7 @@ namespace Csr { class API Exception : public std::exception { public: Exception(int ec, const char *file, const char *function, unsigned int line, - const std::string &message) noexcept; + Audit::LogLevel level, const std::string &message) noexcept; virtual ~Exception() = default; virtual const char *what() const noexcept final; @@ -48,5 +48,11 @@ protected: } // namespace Csr -#define ThrowExc(ec, MESSAGE) \ - throw Csr::Exception(ec, __FILE__, __FUNCTION__, __LINE__, FORMAT(MESSAGE)) +#define __CSR_THROW(ec, LEVEL, MESSAGE) \ + throw Csr::Exception(ec, __FILE__, __FUNCTION__, __LINE__, \ + Csr::Audit::LogLevel::LEVEL, FORMAT(MESSAGE)) + +#define ThrowExc(ec, MESSAGE) __CSR_THROW(ec, Error, MESSAGE) +#define ThrowExcWarn(ec, MESSAGE) __CSR_THROW(ec, Warning, MESSAGE) +#define ThrowExcInfo(ec, MESSAGE) __CSR_THROW(ec, Info, MESSAGE) +#define ThrowExcDebug(ec, MESSAGE) __CSR_THROW(ec, Debug, MESSAGE) diff --git a/src/framework/service/cs-loader.cpp b/src/framework/service/cs-loader.cpp index 79dea5f..524b0b7 100644 --- a/src/framework/service/cs-loader.cpp +++ b/src/framework/service/cs-loader.cpp @@ -254,8 +254,8 @@ void CsLoader::init(const std::string &enginePath, const std::string &roResDir, void *handle = dlopen(enginePath.c_str(), RTLD_LAZY); if (handle == nullptr) - ThrowExc(CSR_ERROR_ENGINE_NOT_EXIST, "engine dlopen error. path: " << enginePath << - " errno: " << errno); + ThrowExcWarn(CSR_ERROR_ENGINE_NOT_EXIST, "engine dlopen error. path: " << + enginePath << " errno: " << errno); this->m_pc.dlhandle = handle; diff --git a/src/framework/service/cs-logic.cpp b/src/framework/service/cs-logic.cpp index 26c6f76..b4da90d 100644 --- a/src/framework/service/cs-logic.cpp +++ b/src/framework/service/cs-logic.cpp @@ -115,7 +115,7 @@ std::string canonicalizePath(const std::string &path, bool checkAccess) if (checkAccess && !isReadable(path)) { const int err = errno; if (err == ENOENT) - ThrowExc(CSR_ERROR_FILE_DO_NOT_EXIST, "File do not exist: " << target); + ThrowExcWarn(CSR_ERROR_FILE_DO_NOT_EXIST, "File do not exist: " << target); else if (err == EACCES) ThrowExc(CSR_ERROR_PERMISSION_DENIED, "Perm denied to get real path: " << target); diff --git a/src/framework/service/file-system.cpp b/src/framework/service/file-system.cpp index 668061e..a87ce29 100644 --- a/src/framework/service/file-system.cpp +++ b/src/framework/service/file-system.cpp @@ -252,7 +252,8 @@ FilePtr File::createInternal(const std::string &fpath, time_t modifiedSince, auto statptr = getStat(fpath); if (statptr == nullptr) - ThrowExc(CSR_ERROR_FILE_DO_NOT_EXIST, "file not exist or no permission: " << fpath); + ThrowExcWarn(CSR_ERROR_FILE_DO_NOT_EXIST, "file not exist or no permission: " << + fpath); else if (!S_ISREG(statptr->st_mode) && !S_ISDIR(statptr->st_mode)) ThrowExc(CSR_ERROR_FILE_SYSTEM, "file type is not reguler or dir: " << fpath); @@ -278,7 +279,8 @@ FsVisitorPtr FsVisitor::create(const std::string &dirpath, time_t modifiedSince) { auto statptr = getStat(dirpath); if (statptr == nullptr) - ThrowExc(CSR_ERROR_FILE_DO_NOT_EXIST, "directory not exist or no permission: " << dirpath); + ThrowExcWarn(CSR_ERROR_FILE_DO_NOT_EXIST, "directory not exist or no " + "permission: " << dirpath); else if (!S_ISDIR(statptr->st_mode)) ThrowExc(CSR_ERROR_FILE_SYSTEM, "file type is not directory: " << dirpath); else diff --git a/src/framework/service/server-service.cpp b/src/framework/service/server-service.cpp index 6263815..b60f3bb 100644 --- a/src/framework/service/server-service.cpp +++ b/src/framework/service/server-service.cpp @@ -91,16 +91,16 @@ ServerService::ServerService() : Service(), m_workqueue(5) this->m_cs = std::make_shared<CsLoader>(CS_ENGINE_PATH, ENGINE_DIR, ENGINE_RW_WORKING_DIR); } catch (const Exception &e) { - ERROR("Excetpion in content screening loader: " << e.what() << - " error: " << e.error() << " treat it as ENGINE_NOT_EXIST."); + WARN("Excetpion in content screening loader: " << e.what() << + " error: " << e.error() << " treat it as ENGINE_NOT_EXIST."); } try { this->m_wp = std::make_shared<WpLoader>(WP_ENGINE_PATH, ENGINE_DIR, ENGINE_RW_WORKING_DIR); } catch (const Exception &e) { - ERROR("Exception in web protection loader: " << e.what() << - " error: " << e.error() << " treat it as ENGINE_NOT_EXIST."); + WARN("Exception in web protection loader: " << e.what() << + " error: " << e.error() << " treat it as ENGINE_NOT_EXIST."); } this->m_cslogic.reset(new CsLogic(this->m_cs, this->m_db)); diff --git a/src/framework/service/wp-loader.cpp b/src/framework/service/wp-loader.cpp index 6c95d2e..755ae59 100644 --- a/src/framework/service/wp-loader.cpp +++ b/src/framework/service/wp-loader.cpp @@ -205,8 +205,8 @@ void WpLoader::init(const std::string &enginePath, const std::string &roResDir, void *handle = dlopen(enginePath.c_str(), RTLD_LAZY); if (handle == nullptr) - ThrowExc(CSR_ERROR_ENGINE_NOT_EXIST, "engine dlopen error. path: " << enginePath << - " errno: " << errno); + ThrowExcWarn(CSR_ERROR_ENGINE_NOT_EXIST, "engine dlopen error. path: " << + enginePath << " errno: " << errno); this->m_pc.dlhandle = handle; |