From 99cd952c9811c749ca11cbeacd0d60aef425c756 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Mon, 13 Sep 2021 14:52:23 +0200 Subject: [PATCH] Add time stamp to logging --- src/ifcparse/IfcLogger.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ifcparse/IfcLogger.cpp b/src/ifcparse/IfcLogger.cpp index 053167c917..02439452f2 100644 --- a/src/ifcparse/IfcLogger.cpp +++ b/src/ifcparse/IfcLogger.cpp @@ -32,8 +32,17 @@ #include #include #include +#include +#include namespace { + + std::string get_time() { + std::ostringstream oss; + time_t now = time(nullptr); + oss << std::put_time(localtime(&now), "%F %T"); + return oss.str(); + } template struct severity_strings { @@ -49,6 +58,7 @@ namespace { template void plain_text_message(T& os, const boost::optional& current_product, Logger::Severity type, const std::string& message, const IfcUtil::IfcBaseInterface* instance) { os << "[" << severity_strings::value[type] << "] "; + os << "[" << get_time().c_str() << "] "; if (current_product) { std::string global_id = *((IfcUtil::IfcBaseEntity*)*current_product)->get("GlobalId"); os << "{" << global_id.c_str() << "} "; @@ -75,6 +85,7 @@ namespace { boost::property_tree::basic_ptree, std::basic_string > pt; // @todo this is crazy + static const typename T::char_type time_string[] = { 't', 'i', 'm', 'e', 0 }; static const typename T::char_type level_string[] = { 'l', 'e', 'v', 'e', 'l', 0 }; static const typename T::char_type product_string[] = { 'p', 'r', 'o', 'd', 'u', 'c', 't', 0 }; static const typename T::char_type message_string[] = { 'm', 'e', 's', 's', 'a', 'g', 'e', 0 }; @@ -88,6 +99,9 @@ namespace { if (instance) { pt.put(instance_string, string_as(instance->data().toString())); } + + pt.put(time_string, string_as(get_time())); + boost::property_tree::write_json(os, pt, false); } }