Logging unification 89/35289/3
authorTomasz Iwanek <t.iwanek@samsung.com>
Thu, 5 Feb 2015 11:44:33 +0000 (12:44 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Wed, 18 Feb 2015 09:12:30 +0000 (10:12 +0100)
Because of existing idea of tagging step in logs,
this commit introduces one more macro:

SCOPE_LOG_TAG(TAG)

Defining this macro in given scope will change log tag of that
scope.

Example:

class StepXYZ : public Step {
  void func() {
    LOG(DEBUG) << "Status is ...";
  }

  SCOPE_LOG_TAG(XYZ)
};

Every log from class StepXYZ will be place with "XYZ" tag.

Change-Id: I8a8e192b0a746dae19a961e238a798b9b2c0c4b9

38 files changed:
src/common/app_installer.cc
src/common/app_installer.h
src/common/pkgmgr_signal.cc
src/common/security_registration.cc
src/common/step/step_copy.cc
src/common/step/step_copy.h
src/common/step/step_generate_xml.cc
src/common/step/step_generate_xml.h
src/common/step/step_parse.cc
src/common/step/step_parse.h
src/common/step/step_record.cc
src/common/step/step_record.h
src/common/step/step_remove.cc
src/common/step/step_remove.h
src/common/step/step_revoke_security.cc
src/common/step/step_revoke_security.h
src/common/step/step_security.cc
src/common/step/step_security.h
src/common/step/step_signal.cc
src/common/step/step_signal.h
src/common/step/step_signature.h
src/common/step/step_unregister.cc
src/common/step/step_unregister.h
src/common/step/step_unzip.cc
src/common/step/step_unzip.h
src/common/utils.cc
src/signature/signature_validator.cc
src/signature/signature_validator.h
src/utils/logging.h
src/utils/values.cc
src/wgt/step/step_parse.cc
src/wgt/step/step_parse.h
src/wgt/step/step_symbolic_link.cc
src/wgt/step/step_symbolic_link.h
src/widget-manifest-parser/application_data.cc
src/widget-manifest-parser/manifest_handlers/permissions_handler.cc
src/widget-manifest-parser/manifest_handlers/tizen_application_handler.cc
src/widget-manifest-parser/manifest_handlers/widget_handler.cc

index cef0eb1..c5825a2 100644 (file)
@@ -1,11 +1,11 @@
 /* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
 
-#include <iostream>
 #include <cstdio>
 
 #include "common/app_installer.h"
 #include "common/context_installer.h"
 #include "common/pkgmgr_signal.h"
+#include "utils/logging.h"
 
 namespace common_installer {
 
@@ -46,23 +46,23 @@ int AppInstaller::Run() {
   int ret = 0;
   for (; it != itEnd; ++it) {
     if ((*it)->process() != Step::Status::OK) {
-      std::cout << "Error during processing" << std::endl;
+      LOG(ERROR) << "Error during processing";
       ret = -1;
       break;
     }
   }
   if (it != itEnd) {
-    std::cout << "Failure occurs" << std::endl;
+    LOG(ERROR) << "Failure occurs";
     do {
       if ((*it)->undo() != Step::Status::OK) {
-        std::cout << "Error during undo operation" << std::endl;
+        LOG(ERROR) << "Error during undo operation";
         ret = -2;
       }
     } while (it-- != itStart);
   } else {
     while (it-- != itStart) {
       if ((*it)->clean() != Step::Status::OK) {
-        std::cout << "Error during clean operation" << std::endl;
+        LOG(ERROR) << "Error during clean operation";
         ret = -3;
         break;
       }
index 760d16c..2cf98a7 100644 (file)
@@ -8,6 +8,7 @@
 #include <memory>
 
 #include "common/step/step.h"
+#include "utils/logging.h"
 
 namespace common_installer {
 
@@ -35,6 +36,8 @@ class AppInstaller {
 
   std::list<std::unique_ptr<Step>> steps_;
   std::unique_ptr<ContextInstaller> context_;
+
+  SCOPE_LOG_TAG(AppInstaller)
 };
 
 }  // namespace common_installer
index e3e64ff..70d332e 100644 (file)
@@ -5,10 +5,8 @@
 #include "common/pkgmgr_signal.h"
 
 #include <cassert>
-#include <iostream>
 
-#define DBG(msg) std::cout << "[PkgmgrSignal] " << msg << std::endl;
-#define ERR(msg) std::cout << "[ERROR: PkgmgrSignal] " << msg << std::endl;
+#include "utils/logging.h"
 
 namespace common_installer {
 
@@ -63,13 +61,14 @@ bool PkgmgrSignal::SendSignal(
         !pkgid.empty() ? pkgid.c_str() : "",
         key,
         value)) {
-    ERR("Fail to send pkgmgr signal");
+    LOG(ERROR) << "Fail to send pkgmgr signal";
     return false;
   }
 
-  DBG("Success to send pkgmgr signal PKGID=" << pkgid
-                                << " KEY=" << key
-                                << " VALUE=" << value);
+  LOG(DEBUG) << "Success to send pkgmgr signal"
+             << " PKGID=" << pkgid
+             << " KEY=" << key
+             << " VALUE=" << value;
   return true;
 }
 
index 2c55ba5..1a4db3d 100644 (file)
@@ -6,11 +6,7 @@
 
 #include <security-manager.h>
 
-#include <iostream>
-
-// TODO(t.iwanek): logging mechanism...
-#define DBG(msg) std::cout << "[DEBUG:SecurityContext] " << msg << std::endl;
-#define ERR(msg) std::cout << "[ERROR:SecurityContext] " << msg << std::endl;
+#include "utils/logging.h"
 
 namespace bf = boost::filesystem;
 
@@ -20,7 +16,7 @@ bool PrepareRequest(const std::string& app_id, const std::string& pkg_id,
     const boost::filesystem::path& path, manifest_x* manifest,
     app_inst_req* req) {
   if (app_id.empty() || pkg_id.empty()) {
-    ERR("Appid or pkgid is empty. Both values must be set");
+    LOG(ERROR) << "Appid or pkgid is empty. Both values must be set";
     return false;
   }
 
@@ -63,21 +59,22 @@ bool RegisterSecurityContext(const std::string& app_id,
 
   int error = security_manager_app_inst_req_new(&req);
   if (error != SECURITY_MANAGER_SUCCESS) {
-    ERR("Failed while calling security_manager_app_inst_req_new failed "
-        << "(error code: " << error << ")");
+    LOG(ERROR)
+        << "Failed while calling security_manager_app_inst_req_new failed "
+        << "(error code: " << error << ")";
     return false;
   }
 
   if (!PrepareRequest(app_id, pkg_id, path, manifest, req)) {
-      ERR("Failed while preparing security_manager_app_inst_req");
+      LOG(ERROR) << "Failed while preparing security_manager_app_inst_req";
       security_manager_app_inst_req_free(req);
       return false;
   }
 
   error = security_manager_app_install(req);
   if (error != SECURITY_MANAGER_SUCCESS) {
-    ERR("Failed while calling security_manager_app_install failed "
-        << "(error code: " << error << ")");
+    LOG(ERROR) << "Failed while calling security_manager_app_install failed "
+               << "(error code: " << error << ")";
     security_manager_app_inst_req_free(req);
     return false;
   }
@@ -93,21 +90,21 @@ bool UnregisterSecurityContext(const std::string& app_id,
 
   int error = security_manager_app_inst_req_new(&req);
   if (error != SECURITY_MANAGER_SUCCESS) {
-    ERR("Failed while calling security_manager_app_inst_req_new  "
-        << "(error code: " << error << ")");
+    LOG(ERROR) << "Failed while calling security_manager_app_inst_req_new  "
+               << "(error code: " << error << ")";
     return false;
   }
 
   if (!PrepareRequest(app_id, pkg_id, bf::path(), nullptr, req)) {
-    ERR("Failed while preparing security_manager_app_inst_req");
+    LOG(ERROR) << "Failed while preparing security_manager_app_inst_req";
     security_manager_app_inst_req_free(req);
     return false;
   }
 
   error = security_manager_app_uninstall(req);
   if (error != SECURITY_MANAGER_SUCCESS) {
-    ERR("Failed while calling  security_manager_app_uninstall failed "
-        << "(error code: " << error << ")");
+    LOG(ERROR) << "Failed while calling  security_manager_app_uninstall failed "
+               << "(error code: " << error << ")";
     security_manager_app_inst_req_free(req);
     return false;
   }
index b62e5f0..daafde7 100644 (file)
@@ -4,14 +4,10 @@
 
 #include <cassert>
 #include <cstring>
-#include <iostream>
 #include <string>
 
 #include "common/utils.h"
 
-#define DBG(msg) std::cout << "[Copy] " << msg << std::endl;
-#define ERR(msg) std::cout << "[ERROR: Copy] " << msg << std::endl;
-
 namespace common_installer {
 namespace copy {
 
@@ -34,18 +30,18 @@ Step::Status StepCopy::process() {
     install_path /= fs::path(context_->manifest_data()->mainapp_id);
 
   if (!utils::CopyDir(fs::path(context_->unpack_directory()), install_path)) {
-    ERR("Fail to copy tmp dir: " << context_->unpack_directory()
-        << " to dst dir: " << install_path.string());
+    LOG(ERROR) << "Fail to copy tmp dir: " << context_->unpack_directory()
+               << " to dst dir: " << install_path.string();
     return Step::Status::ERROR;
   }
 
-  DBG("Successfully copy: " << context_->unpack_directory()
-      << " to: " << install_path.string() << " directory");
+  LOG(INFO) << "Successfully copy: " << context_->unpack_directory()
+            << " to: " << install_path.string() << " directory";
   return Status::OK;
 }
 
 Step::Status StepCopy::clean() {
-  DBG("Remove tmp dir: " << context_->unpack_directory());
+  LOG(DEBUG) << "Remove tmp dir: " << context_->unpack_directory();
   fs::remove_all(context_->unpack_directory());
   return Status::OK;
 }
index 48e92f3..7c77a9a 100644 (file)
@@ -6,6 +6,7 @@
 #include "common/context_installer.h"
 
 #include "common/step/step.h"
+#include "utils/logging.h"
 
 namespace common_installer {
 namespace copy {
@@ -17,6 +18,8 @@ class StepCopy : public Step {
   Status process() override;
   Status clean() override;
   Status undo() override;
+
+  SCOPE_LOG_TAG(Copy)
 };
 
 }  // namespace copy
index 25f5043..4498ab0 100644 (file)
 
 #include <cassert>
 #include <cstring>
-#include <iostream>
 #include <string>
 
 #include "common/utils.h"
 
-#define DBG(msg) std::cout << "[GenerateXML] " << msg << std::endl;
-#define ERR(msg) std::cout << "[ERROR: GenerateXML] " << msg << std::endl;
-
 namespace fs = boost::filesystem;
 
 namespace common_installer {
@@ -36,8 +32,8 @@ Step::Status StepGenerateXml::process() {
   boost::system::error_code error;
   if ((!context_->manifest_data()->uiapplication) &&
      (!context_->manifest_data()->serviceapplication)) {
-    ERR("There is neither UI applications nor"
-        << "Services applications described!\n");
+    LOG(ERROR) << "There is neither UI applications nor"
+               << "Services applications described!";
     return Step::Status::ERROR;
   }
 
@@ -48,7 +44,7 @@ Step::Status StepGenerateXml::process() {
 
   writer = xmlNewTextWriterFilename(context_->xml_path().c_str(), 0);
   if (!writer) {
-    ERR("Failed to create new file\n");
+    LOG(ERROR) << "Failed to create new file";
     return Step::Status::ERROR;
   }
 
@@ -116,7 +112,7 @@ Step::Status StepGenerateXml::process() {
       fs::rename(app_icon, icon_path_ /= icon);
     } else {
       fs::create_symlink(default_icon, icon_path_ /= icon, error);
-      DBG("Icon is not found in package, the default icon is setting");
+      LOG(DEBUG) << "Icon is not found in package, the default icon is setting";
     }
 
     xmlTextWriterWriteFormatElement(writer, BAD_CAST "icon",
@@ -178,7 +174,7 @@ Step::Status StepGenerateXml::process() {
       fs::rename(app_icon, icon_path_ /= icon);
     } else {
       fs::rename(default_icon, icon_path_ /= icon);
-      DBG("Icon is not found in package, the default icon is setting");
+      LOG(DEBUG) << "Icon is not found in package, the default icon is setting";
     }
 
     for (appcontrol_x* appc_svc = svc->appcontrol; appc_svc != nullptr;
@@ -224,11 +220,11 @@ Step::Status StepGenerateXml::process() {
 
   if (pkgmgr_parser_check_manifest_validation(
       context_->xml_path().c_str()) != 0) {
-    DBG("Manifest is not valid");
+    LOG(ERROR) << "Manifest is not valid";
     return Step::Status::ERROR;
   }
 
-  DBG("Successfully create manifest xml " << context_->xml_path());
+  LOG(DEBUG) << "Successfully create manifest xml " << context_->xml_path();
   return Status::OK;
 }
 
index ff5a0c9..021d70c 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "common/context_installer.h"
 #include "common/step/step.h"
+#include "utils/logging.h"
 
 namespace common_installer {
 namespace generate_xml {
@@ -22,6 +23,8 @@ class StepGenerateXml : public Step {
 
  private:
   boost::filesystem::path icon_path_;
+
+  SCOPE_LOG_TAG(GenerateXML)
 };
 
 }  // namespace generate_xml
index 5a9d220..6d73767 100644 (file)
@@ -8,15 +8,11 @@
 #include <boost/filesystem.hpp>
 #include <cassert>
 #include <cstring>
-#include <iostream>
 #include <cstdio>
 #include <string>
 
 #include "common/utils.h"
 
-#define DBG(msg) std::cout << "[Parse] " << msg << std::endl;
-#define ERR(msg) std::cout << "[ERROR: Parse] " << msg << std::endl;
-
 namespace common_installer {
 namespace parse {
 
@@ -32,14 +28,14 @@ Step::Status StepParse::process() {
   manifest_x* mfx = pkgmgr_parser_usr_process_manifest_xml(
     context_->xml_path().c_str(), context_->uid());
   if (!mfx) {
-    DBG("Failed to parse tizen manifest xml " << context_->xml_path().c_str());
+    LOG(ERROR) << "Failed to parse tizen manifest xml " << context_->xml_path();
     return Step::Status::ERROR;
   }
 
   context_->set_manifest(mfx);
   context_->set_pkg_path(context_->GetApplicationPath());
 
-  DBG("Successfully parse tizen manifest xml");
+  LOG(DEBUG) << "Successfully parse tizen manifest xml";
 
   return Status::OK;
 }
index d0b6938..029483d 100644 (file)
@@ -6,6 +6,7 @@
 #include "common/context_installer.h"
 
 #include "common/step/step.h"
+#include "utils/logging.h"
 
 namespace common_installer {
 namespace parse {
@@ -17,6 +18,8 @@ class StepParse : public Step {
   Status process() override;
   Status clean() override;
   Status undo() override;
+
+  SCOPE_LOG_TAG(Parse)
 };
 
 }  // namespace parse
index 1f9ea42..6656455 100644 (file)
@@ -8,13 +8,10 @@
 #include <boost/filesystem.hpp>
 #include <cassert>
 #include <cstring>
-#include <iostream>
 #include <cstdio>
 #include <string>
-#include "common/utils.h"
 
-#define DBG(msg) std::cout << "[Record] " << msg << std::endl;
-#define ERR(msg) std::cout << "[ERROR: Record] " << msg << std::endl;
+#include "common/utils.h"
 
 namespace {
 
@@ -48,10 +45,10 @@ Step::Status StepRecord::process() {
           context_->xml_path().c_str(), appinst_tags);
 
   if (ret != 0) {
-    ERR("Failed to record package into database");
+    LOG(ERROR) << "Failed to record package into database";
     return Step::Status::ERROR;
   }
-  DBG("Successfully install the application");
+  LOG(INFO) << "Successfully install the application";
   return Status::OK;
 }
 
@@ -69,11 +66,11 @@ Step::Status StepRecord::undo() {
       cmd = std::string(kAilInit) + ";" + kPkgInit;
 
   if (execv(cmd.c_str(), nullptr) == -1) {
-      ERR("Error during execvp %s");
+      LOG(ERROR) << "Error during execvp %s";
       return Step::Status::ERROR;
   }
 
-  DBG("Successfuly clean database");
+  LOG(INFO) << "Successfuly clean database";
   return Status::OK;
 }
 
index d24a2f2..fadeac4 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "common/context_installer.h"
 #include "common/step/step.h"
+#include "utils/logging.h"
 
 namespace common_installer {
 namespace record {
@@ -16,6 +17,8 @@ class StepRecord : public Step {
   Status process() override;
   Status clean() override;
   Status undo() override;
+
+  SCOPE_LOG_TAG(Record)
 };
 
 }  // namespace record
index cbbadcd..c588e2c 100755 (executable)
@@ -8,13 +8,9 @@
 #include <pkgmgr-info.h>
 
 #include <cstring>
-#include <iostream>
 
 #include "common/utils.h"
 
-#define DBG(msg) std::cout << "[Remove] " << msg << std::endl;
-#define ERR(msg) std::cout << "[ERROR: Remove] " << msg << std::endl;
-
 namespace common_installer {
 namespace remove {
 
@@ -24,7 +20,7 @@ Step::Status StepRemove::process() {
   uiapplication_x* ui = context_->manifest_data()->uiapplication;
 
   if (!fs::exists(context_->pkg_path()))
-    DBG("dir: " << context_->pkg_path() << "not exist");
+    LOG(DEBUG) << "dir: " << context_->pkg_path() << "not exist";
 
   fs::remove_all(context_->pkg_path());
   for (; ui != nullptr; ui = ui->next) {
@@ -36,7 +32,7 @@ Step::Status StepRemove::process() {
   }
   fs::remove_all(context_->xml_path());
 
-  DBG("Removing dir: " << context_->pkg_path());
+  LOG(DEBUG) << "Removing dir: " << context_->pkg_path();
 
   return Status::OK;
 }
index 3cf460a..ac79aed 100755 (executable)
@@ -8,6 +8,7 @@
 #include "common/context_installer.h"
 
 #include "common/step/step.h"
+#include "utils/logging.h"
 
 namespace common_installer {
 namespace remove {
@@ -19,6 +20,8 @@ class StepRemove : public Step {
   Status process() override;
   Status clean() override;
   Status undo() override;
+
+  SCOPE_LOG_TAG(Remove)
 };
 
 }  // namespace remove
index e7f476c..20a9f2b 100644 (file)
@@ -4,14 +4,8 @@
 
 #include "common/step/step_revoke_security.h"
 
-#include <iostream>
-
 #include "common/security_registration.h"
 
-// TODO(t.iwanek): logging mechanism...
-#define DBG(msg) std::cout << "[RevokeSecurity] " << msg << std::endl;
-#define ERR(msg) std::cout << "[ERROR:RevokeSecurity] " << msg << std::endl;
-
 namespace common_installer {
 namespace revoke_security {
 
@@ -20,7 +14,7 @@ Step::Status StepRevokeSecurity::process() {
       context_->pkgid(), context_->manifest_data())) {
     return Status::ERROR;
   }
-  DBG("Security context uninstalled");
+  LOG(DEBUG) << "Security context uninstalled";
   return Status::OK;
 }
 
@@ -30,7 +24,7 @@ Step::Status StepRevokeSecurity::undo() {
       context_->manifest_data())) {
     return Status::ERROR;
   }
-  DBG("Security context installed");
+  LOG(DEBUG) << "Security context installed";
   return Status::OK;
 }
 
index eb981a2..5c8a716 100644 (file)
@@ -6,6 +6,7 @@
 #define COMMON_STEP_STEP_REVOKE_SECURITY_H_
 
 #include "common/step/step.h"
+#include "utils/logging.h"
 
 namespace common_installer {
 namespace revoke_security {
@@ -18,6 +19,8 @@ class StepRevokeSecurity : public Step {
   Status process() override;
   Status undo() override;
   Status clean() override { return Status::OK; }
+
+  SCOPE_LOG_TAG(RevokeSecurity)
 };
 
 }  // namespace revoke_security
index 0216fdc..573d7c6 100644 (file)
@@ -4,14 +4,8 @@
 
 #include "common/step/step_security.h"
 
-#include <iostream>
-
 #include "common/security_registration.h"
 
-// TODO(t.iwanek): logging mechanism...
-#define DBG(msg) std::cout << "[Security] " << msg << std::endl;
-#define ERR(msg) std::cout << "[ERROR:Security] " << msg << std::endl;
-
 namespace common_installer {
 namespace security {
 
@@ -21,7 +15,7 @@ Step::Status StepSecurity::process() {
       context_->manifest_data())) {
     return Status::ERROR;
   }
-  DBG("Security context installed");
+  LOG(DEBUG) << "Security context installed";
   return Status::OK;
 }
 
@@ -30,7 +24,7 @@ Step::Status StepSecurity::undo() {
       context_->pkgid(), context_->manifest_data())) {
     return Status::ERROR;
   }
-  DBG("Security context uninstalled");
+  LOG(DEBUG) << "Security context uninstalled";
   return Status::OK;
 }
 
index 43d7422..6e1fc72 100644 (file)
@@ -6,6 +6,7 @@
 #define COMMON_STEP_STEP_SECURITY_H_
 
 #include "common/step/step.h"
+#include "utils/logging.h"
 
 namespace common_installer {
 namespace security {
@@ -17,6 +18,8 @@ class StepSecurity : public Step {
   Status process() override;
   Status undo() override;
   Status clean() override { return Status::OK; }
+
+  SCOPE_LOG_TAG(Security)
 };
 
 }  // namespace security
index 209552d..25f6002 100644 (file)
@@ -2,13 +2,11 @@
 
 #include "common/step/step_signal.h"
 
-#include <iostream>
+#include <pkgmgr-info.h>
+#include <unistd.h>
 
 #include "common/utils.h"
 
-#define DBG(msg) std::cout << "[Signal] " << msg << std::endl;
-#define ERR(msg) std::cout << "[ERROR: Signal] " << msg << std::endl;
-
 namespace common_installer {
 namespace signal {
 
@@ -17,7 +15,7 @@ Step::Status StepSignal::process() {
       context_->manifest_data()->type, context_->pkgid())) {
     return Status::ERROR;
   }
-  DBG("Send Start");
+  LOG(DEBUG) << "Send Start";
   return Status::OK;
 }
 
@@ -27,7 +25,7 @@ Step::Status StepSignal::clean() {
         context_->manifest_data()->type, context_->pkgid())) {
     return Status::ERROR;
   }
-  DBG("Send Success");
+  LOG(DEBUG) << "Send Success";
   return Status::OK;
 }
 
@@ -37,7 +35,7 @@ Step::Status StepSignal::undo() {
         context_->manifest_data()->type, context_->pkgid())) {
     return Status::ERROR;
   }
-  DBG("Send Error");
+  LOG(ERROR) << "Send Error";
   return Status::OK;
 }
 
index 5843294..e214d0b 100644 (file)
@@ -8,6 +8,7 @@
 #include "common/context_installer.h"
 
 #include "common/step/step.h"
+#include "utils/logging.h"
 
 namespace common_installer {
 namespace signal {
@@ -19,6 +20,12 @@ class StepSignal : public Step {
   Status process() override;
   Status clean() override;
   Status undo() override;
+
+ private:
+  bool sendSignal(ContextInstaller* data, const std::string& key,
+      const std::string& value);
+
+  SCOPE_LOG_TAG(Signal)
 };
 
 }  // namespace signal
index 2091887..1cf5ce4 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "common/context_installer.h"
 #include "common/step/step.h"
+#include "utils/logging.h"
 
 namespace common_installer {
 namespace signature {
@@ -18,6 +19,8 @@ class StepSignature : public Step {
   Status process() override;
   Status undo() override { return Status::OK; }
   Status clean() override { return Status::OK; }
+
+  SCOPE_LOG_TAG(Signature)
 };
 
 }  // namespace signature
index 763737e..4bd9d52 100755 (executable)
@@ -7,12 +7,9 @@
 #include <boost/filesystem.hpp>
 #include <cassert>
 #include <cstring>
-#include <iostream>
 
 #include "common/step/step_unregister.h"
 #include "common/utils.h"
-#define DBG(msg) std::cout << "[Unregister] " << msg << std::endl;
-#define ERR(msg) std::cout << "[ERROR: Unregister] " << msg << std::endl;
 
 namespace common_installer {
 namespace unregister {
@@ -31,21 +28,21 @@ Step::Status StepUnregister::process() {
           context_->xml_path().c_str(), appinst_tags);
 
   if (ret != 0) {
-    DBG("Failed to unregister package into database");
+    LOG(ERROR) << "Failed to unregister package into database";
     return Status::ERROR;
   }
-  DBG("Successfully unregister the application");
+  LOG(DEBUG) << "Successfully unregister the application";
 
   return Status::OK;
 }
 
 Step::Status StepUnregister::clean() {
-  DBG("Empty 'clean' method");
+  LOG(DEBUG) << "Empty 'clean' method";
   return Status::OK;
 }
 
 Step::Status StepUnregister::undo() {
-  DBG("Empty 'undo' method");
+  LOG(DEBUG) << "Empty 'undo' method";
   return Status::OK;
 }
 
index 5a5a910..7000f55 100755 (executable)
@@ -7,6 +7,7 @@
 
 #include "common/context_installer.h"
 #include "common/step/step.h"
+#include "utils/logging.h"
 
 namespace common_installer {
 namespace unregister {
@@ -18,6 +19,8 @@ class StepUnregister : public Step {
   Step::Status process() override;
   Step::Status clean() override;
   Step::Status undo() override;
+
+  SCOPE_LOG_TAG(Unregister)
 };
 
 }  // namespace unregister
index 3ebb761..08d5639 100644 (file)
 #include <cstdlib>
 #include <climits>
 #include <cstring>
-#include <iostream>
 #include <string>
 
 #include "common/utils.h"
 
-#define DBG(msg) std::cout << "[Unzip] " << msg << std::endl;
-#define ERR(msg) std::cout << "[ERROR: Unzip] " << msg << std::endl;
-
 #define ZIPBUFSIZE 8192
 #define ZIPMAXPATH 256
 
@@ -52,7 +48,7 @@ boost::filesystem::path StepUnzip::GenerateTmpDir(const char* app_path) {
 Step::Status StepUnzip::ExtractToTmpDir(const char* src,
     const boost::filesystem::path& tmp_dir) {
   if (is_extracted_) {
-    ERR(src << " is already extracted");
+    LOG(ERROR) << src << " is already extracted";
     return Status::OK;
   }
 
@@ -65,12 +61,12 @@ Step::Status StepUnzip::ExtractToTmpDir(const char* src,
 
   unzFile* zip_file = static_cast<unzFile*>(unzOpen(src));
   if (zip_file == NULL) {
-    ERR("Failed to open the source dir: " << src);
+    LOG(ERROR) << "Failed to open the source dir: " << src;
     return Step::Status::ERROR;
   }
 
   if (unzGetGlobalInfo(zip_file, &info) != UNZ_OK) {
-    ERR("Failed to read global info");
+    LOG(ERROR) << "Failed to read global info";
     unzClose(zip_file);
     return Step::Status::ERROR;
   }
@@ -78,7 +74,7 @@ Step::Status StepUnzip::ExtractToTmpDir(const char* src,
   for (uLong i = 0; i < info.number_entry; i++) {
     if (unzGetCurrentFileInfo(zip_file, &raw_file_info, raw_file_name_in_zip,
         sizeof(raw_file_name_in_zip), NULL, 0, NULL, 0) != UNZ_OK) {
-      ERR("Failed to read file info");
+      LOG(ERROR) << "Failed to read file info";
       unzClose(zip_file);
       return Step::Status::ERROR;
     }
@@ -89,14 +85,14 @@ Step::Status StepUnzip::ExtractToTmpDir(const char* src,
     boost::filesystem::path filename_in_zip_path(raw_file_name_in_zip);
     if (!filename_in_zip_path.parent_path().empty()) {
       if (!utils::CreateDir(filename_in_zip_path.parent_path())) {
-        ERR("Failed to create directory: "
-            << filename_in_zip_path.parent_path());
+        LOG(ERROR) << "Failed to create directory: "
+            << filename_in_zip_path.parent_path();
         return Step::Status::ERROR;
       }
     }
 
     if (unzOpenCurrentFile(zip_file) != UNZ_OK) {
-      ERR("Failed to open file");
+      LOG(ERROR) << "Failed to open file";
       unzClose(zip_file);
       return Step::Status::ERROR;
     }
@@ -104,7 +100,7 @@ Step::Status StepUnzip::ExtractToTmpDir(const char* src,
     if (!is_directory(filename_in_zip_path)) {
       FILE *out = fopen(raw_file_name_in_zip, "wb");
       if (!out) {
-        ERR("Failed to open destination ");
+        LOG(ERROR) << "Failed to open destination ";
         unzCloseCurrentFile(zip_file);
         return Step::Status::ERROR;
       }
@@ -113,7 +109,7 @@ Step::Status StepUnzip::ExtractToTmpDir(const char* src,
       do {
         ret = unzReadCurrentFile(zip_file, read_buffer, ZIPBUFSIZE);
         if (ret < 0) {
-          ERR("Failed to read data: " << ret);
+          LOG(ERROR) << "Failed to read data: " << ret;
           unzCloseCurrentFile(zip_file);
           return Step::Status::ERROR;
         } else {
@@ -126,7 +122,7 @@ Step::Status StepUnzip::ExtractToTmpDir(const char* src,
 
     if ((i+1) < info.number_entry) {
       if (unzGoToNextFile(zip_file) != UNZ_OK) {
-        ERR("Failed to read next file");
+        LOG(ERROR) << "Failed to read next file";
         unzCloseCurrentFile(zip_file);
         return Step::Status::ERROR;
       }
@@ -146,26 +142,26 @@ Step::Status StepUnzip::process() {
       GenerateTmpDir(context_->GetRootApplicationPath());
 
   if (!utils::CreateDir(tmp_dir)) {
-    ERR("Failed to create temp directory: " << tmp_dir);
+    LOG(ERROR) << "Failed to create temp directory: " << tmp_dir;
     return Step::Status::ERROR;
   }
 
   if (ExtractToTmpDir(context_->file_path().c_str(), tmp_dir)
       != Step::Status::OK) {
-    ERR("Failed to process unpack step");
+    LOG(ERROR) << "Failed to process unpack step";
     return Step::Status::ERROR;
   }
   context_->set_unpack_directory(tmp_dir.string());
 
-  DBG(context_->file_path() << " was successfully unzipped into "
-      << context_->unpack_directory());
+  LOG(INFO) << context_->file_path() << " was successfully unzipped into "
+            << context_->unpack_directory();
   return Status::OK;
 }
 
 Step::Status StepUnzip::undo() {
   if (access(context_->unpack_directory().c_str(), F_OK) == 0) {
     boost::filesystem::remove_all(context_->unpack_directory());
-    DBG("remove temp dir: " << context_->unpack_directory());
+    LOG(DEBUG) << "remove temp dir: " << context_->unpack_directory();
   }
   return Status::OK;
 }
index 5620144..868aeb7 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "common/context_installer.h"
 #include "common/step/step.h"
+#include "utils/logging.h"
 
 namespace common_installer {
 namespace unzip {
@@ -25,6 +26,8 @@ class StepUnzip : public Step {
       const boost::filesystem::path& tmp_dir);
 
   bool is_extracted_;
+
+  SCOPE_LOG_TAG(Unzip)
 };
 
 }  // namespace unzip
index 804a090..5130417 100644 (file)
@@ -3,10 +3,9 @@
 #include "common/utils.h"
 
 #include <boost/filesystem/path.hpp>
-#include <iostream>
 #include <string>
 
-#define ERR(msg) std::cout << "[ERROR] " << msg << std::endl;
+#include "utils/logging.h"
 
 namespace utils {
 
@@ -19,8 +18,8 @@ bool CreateDir(const fs::path& path) {
   boost::system::error_code error;
   fs::create_directories(path, error);
   if (error) {
-    ERR("Failed to create directory: "
-        << boost::system::system_error(error).what());
+    LOG(ERROR) << "Failed to create directory: "
+               << boost::system::system_error(error).what();
     return false;
   }
 
@@ -28,8 +27,8 @@ bool CreateDir(const fs::path& path) {
       | fs::group_read | fs::others_read,
       error);
   if (error) {
-    ERR("Failed to set permission: "
-        << boost::system::system_error(error).what());
+    LOG(ERROR) << "Failed to set permission: "
+               << boost::system::system_error(error).what();
     return false;
   }
   return true;
@@ -39,21 +38,22 @@ bool CopyDir(const fs::path& src, const fs::path& dst) {
   try {
     // Check whether the function call is valid
     if (!fs::exists(src) || !fs::is_directory(src)) {
-      ERR("Source directory " << src.string()
-          << " does not exist or is not a directory.");
+      LOG(ERROR) << "Source directory " << src.string()
+                 << " does not exist or is not a directory.";
       return false;
     }
     if (fs::exists(dst)) {
-      ERR("Destination directory " << dst.string() << " already exists.");
+      LOG(ERROR) << "Destination directory " << dst.string()
+                 << " already exists.";
       return false;
     }
     // Create the destination directory
     if (!CreateDir(dst)) {
-      ERR("Unable to create destination directory" << dst.string());
+      LOG(ERROR) << "Unable to create destination directory" << dst.string();
       return false;
     }
   } catch (const fs::filesystem_error& error) {
-      ERR(error.what());
+      LOG(ERROR) << error.what();
   }
 
   // Iterate through the source directory
@@ -72,7 +72,7 @@ bool CopyDir(const fs::path& src, const fs::path& dst) {
         fs::copy_file(current, dst / current.filename());
       }
     } catch (const fs::filesystem_error& error) {
-        ERR(error.what());
+        LOG(ERROR) << error.what();
     }
   }
   return true;
index 882d800..f9070c0 100644 (file)
@@ -16,7 +16,6 @@
 #include <set>
 #include <string>
 
-#include "utils/logging.h"
 #include "signature/signature_data.h"
 #include "signature/signature_parser.h"
 #include "signature/signature_xmlsec_adaptor.h"
index 824951c..ebe8bdd 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <string>
 
+#include "utils/logging.h"
 #include "utils/macros.h"
 
 namespace common_installer {
@@ -28,6 +29,8 @@ class SignatureValidator {
   static Status Check(const boost::filesystem::path& widget_path);
 
  private:
+  SCOPE_LOG_TAG(SignatureValidator)
+
   DISALLOW_COPY_AND_ASSIGN(SignatureValidator);
 };
 
index 58c254d..ec91119 100644 (file)
@@ -6,6 +6,7 @@
 #define UTILS_LOGGING_H_
 
 #include <cassert>
+#include <iomanip>
 #include <iostream>
 #include <sstream>
 
@@ -20,16 +21,16 @@ enum class LogLevel {
 
 template<LogLevel> struct LogTag;
 template<> struct LogTag<LogLevel::LOG_ERROR> {
-  static constexpr const char* value = "\033[0;31m[ERROR]  \033[0m";
+  static constexpr const char* value = "\033[1;31m| ERROR   |\033[0m";
 };
 template<> struct LogTag<LogLevel::LOG_WARNING> {
-  static constexpr const char* value = "\033[0;33m[WARNING]\033[0m";
+  static constexpr const char* value = "\033[1;33m| WARNING |\033[0m";
 };
 template<> struct LogTag<LogLevel::LOG_INFO>  {
-  static constexpr const char* value = "\033[0;32m[INFO]   \033[0m";
+  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";
+  static constexpr const char* value = "\033[0m| DEBUG   |\033[0m";
 };
 
 class LogCatcher {
@@ -44,12 +45,25 @@ class LogCatcher {
 
 }  // namespace utils
 
+inline static const constexpr char* __tag_for_logging() {
+  return "";
+}
+
+// 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() & std::ostringstream()                               \
-      << ::utils::LogTag<::utils::LogLevel::LOG_##LEVEL>::value                \
+      << ::utils::LogTag<::utils::LogLevel::LOG_ ## LEVEL>::value              \
+      << " " << std::setw(20) << std::left << __tag_for_logging()              \
+      << std::setw(0) << " : "                                                 \
 
 #endif  // UTILS_LOGGING_H_
index 2c93108..f82e8d8 100644 (file)
@@ -11,8 +11,8 @@
 #include <algorithm>
 #include <cassert>
 #include <cmath>
-#include <iostream>
-#include <ostream>
+
+#include "utils/logging.h"
 
 namespace common_installer {
 namespace utils {
@@ -167,8 +167,8 @@ FundamentalValue::FundamentalValue(int in_value)
 FundamentalValue::FundamentalValue(double in_value)
     : Value(TYPE_DOUBLE), double_value_(in_value) {
   if (!std::isfinite(double_value_)) {
-    std::cerr << "Non-finite (i.e. NaN or positive/negative infinity) "
-              << "values cannot be represented in JSON";
+    LOG(ERROR) << "Non-finite (i.e. NaN or positive/negative infinity) "
+               << "values cannot be represented in JSON";
     double_value_ = 0.0;
   }
 }
@@ -208,7 +208,7 @@ FundamentalValue* FundamentalValue::DeepCopy() const {
       return new FundamentalValue(double_value_);
 
     default:
-      std::cerr << "Not reached.\n";
+      LOG(ERROR) << "Not reached";
       return nullptr;
   }
 }
@@ -231,7 +231,7 @@ bool FundamentalValue::Equals(const Value* other) const {
       return GetAsDouble(&lhs) && other->GetAsDouble(&rhs) && lhs == rhs;
     }
     default:
-      std::cerr << "Not reached.\n";
+      LOG(ERROR) << "Not reached";
       return false;
   }
 }
index 2739f1f..e52a2b9 100644 (file)
@@ -8,7 +8,6 @@
 
 #include <cstdio>
 #include <cstdlib>
-#include <iostream>
 #include <string>
 
 #include "common/app_installer.h"
@@ -20,16 +19,16 @@ namespace parse {
 
 common_installer::Step::Status StepParse::process() {
   if (!StepParse::Check(context_->unpack_directory())) {
-    std::cout << "[Parse] No config.xml" << std::endl;
+    LOG(ERROR) << "No config.xml";
     return common_installer::Step::Status::ERROR;
   }
 
   const ManifestData* data = nullptr;
   const char* error = nullptr;
   if (!ParseManifest(config_.c_str(), &data, &error)) {
-    std::cout << "[Parse] Parse failed. " <<  error << std::endl;
+     LOG(ERROR) << "Parse failed. " <<  error;
     if (!ReleaseData(data, error))
-      std::cout << "[Parse] Release data failed." << std::endl;
+      LOG(ERROR) << " Release data failed.";
     return common_installer::Step::Status::ERROR;
   }
 
@@ -42,24 +41,22 @@ common_installer::Step::Status StepParse::process() {
       std::string(data->package));
   fillManifest(data, context_->manifest_data());
 
-  //--- Test ---
-  std::cout << "[Parse] Read data -[ " << std::endl;
-  std::cout << "  package     = " <<  data->package << std::endl;
-  std::cout << "  id          = " <<  data->id << std::endl;
-  std::cout << "  name        = " <<  data->name << std::endl;
-  std::cout << "  short_name  = " <<  data->short_name << std::endl;
-  std::cout << "  version     = " <<  data->version << std::endl;
-  std::cout << "  icon        = " <<  data->icon << std::endl;
-  std::cout << "  api_version = " <<  data->api_version << std::endl;
-  std::cout << "  privileges -[" << std::endl;
+  LOG(DEBUG) << " Read data -[ ";
+  LOG(DEBUG) << "  package     = " <<  data->package;
+  LOG(DEBUG) << "  id          = " <<  data->id;
+  LOG(DEBUG) << "  name        = " <<  data->name;
+  LOG(DEBUG) << "  short_name  = " <<  data->short_name;
+  LOG(DEBUG) << "  version     = " <<  data->version;
+  LOG(DEBUG) << "  icon        = " <<  data->icon;
+  LOG(DEBUG) << "  api_version = " <<  data->api_version;
+  LOG(DEBUG) << "  privileges -[";
   for (unsigned int i = 0; i < data->privilege_count; ++i)
-    std::cout << "    " << data->privilege_list[i] << std::endl;
-  std::cout << "  ]-" << std::endl;
-  std::cout << "]-" << std::endl;
-  //--- End Test ---
+    LOG(DEBUG) << "    " << data->privilege_list[i];
+  LOG(DEBUG) << "  ]-";
+  LOG(DEBUG) << "]-";
 
   if (!ReleaseData(data, error)) {
-    std::cout << "[Parse] Release data failed." << std::endl;
+    LOG(ERROR) << "Release data failed.";
     return common_installer::Step::Status::ERROR;
   }
 
@@ -70,7 +67,7 @@ bool StepParse::Check(const boost::filesystem::path& widget_path) {
   boost::filesystem::path config = widget_path;
   config /= "config.xml";
 
-  std::cout << "[Parse] config.xml path: " << config << std::endl;
+  LOG(DEBUG) << "config.xml path: " << config;
 
   if (!boost::filesystem::exists(config))
     return false;
index 2a9227c..f8ec754 100644 (file)
@@ -10,6 +10,7 @@
 #include "common/app_installer.h"
 #include "common/context_installer.h"
 #include "common/step/step.h"
+#include "utils/logging.h"
 
 namespace wgt {
 namespace parse {
@@ -26,6 +27,8 @@ class StepParse : public common_installer::Step {
   boost::filesystem::path config_;
   bool Check(const boost::filesystem::path& widget_path);
   void fillManifest(const ManifestData* data, manifest_x* manifest);
+
+  SCOPE_LOG_TAG(Parse)
 };
 
 }  // namespace parse
index 5ce2c31..af5bb26 100644 (file)
@@ -8,15 +8,11 @@
 #include <boost/filesystem.hpp>
 #include <cassert>
 #include <cstring>
-#include <iostream>
 #include <cstdio>
 #include <string>
 
 #include "common/utils.h"
 
-#define DBG(msg) std::cout << "[Symoblic Link] " << msg << std::endl;
-#define ERR(msg) std::cout << "[ERROR: Symoblic Link] " << msg << std::endl;
-
 namespace wgt {
 namespace symbolic_link {
 
@@ -28,8 +24,8 @@ common_installer::Step::Status StepSymbolicLink::process() {
   uiapplication_x* ui = context_->manifest_data()->uiapplication;
   serviceapplication_x* svc = context_->manifest_data()->serviceapplication;
   if ((!ui) && (!svc)) {
-    ERR("There is neither UI applications nor"
-        << "Services applications described!\n");
+     LOG(ERROR) << "There is neither UI applications nor"
+        << "Services applications described!";
     return Step::Status::ERROR;
   }
   // add ui-application element per ui application
@@ -43,8 +39,8 @@ common_installer::Step::Status StepSymbolicLink::process() {
 
     fs::create_symlink(fs::path(WRT_LAUNCHER), exec_path, error);
     if (error) {
-      ERR("Failed to set symbolic link "
-        << boost::system::system_error(error).what());
+      LOG(ERROR) << "Failed to set symbolic link "
+        << boost::system::system_error(error).what();
       return Step::Status::ERROR;
     }
   }
@@ -58,12 +54,12 @@ common_installer::Step::Status StepSymbolicLink::process() {
 
     fs::create_symlink(fs::path(WRT_LAUNCHER), exec_path, error);
     if (error) {
-      ERR("Failed to set symbolic link "
-        << boost::system::system_error(error).what());
+      LOG(ERROR) << "Failed to set symbolic link "
+        << boost::system::system_error(error).what();
       return Step::Status::ERROR;
     }
   }
-  DBG("Successfully parse tizen manifest xml");
+  LOG(DEBUG) << "Successfully parse tizen manifest xml";
 
   return Status::OK;
 }
index 207dce5..1ced2fb 100644 (file)
@@ -8,6 +8,7 @@
 #include "common/app_installer.h"
 #include "common/context_installer.h"
 #include "common/step/step.h"
+#include "utils/logging.h"
 
 namespace wgt {
 namespace symbolic_link {
@@ -19,6 +20,8 @@ class StepSymbolicLink : public common_installer::Step {
   Status process() override;
   Status clean() override;
   Status undo() override;
+
+  SCOPE_LOG_TAG(SymbolicLink)
 };
 
 }  // namespace symbolic_link
index 6df4592..2887cf4 100644 (file)
@@ -6,7 +6,6 @@
 #include "widget-manifest-parser/application_data.h"
 
 #include <cassert>
-#include <iostream>
 #include <regex>
 
 #include "utils/logging.h"
index c4ba2c2..b30c309 100644 (file)
@@ -5,8 +5,6 @@
 
 #include "widget-manifest-parser/manifest_handlers/permissions_handler.h"
 
-#include <iostream>
-
 #include "utils/logging.h"
 #include "utils/values.h"
 #include "widget-manifest-parser/application_manifest_constants.h"
index 85e6562..6e365c6 100644 (file)
@@ -10,6 +10,7 @@
 #include <regex>
 #include <utility>
 
+#include "utils/logging.h"
 #include "utils/values.h"
 #include "widget-manifest-parser/application_manifest_constants.h"
 
@@ -104,8 +105,8 @@ bool TizenApplicationHandler::Validate(
   if (app_info->id().find(app_info->package()) != 0) {
     *error = "The application element property id "
              "does not start with package.\n";
-    fprintf(stderr, "app_info->id() = %s\n", app_info->id().c_str());
-    fprintf(stderr, "app_info->package() = %s\n", app_info->package().c_str());
+    LOG(ERROR) << "app_info->id() = " << app_info->id();
+    LOG(ERROR) << "app_info->package() = " << app_info->package();
     return false;
   }
   if (app_info->required_version().empty()) {
index 63fda6e..d0f1535 100644 (file)
@@ -106,7 +106,6 @@ void WidgetInfo::SetName(const std::string& name) {
 }
 
 void WidgetInfo::SetShortName(const std::string& short_name) {
-  fprintf(stderr, "setting short name: %s\n", short_name.c_str());
   value_->SetString(kShortName, short_name);
 }