IOSS 2.0
Loading...
Searching...
No Matches
Iocatalyst_CatalystLogging.h
Go to the documentation of this file.
1// Copyright(C) 1999-2021 National Technology & Engineering Solutions
2// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3// NTESS, the U.S. Government retains certain rights in this software.
4//
5// See packages/seacas/LICENSE for details
6
7#ifndef IOSS_IOVS_CATALYST_LOGGING_H
8#define IOSS_IOVS_CATALYST_LOGGING_H
9
10#include "iocatalyst_export.h"
11
12#include <Ioss_CodeTypes.h>
14#include <string>
15#include <vector>
16
17namespace Iocatalyst {
18
19 class IOCATALYST_EXPORT CatalystLogging
20 {
21 // Enables Catalyst log output from IOSS when Catalyst CGNS or
22 // Exodus IOSS databases are created. Rank 0 of the application
23 // writes an entry to a CSV (comma separted value) log file upon
24 // IOSS database creation. Log output is controlled through
25 // IOSS properties. IOSS properties that control logging must be
26 // prepened with the string "CATALYST_LOGGING_".
27 //
28 // There are three reserved IOSS property names for logging.
29 //
30 // "CATALYST_LOGGING_ENABLED" : enables Catalyst log output when passed
31 // an argument of "true or a non-zero integer". Default is "false".
32 //
33 // "CATALYST_LOGGING_FILE_NAME" : string specifying the log file output
34 // name. Default is "catalyst_log.csv".
35 //
36 // "CATALYST_LOGGING_OUTPUT_DIRECTORY_PATH" : string specifying an absolute
37 // or relative path to the log file. Default is current working directory, "".
38 //
39 // Real, Integer, and String IOSS properties prepended by the string
40 // "CATALYST_LOGGING_" are used to specify output for the log line in the CSV
41 // output log file. The logger will remove the prepended string and create
42 // a header line in the CSV file sorted by name.
43 //
44 // Example application code creating a Catalyst IOSS database with logging:
45 //
46 // Ioss::PropertyManager *p;
47 // p->add(Ioss::Property("CATALYST_LOGGING_ENABLED", true));
48 // p->add(Ioss::Property("CATALYST_LOGGING_FILE_NAME", "app_log.csv"));
49 // p->add(Ioss::Property("CATALYST_LOGGING_OUTPUT_DIRECTORY_PATH, "/etc/logs/"));
50 // p->add(Ioss::Property("CATALYST_LOGGING_NUM_RANKS", getNumRanks()));
51 // p->add(Ioss::Property("CATALYST_LOGGING_DATE", getDate()));
52 // p->add(Ioss::Property("CATALYST_LOGGING_USER", getUser()));
53 // p->add(Ioss::Property("CATALYST_LOGGING_APP_NAME", getAppName()));
54 //
55 // The IOSS properties contained in *p are passed to the IOSS
56 // Ioss::IOFactory::create(). A log entry will be appended to the log file
57 // at "/etc/logs/app_log_.csv" every time a Catalyst database is created by
58 // a running instance of the application. The CSV log file will have the following
59 // format, which can be easily read by Python.
60 //
61 // APP_NAME,DATE,NUM_RANKS,USER
62 // goo,November 10th,16,joe
63 // bar,December 12th,8,stan
64 //
65 // If an IOSS string property contains commas, these need to be quoted.
66 //
67 // p->add(Ioss::Property("CATALYST_LOGGING_ADDRESS", "\"123 main, PO 4, ND, 34422\""))
68 //
69 // Quotes inside strings must also be quoted.
70 //
71 // p->add(Ioss::Property("CATALYST_LOGGING_QUOTE", "I am \"\"Dave\"\""))
72
73 public:
75
76 bool isCatalystLoggingON() { return catalystLoggingEnabled; };
77 std::string getLogFileName() { return logFileName; };
78 static std::string getDefaultLogFileName() { return "catalyst_log.csv"; };
79 std::string getLogOutputDirectoryPath() { return logOutputDirectoryPath; };
80 std::string getDefaultLogOutputDirectoryPath() { return ""; };
81 void setProperties(const Ioss::PropertyManager *properties);
82 std::vector<std::string> getLogFileHeaders();
83 std::vector<std::string> writeToLogFile();
84 std::vector<std::vector<std::string>> readLogFile();
85 static std::vector<std::vector<std::string>> readLogFile(const std::string &logFilePath);
86 std::string getLogFilePath()
87 {
88 if (logOutputDirectoryPath.empty()) {
89 return getLogFileName();
90 }
91 else {
92 std::string opath = getLogOutputDirectoryPath();
93 if (opath.back() != '/') {
94 opath += '/';
95 }
96 return opath + getLogFileName();
97 }
98 };
99 static char getDelimeter() { return ','; };
100 bool isCatalystLoggingProp(std::string &propName) { return propName.rfind(logPrefix, 0) == 0; };
101 std::string getHeaderNameFromPropName(std::string &propName)
102 {
103 return propName.substr(logPrefix.length());
104 };
105 std::string getPropNameFromHeaderName(std::string &headerName)
106 {
107 return logPrefix + headerName;
108 };
109 bool isReservedPropName(std::string &propName)
110 {
111 return propName == enabledProp || propName == fileNameProp || propName == directoryPathProp;
112 };
113 bool isSupportedPropType(std::string &propName)
114 {
115 bool retVal = false;
116 if (properties && properties->exists(propName)) {
117 Ioss::Property::BasicType type = properties->get(propName).get_type();
118 retVal = (type == Ioss::Property::INTEGER || type == Ioss::Property::REAL ||
119 type == Ioss::Property::STRING);
120 }
121 return retVal;
122 };
123
124 private:
126 std::string logFileName;
129 std::string logPrefix = "CATALYST_LOGGING_";
130 std::string enabledProp = logPrefix + "ENABLED";
131 std::string fileNameProp = logPrefix + "FILE_NAME";
132 std::string directoryPathProp = logPrefix + "OUTPUT_DIRECTORY_PATH";
133 void initializeDefaults();
134 void writeVectorWithDelimeter(std::fstream &file, const std::vector<std::string> &string_vector,
135 char delimeter);
136 static std::vector<std::string> splitStringWithDelimeter(const std::string &input,
137 char delimeter);
138 bool isLogFileEmpty();
139 std::vector<std::string> getLogOutputFromProps(std::vector<std::string> &headers);
140 };
141
142} // namespace Iocatalyst
143
144#endif
Definition Iocatalyst_CatalystLogging.h:20
std::string getHeaderNameFromPropName(std::string &propName)
Definition Iocatalyst_CatalystLogging.h:101
const Ioss::PropertyManager * properties
Definition Iocatalyst_CatalystLogging.h:128
std::string getDefaultLogOutputDirectoryPath()
Definition Iocatalyst_CatalystLogging.h:80
bool isSupportedPropType(std::string &propName)
Definition Iocatalyst_CatalystLogging.h:113
std::string logFileName
Definition Iocatalyst_CatalystLogging.h:126
std::string getPropNameFromHeaderName(std::string &headerName)
Definition Iocatalyst_CatalystLogging.h:105
std::string getLogOutputDirectoryPath()
Definition Iocatalyst_CatalystLogging.h:79
bool isCatalystLoggingON()
Definition Iocatalyst_CatalystLogging.h:76
bool isCatalystLoggingProp(std::string &propName)
Definition Iocatalyst_CatalystLogging.h:100
std::string logOutputDirectoryPath
Definition Iocatalyst_CatalystLogging.h:127
bool isReservedPropName(std::string &propName)
Definition Iocatalyst_CatalystLogging.h:109
std::string getLogFileName()
Definition Iocatalyst_CatalystLogging.h:77
std::string getLogFilePath()
Definition Iocatalyst_CatalystLogging.h:86
static std::string getDefaultLogFileName()
Definition Iocatalyst_CatalystLogging.h:78
bool catalystLoggingEnabled
Definition Iocatalyst_CatalystLogging.h:125
static char getDelimeter()
Definition Iocatalyst_CatalystLogging.h:99
A collection of Ioss::Property objects.
Definition Ioss_PropertyManager.h:36
BasicType
Definition Ioss_Property.h:29
@ INTEGER
Definition Ioss_Property.h:29
@ REAL
Definition Ioss_Property.h:29
@ STRING
Definition Ioss_Property.h:29
A namespace for the Catalyst 2.0 database format.
Definition Iocatalyst_CatalystLogging.C:13