mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
Add time stamp to logging
This commit is contained in:
@@ -32,9 +32,18 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <ctime>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
namespace {
|
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 <typename T>
|
template <typename T>
|
||||||
struct severity_strings {
|
struct severity_strings {
|
||||||
static const std::array<std::basic_string<T>, 4> value;
|
static const std::array<std::basic_string<T>, 4> value;
|
||||||
@@ -49,6 +58,7 @@ namespace {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void plain_text_message(T& os, const boost::optional<IfcUtil::IfcBaseClass*>& current_product, Logger::Severity type, const std::string& message, const IfcUtil::IfcBaseInterface* instance) {
|
void plain_text_message(T& os, const boost::optional<IfcUtil::IfcBaseClass*>& current_product, Logger::Severity type, const std::string& message, const IfcUtil::IfcBaseInterface* instance) {
|
||||||
os << "[" << severity_strings<typename T::char_type>::value[type] << "] ";
|
os << "[" << severity_strings<typename T::char_type>::value[type] << "] ";
|
||||||
|
os << "[" << get_time().c_str() << "] ";
|
||||||
if (current_product) {
|
if (current_product) {
|
||||||
std::string global_id = *((IfcUtil::IfcBaseEntity*)*current_product)->get("GlobalId");
|
std::string global_id = *((IfcUtil::IfcBaseEntity*)*current_product)->get("GlobalId");
|
||||||
os << "{" << global_id.c_str() << "} ";
|
os << "{" << global_id.c_str() << "} ";
|
||||||
@@ -75,6 +85,7 @@ namespace {
|
|||||||
boost::property_tree::basic_ptree<std::basic_string<typename T::char_type>, std::basic_string<typename T::char_type> > pt;
|
boost::property_tree::basic_ptree<std::basic_string<typename T::char_type>, std::basic_string<typename T::char_type> > pt;
|
||||||
|
|
||||||
// @todo this is crazy
|
// @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 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 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 };
|
static const typename T::char_type message_string[] = { 'm', 'e', 's', 's', 'a', 'g', 'e', 0 };
|
||||||
@@ -88,6 +99,9 @@ namespace {
|
|||||||
if (instance) {
|
if (instance) {
|
||||||
pt.put(instance_string, string_as<typename T::char_type>(instance->data().toString()));
|
pt.put(instance_string, string_as<typename T::char_type>(instance->data().toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pt.put(time_string, string_as<typename T::char_type>(get_time()));
|
||||||
|
|
||||||
boost::property_tree::write_json(os, pt, false);
|
boost::property_tree::write_json(os, pt, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user