[cpp-sp] branch main updated: Add a File logger for aid in debugging.

Scott Cantor cantor.2 at osu.edu
Wed Jun 18 23:36:35 UTC 2025


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository cpp-sp.

View the commit online:
http://git.shibboleth.net/view/?p=cpp-sp.git;a=commit;h=a1b4d44400ea51f0a5cf7b01bf5c5d302cb67e5f

The following commit(s) were added to refs/heads/main by this push:
     new a1b4d444 Add a File logger for aid in debugging.
a1b4d444 is described below

commit a1b4d44400ea51f0a5cf7b01bf5c5d302cb67e5f
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Jun 18 19:36:27 2025 -0400

    Add a File logger for aid in debugging.
---
 Projects/vc22/shibsp.vcxproj                       |  1 +
 Projects/vc22/shibsp.vcxproj.filters               |  3 ++
 shibsp/Makefile.am                                 |  5 ++-
 shibsp/logging/LoggingService.h                    |  3 ++
 shibsp/logging/impl/AbstractLoggingService.cpp     |  2 +
 shibsp/logging/impl/ConsoleLoggingService.cpp      |  1 +
 ...leLoggingService.cpp => FileLoggingService.cpp} | 47 +++++++++++++++++-----
 7 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/Projects/vc22/shibsp.vcxproj b/Projects/vc22/shibsp.vcxproj
index 04ee38b3..ffeeb6c1 100644
--- a/Projects/vc22/shibsp.vcxproj
+++ b/Projects/vc22/shibsp.vcxproj
@@ -135,6 +135,7 @@
     <ClCompile Include="..\..\shibsp\logging\impl\AbstractLoggingService.cpp" />
     <ClCompile Include="..\..\shibsp\logging\impl\Category.cpp" />
     <ClCompile Include="..\..\shibsp\logging\impl\ConsoleLoggingService.cpp" />
+    <ClCompile Include="..\..\shibsp\logging\impl\FileLoggingService.cpp" />
     <ClCompile Include="..\..\shibsp\logging\impl\Priority.cpp" />
     <ClCompile Include="..\..\shibsp\logging\impl\StringUtil.cpp">
       <DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4996;%(DisableSpecificWarnings)</DisableSpecificWarnings>
diff --git a/Projects/vc22/shibsp.vcxproj.filters b/Projects/vc22/shibsp.vcxproj.filters
index cb83b5d9..22957202 100644
--- a/Projects/vc22/shibsp.vcxproj.filters
+++ b/Projects/vc22/shibsp.vcxproj.filters
@@ -290,6 +290,9 @@
     <ClCompile Include="..\..\shibsp\logging\impl\ConsoleLoggingService.cpp">
       <Filter>Source Files\Logging</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\shibsp\logging\impl\FileLoggingService.cpp">
+      <Filter>Source Files\Logging</Filter>
+    </ClCompile>
     <ClCompile Include="..\..\shibsp\logging\impl\Priority.cpp">
       <Filter>Source Files\Logging</Filter>
     </ClCompile>
diff --git a/shibsp/Makefile.am b/shibsp/Makefile.am
index 5608a9c4..2fcf4d6f 100644
--- a/shibsp/Makefile.am
+++ b/shibsp/Makefile.am
@@ -130,6 +130,7 @@ libshibsp_la_SOURCES = \
 	logging/impl/AbstractLoggingService.cpp \
 	logging/impl/Category.cpp \
 	logging/impl/ConsoleLoggingService.cpp \
+	logging/impl/FileLoggingService.cpp \
 	logging/impl/Priority.cpp \
 	logging/impl/StringUtil.cpp \
 	logging/impl/SyslogLoggingService.cpp \
@@ -188,7 +189,9 @@ EXTRA_DIST = \
 	config_pub_win32.h\
 	paths.h.in \
 	resource.h \
-	shibsp.rc
+	shibsp.rc \
+	logging/impl/WindowsLoggingService.cpp \
+	remoting/impl/WinHTTPRemotingService.cpp
 
 BUILT_SOURCES = paths.h
 
