changeset 1485:27661b33f624

Creation of Logging.h
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Aug 2015 09:35:09 +0200
parents b64f48e19ab9
children f967bdf8534e
files CMakeLists.txt Core/Logging.cpp Core/Logging.h OrthancServer/OrthancInitialization.cpp OrthancServer/main.cpp UnitTestsSources/UnitTestsMain.cpp
diffstat 6 files changed, 143 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Sun Aug 02 15:57:45 2015 +0200
+++ b/CMakeLists.txt	Tue Aug 04 09:35:09 2015 +0200
@@ -106,6 +106,7 @@
   Core/HttpServer/MongooseServer.cpp
   Core/HttpServer/HttpFileSender.cpp
   Core/HttpServer/FilesystemHttpSender.cpp
+  Core/Logging.cpp
   Core/RestApi/RestApiCall.cpp
   Core/RestApi/RestApiGetCall.cpp
   Core/RestApi/RestApiHierarchy.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Core/Logging.cpp	Tue Aug 04 09:35:09 2015 +0200
@@ -0,0 +1,74 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "PrecompiledHeaders.h"
+#include "Logging.h"
+
+
+namespace Orthanc
+{  
+  namespace Logging
+  {
+    void Initialize()
+    {
+      // Initialize Google's logging library.
+      FLAGS_logtostderr = true;
+      FLAGS_minloglevel = 1;   // Do not print LOG(INFO) by default
+      FLAGS_v = 0;             // Do not print trace-level VLOG(1) by default
+
+      google::InitGoogleLogging("Orthanc");
+    }
+
+    void Finalize()
+    {
+      google::ShutdownGoogleLogging();
+    }
+
+    void EnableInfoLevel(bool enabled)
+    {
+      FLAGS_minloglevel = (enabled ? 0 : 1);
+    }
+
+    void EnableTraceLevel(bool enabled)
+    {
+      if (enabled)
+      {
+        FLAGS_minloglevel = 0;
+        FLAGS_v = 1;
+      }
+      else
+      {
+        FLAGS_v = 0;
+      }
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Core/Logging.h	Tue Aug 04 09:35:09 2015 +0200
@@ -0,0 +1,49 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include <glog/logging.h>
+
+namespace Orthanc
+{
+  namespace Logging
+  {
+    void Initialize();
+
+    void Finalize();
+
+    void EnableInfoLevel(bool enabled);
+
+    void EnableTraceLevel(bool enabled);
+  }
+}
--- a/OrthancServer/OrthancInitialization.cpp	Sun Aug 02 15:57:45 2015 +0200
+++ b/OrthancServer/OrthancInitialization.cpp	Tue Aug 04 09:35:09 2015 +0200
@@ -34,19 +34,19 @@
 #include "OrthancInitialization.h"
 
 #include "../Core/HttpClient.h"
+#include "../Core/Logging.h"
 #include "../Core/OrthancException.h"
 #include "../Core/Toolbox.h"
+#include "../Core/FileStorage/FilesystemStorage.h"
+
 #include "DicomProtocol/DicomServer.h"
 #include "ServerEnumerations.h"
+#include "DatabaseWrapper.h"
 
 #include <boost/lexical_cast.hpp>
 #include <boost/filesystem.hpp>
 #include <curl/curl.h>
 #include <boost/thread.hpp>
-#include <glog/logging.h>
-
-#include "DatabaseWrapper.h"
-#include "../Core/FileStorage/FilesystemStorage.h"
 
 
 #if ORTHANC_JPEG_ENABLED == 1
--- a/OrthancServer/main.cpp	Sun Aug 02 15:57:45 2015 +0200
+++ b/OrthancServer/main.cpp	Tue Aug 04 09:35:09 2015 +0200
@@ -37,6 +37,7 @@
 #include <glog/logging.h>
 #include <boost/algorithm/string/predicate.hpp>
 
+#include "../Core/Logging.h"
 #include "../Core/Uuid.h"
 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h"
 #include "../Core/HttpServer/FilesystemHttpHandler.h"
@@ -624,10 +625,7 @@
 
 int main(int argc, char* argv[]) 
 {
-  // Initialize Google's logging library.
-  FLAGS_logtostderr = true;
-  FLAGS_minloglevel = 1;
-  FLAGS_v = 0;
+  Logging::Initialize();
 
   for (int i = 1; i < argc; i++)
   {
@@ -645,13 +643,12 @@
 
     if (std::string(argv[i]) == "--verbose")
     {
-      FLAGS_minloglevel = 0;
+      Logging::EnableInfoLevel(true);
     }
 
     if (std::string(argv[i]) == "--trace")
     {
-      FLAGS_minloglevel = 0;
-      FLAGS_v = 1;
+      Logging::EnableTraceLevel(true);
     }
 
     if (boost::starts_with(argv[i], "--logdir="))
@@ -678,8 +675,6 @@
     }
   }
 
-  google::InitGoogleLogging("Orthanc");
-
   const char* configurationFile = NULL;
   for (int i = 1; i < argc; i++)
   {
@@ -736,5 +731,7 @@
 
   LOG(WARNING) << "Orthanc has stopped";
 
+  Logging::Finalize();
+
   return status;
 }
--- a/UnitTestsSources/UnitTestsMain.cpp	Sun Aug 02 15:57:45 2015 +0200
+++ b/UnitTestsSources/UnitTestsMain.cpp	Tue Aug 04 09:35:09 2015 +0200
@@ -40,6 +40,7 @@
 #include "../Core/Compression/ZlibCompressor.h"
 #include "../Core/DicomFormat/DicomTag.h"
 #include "../Core/HttpServer/HttpToolbox.h"
+#include "../Core/Logging.h"
 #include "../Core/OrthancException.h"
 #include "../Core/Toolbox.h"
 #include "../Core/Uuid.h"
@@ -488,8 +489,6 @@
 }
 
 
-#include <glog/logging.h>
-
 TEST(Logger, Basic)
 {
   LOG(INFO) << "I say hello";
@@ -821,22 +820,17 @@
 
 int main(int argc, char **argv)
 {
-  // Initialize Google's logging library.
-  FLAGS_logtostderr = true;
-  FLAGS_minloglevel = 0;
-
-  // Go to trace-level verbosity
-  //FLAGS_v = 1;
+  Logging::Initialize();
+  Logging::EnableInfoLevel(true);
+  Toolbox::DetectEndianness();
+  Toolbox::MakeDirectory("UnitTestsResults");
+  OrthancInitialize();
 
-  Toolbox::DetectEndianness();
-
-  google::InitGoogleLogging("Orthanc");
-
-  Toolbox::MakeDirectory("UnitTestsResults");
-
-  OrthancInitialize();
   ::testing::InitGoogleTest(&argc, argv);
   int result = RUN_ALL_TESTS();
+
   OrthancFinalize();
+  Logging::Finalize();
+
   return result;
 }