Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
JSONMessage Class Referenceabstract

#include <ored/utilities/log.hpp>

+ Inheritance diagram for JSONMessage:
+ Collaboration diagram for JSONMessage:

Public Member Functions

virtual ~JSONMessage ()
 
virtual std::string msg () const =0
 return a std::string for the log file More...
 
void log () const
 generate Boost log record to pass to corresponding sinks More...
 
const std::string json () const
 create JSON-like output from the data More...
 
void set (const std::string &key, const boost::any &value)
 

Protected Member Functions

virtual void emitLog () const =0
 generate Boost log record - this method is called by log() More...
 

Static Protected Member Functions

static std::string jsonify (const boost::any &)
 

Protected Attributes

std::map< std::string, boost::any > data_
 

Detailed Description

Definition at line 635 of file log.hpp.

Constructor & Destructor Documentation

◆ ~JSONMessage()

virtual ~JSONMessage ( )
virtual

Definition at line 637 of file log.hpp.

637{}

Member Function Documentation

◆ msg()

virtual std::string msg ( ) const
pure virtual

return a std::string for the log file

Implemented in StructuredMessage, EventMessage, and ProgressMessage.

+ Here is the caller graph for this function:

◆ log()

void log ( ) const

generate Boost log record to pass to corresponding sinks

Definition at line 491 of file log.cpp.

491 {
492 if (!ore::data::Log::instance().checkExcludeFilters(msg()))
493 emitLog();
494}
virtual std::string msg() const =0
return a std::string for the log file
virtual void emitLog() const =0
generate Boost log record - this method is called by log()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ json()

const std::string json ( ) const

create JSON-like output from the data

Definition at line 643 of file log.hpp.

643{ return jsonify(data_); }
static std::string jsonify(const boost::any &)
Definition: log.cpp:496
std::map< std::string, boost::any > data_
Definition: log.hpp:651
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set()

void set ( const std::string &  key,
const boost::any &  value 
)

Definition at line 644 of file log.hpp.

644{ data_[key] = value; }
SafeStack< ValueType > value

◆ emitLog()

virtual void emitLog ( ) const
protectedpure virtual

generate Boost log record - this method is called by log()

Implemented in StructuredMessage, EventMessage, and ProgressMessage.

+ Here is the caller graph for this function:

◆ jsonify()

string jsonify ( const boost::any &  obj)
staticprotected

Definition at line 496 of file log.cpp.

496 {
497 if (obj.type() == typeid(map<string, boost::any>)) {
498 string jsonStr = "{ ";
499 Size i = 0;
500 for (const auto& kv : boost::any_cast<map<string, boost::any>>(obj)) {
501 if (i > 0)
502 jsonStr += ", ";
503 jsonStr += '\"' + kv.first + "\": " + jsonify(kv.second);
504 i++;
505 }
506 jsonStr += " }";
507 return jsonStr;
508 } else if (obj.type() == typeid(vector<boost::any>)) {
509 string arrayStr = "[ ";
510 Size i = 0;
511 for (const auto& v : boost::any_cast<vector<boost::any>>(obj)) {
512 if (i > 0)
513 arrayStr += ", ";
514 arrayStr += jsonify(v);
515 i++;
516 }
517 arrayStr += " ]";
518 return arrayStr;
519 } else if (obj.type() == typeid(string)) {
520 string str = boost::any_cast<string>(obj);
521 boost::replace_all(str, "\\", "\\\\"); // do this before the below otherwise we get \\"
522 boost::replace_all(str, "\"", "\\\"");
523 boost::replace_all(str, "\r", "\\r");
524 boost::replace_all(str, "\n", "\\n");
525 return '\"' + str + '\"';
526 } else if (obj.type() == typeid(StructuredMessage::Category)) {
527 return to_string(boost::any_cast<StructuredMessage::Category>(obj));
528 } else if (obj.type() == typeid(StructuredMessage::Group)) {
529 return to_string(boost::any_cast<StructuredMessage::Group>(obj));
530 } else if (obj.type() == typeid(int)) {
531 return to_string(boost::any_cast<int>(obj));
532 } else if (obj.type() == typeid(bool)) {
533 return to_string(boost::any_cast<bool>(obj));
534 } else if (obj.type() == typeid(QuantLib::Size)) {
535 return to_string(boost::any_cast<QuantLib::Size>(obj));
536 } else if (obj.type() == typeid(QuantLib::Real)) {
537 return to_string(boost::any_cast<QuantLib::Real>(obj));
538 } else if (obj.type() == typeid(unsigned int)) {
539 return to_string(boost::any_cast<unsigned int>(obj));
540 } else if (obj.type() == typeid(unsigned short)) {
541 return to_string(boost::any_cast<unsigned short>(obj));
542 } else if (obj.type() == typeid(float)) {
543 return to_string(boost::any_cast<float>(obj));
544 } else {
545 try {
546 // It is possible that this line is the one causing the unknown value error.
547 StructuredLoggingErrorMessage("JSON Message Logging", "JSONMessage::jsonify() : Unrecognised value type")
548 .log();
549 } catch (...) {
550 }
551 return string();
552 }
553}
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
MarketObject obj
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ data_

std::map<std::string, boost::any> data_
protected

Definition at line 651 of file log.hpp.