diff --git a/shibsp/logging/LoggingService.h b/shibsp/logging/LoggingService.h
index b03911e2..1722aaae 100644
--- a/shibsp/logging/LoggingService.h
+++ b/shibsp/logging/LoggingService.h
@@ -71,6 +71,9 @@ namespace shibsp {
     /** Logging to the console. */
     #define CONSOLE_LOGGING_SERVICE     "console"
 
+    /** Logging to a file. */
+    #define FILE_LOGGING_SERVICE     "file"
+
     /** Logging to the syslog API. */
     #define SYSLOG_LOGGING_SERVICE      "syslog"
 
diff --git a/shibsp/logging/impl/AbstractLoggingService.cpp b/shibsp/logging/impl/AbstractLoggingService.cpp
index bb44872a..945a3b81 100644
--- a/shibsp/logging/impl/AbstractLoggingService.cpp
+++ b/shibsp/logging/impl/AbstractLoggingService.cpp
@@ -40,6 +40,7 @@ namespace shibsp {
     };
 
     extern LoggingService* SHIBSP_DLLLOCAL ConsoleLoggingServiceFactory(ptree& pt, bool);
+    extern LoggingService* SHIBSP_DLLLOCAL FileLoggingServiceFactory(ptree& pt, bool);
 #ifdef WIN32
     extern LoggingService* SHIBSP_DLLLOCAL WindowsLoggingServiceFactory(ptree& pt, bool);
 #else
@@ -51,6 +52,7 @@ void SHIBSP_API shibsp::registerLoggingServices()
 {
     AgentConfig& conf=AgentConfig::getConfig();
     conf.LoggingServiceManager.registerFactory(CONSOLE_LOGGING_SERVICE, ConsoleLoggingServiceFactory);
+    conf.LoggingServiceManager.registerFactory(FILE_LOGGING_SERVICE, FileLoggingServiceFactory);
 #ifdef WIN32
     conf.LoggingServiceManager.registerFactory(WINDOWS_LOGGING_SERVICE, WindowsLoggingServiceFactory);
 #else
diff --git a/shibsp/logging/impl/ConsoleLoggingService.cpp b/shibsp/logging/impl/ConsoleLoggingService.cpp
index aa936300..923f2014 100644
--- a/shibsp/logging/impl/ConsoleLoggingService.cpp
+++ b/shibsp/logging/impl/ConsoleLoggingService.cpp
@@ -35,6 +35,7 @@ namespace shibsp {
     class ConsoleLoggingService : public virtual AbstractLoggingService {
     public:
         ConsoleLoggingService(const ptree& pt);
+        virtual ~ConsoleLoggingService() {}
 
         void outputMessage(const Category& category, Priority::Value prio, const string& message) {
             outputMessage(category, prio, message.c_str());
diff --git a/shibsp/logging/impl/ConsoleLoggingService.cpp b/shibsp/logging/impl/FileLoggingService.cpp
similarity index 50%
copy from shibsp/logging/impl/ConsoleLoggingService.cpp
copy to shibsp/logging/impl/FileLoggingService.cpp
index aa936300..e8060cf8 100644
--- a/shibsp/logging/impl/ConsoleLoggingService.cpp
+++ b/shibsp/logging/impl/FileLoggingService.cpp
@@ -13,17 +13,21 @@
  */
 
 /**
- * logging/impl/ConsoleLoggingService.cpp
+ * logging/impl/FileLoggingService.cpp
  *
  * Logging service implementation using the console.
  */
 
 #include "internal.h"
+#include "exceptions.h"
+#include "AgentConfig.h"
 #include "logging/impl/AbstractLoggingService.h"
 #include "util/Date.h"
+#include "util/PathResolver.h"
 
 #include <chrono>
-#include <iostream>
+#include <fstream>
+#include <sstream>
 #include <boost/property_tree/ptree.hpp>
 
 using namespace shibsp;
@@ -32,36 +36,57 @@ using namespace std;
 
 namespace shibsp {
 
-    class ConsoleLoggingService : public virtual AbstractLoggingService {
+    class FileLoggingService : public virtual AbstractLoggingService {
     public:
-        ConsoleLoggingService(const ptree& pt);
+        FileLoggingService(const ptree& pt);
+        virtual ~FileLoggingService();
 
         void outputMessage(const Category& category, Priority::Value prio, const string& message) {
             outputMessage(category, prio, message.c_str());
         }
         void outputMessage(const Category& category, Priority::Value prio, const char* message);
 
+    private:
+        ofstream m_out;
     };
 
-    LoggingService* SHIBSP_DLLLOCAL ConsoleLoggingServiceFactory(ptree& pt, bool) {
-        return new ConsoleLoggingService(pt);
+    LoggingService* SHIBSP_DLLLOCAL FileLoggingServiceFactory(ptree& pt, bool) {
+        return new FileLoggingService(pt);
     }
 
 }
 
-ConsoleLoggingService::ConsoleLoggingService(const ptree& pt) : AbstractLoggingService(pt)
+FileLoggingService::FileLoggingService(const ptree& pt) : AbstractLoggingService(pt)
 {
-    // No dedicated settings at the moment, might be worth supporting some kind of
-    // message formatting.
+    static const char PATH_PROP_PATH[] = "logging.path";
+
+    string path = pt.get(PATH_PROP_PATH, "");
+    if (path.empty()) {
+        throw ConfigurationException(string("No ") + PATH_PROP_PATH + " in [logging] section of configuration.");
+    }
+    AgentConfig::getConfig().getPathResolver().resolve(path, PathResolver::SHIBSP_LOG_FILE);
+
+    m_out.open(path, ios_base::out | ios_base::app);
+    if (!m_out) {
+        throw ConfigurationException(string("Unable to open log file (") + path + ") for writing.");
+    }
+}
+
+FileLoggingService::~FileLoggingService()
+{
+    m_out.close();
 }
 
-void ConsoleLoggingService::outputMessage(const Category& category, Priority::Value prio, const char* message)
+void FileLoggingService::outputMessage(const Category& category, Priority::Value prio, const char* message)
 {
     auto now = chrono::system_clock::now();
 
-    cout << date::format("%FT%TZ", date::floor<chrono::milliseconds>(now)) << " - "
+    stringstream sink;
+    sink << date::format("%FT%TZ", date::floor<chrono::milliseconds>(now)) << " - "
         << Priority::getPriorityName(prio)
         << " [" << category.getName() << "] - "
         << message
         << endl;
+    
+    m_out << sink.str();
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list