OMSimulatorLib The OMSimulator project is a FMI-based co-simulation environment.

Loading...
Searching...
No Matches
Logging.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36#pragma once
37
38#include "OMSimulator/Types.h"
39
40#include <string>
41
42 namespace oms
43{
44 namespace Log
45 {
46 // The functions in the Internal namespace are not meant to be used directly.
47 // They are intended to be used by the macros defined below.
48 namespace Internal
49 {
50 void Info(const std::string &msg);
51 oms_status_enu_t Warning(const std::string &msg);
52 oms_status_enu_t Error(const std::string &msg, const std::string &function);
53
54 bool DebugEnabled();
55 bool TraceEnabled();
56
57 void Debug(const std::string &msg);
58 void Trace(const std::string &function, const std::string &file, const long line);
59 }
60
61 void ProgressBar(double start, double stop, double value);
62 void TerminateBar();
63
64 void SetCallback(void (*cb)(oms_message_type_enu_t type, const char *message));
65 oms_status_enu_t SetLogFile(const std::string &filename);
66
67 oms_status_enu_t SetLoggingLevel(int logLevel);
68 const int GetLoggingLevel();
69
70 void SetMaxLogFileSize(const unsigned long size);
71 }
72}
73
74#define logInfo(msg) oms::Log::Internal::Info(msg)
75#define logWarning(msg) oms::Log::Internal::Warning(msg)
76#define logError(msg) oms::Log::Internal::Error(msg, __func__)
77
78#if !defined(NDEBUG)
79 #define logDebugEnabled() oms::Log::Internal::DebugEnabled()
80 #define logTraceEnabled() oms::Log::Internal::TraceEnabled()
81
82 #define logDebug(msg) oms::Log::Internal::Debug(msg)
83 #define logTrace() oms::Log::Internal::Trace(__func__, __FILE__, __LINE__)
84#else
85 #define logDebugEnabled() (false)
86 #define logTraceEnabled() (false)
87
88 #define logDebug(msg) ((void)0)
89 #define logTrace() ((void)0)
90#endif
91
92// common error messages
93#define logError_AlreadyInScope(cref) logError("\"" + std::string(cref) + "\" already exists in the scope")
94#define logError_BusAndConnectorNotSameModel(bus, connector) logError("Bus \"" + std::string(bus) + "\" and connector \"" + std::string(connector) + "\" do not belong to same model")
95#define logError_BusAndConnectorNotSameSystem(bus, connector) logError("Bus \"" + std::string(bus) + "\" and connector \"" + std::string(connector) + "\" do not belong to same system")
96#define logError_BusNotInComponent(cref, component) logError("Bus connector \"" + std::string(cref) + "\" not found in component \"" + std::string(component->getFullCref()) + "\"")
97#define logError_BusNotInSystem(cref, system) logError("Bus connector \"" + std::string(cref) + "\" not found in system \"" + std::string(system->getFullCref()) + "\"")
98#define logError_ComponentNotInSystem(system, component) logError("System \"" + std::string(system->getFullCref()) + "\" does not contain component \"" + std::string(component) + "\"")
99#define logError_ConnectionExistsAlready(crefA, crefB, system) logError("Connection <\"" + std::string(crefA) + "\", \"" + std::string(crefB) + "\"> exists already in system \"" + std::string(system->getFullCref()) + "\"")
100#define logError_ConnectionNotInSystem(crefA, crefB, system) logError("Connection <\"" + std::string(crefA) + "\", \"" + std::string(crefB) + "\"> not found in system \"" + std::string(system->getFullCref()) + "\"")
101#define logError_ConnectorNotInComponent(cref, component) logError("Connector \"" + std::string(cref) + "\" not found in component \"" + std::string(component->getFullCref()) + "\"")
102#define logError_ConnectorNotInSystem(cref, system) logError("Connector \"" + std::string(cref) + "\" not found in system \"" + std::string(system->getFullCref()) + "\"")
103#define logError_FMUCall(call, fmu) logError(std::string(call) + " failed for FMU \"" + std::string(fmu->getFullCref()) + "\"")
104#define logError_Initialization(system) logError("Initialization of system \"" + std::string(system) + "\" failed")
105#define logError_InternalError logError("internal error")
106#define logError_InvalidIdent(cref) logError("\"" + std::string(cref) + "\" is not a valid ident")
107#define logError_InvalidIdent(cref) logError("\"" + std::string(cref) + "\" is not a valid ident")
108#define logError_ModelInWrongState(cref) logError("Model \"" + std::string(cref) + "\" is in wrong model state")
109#define logError_ModelNotInScope(cref) logError("Model \"" + std::string(cref) + "\" does not exist in the scope")
110#define logError_NotForScSystem logError("Not available for strongly coupled systems")
111#define logError_NotImplemented logError("Not implemented")
112#define logError_OnlyForModel logError("Only implemented for model identifiers")
113#define logError_OnlyForRealInputs(cref) logError("Signal \"" + std::string(cref) + "\" is not a real input signal")
114#define logError_OnlyForSystemWC logError("Only available for WC systems")
115#define logError_ResetFailed(system) logError("failed to reset system \"" + std::string(system) + "\" to instantiation mode")
116#define logError_SubSystemNotInSystem(system, subsystem) logError("System \"" + std::string(system) + "\" does not contain subsystem \"" + std::string(subsystem) + "\"")
117#define logError_SystemNotInModel(model, system) logError("Model \"" + std::string(model) + "\" does not contain system \"" + std::string(system) + "\"")
118#define logError_Termination(system) logError("Termination of system \"" + std::string(system) + "\" failed")
119#define logError_UnknownSignal(cref) logError("Unknown signal \"" + std::string(cref) + "\"")
120#define logError_WrongSchema(name) logError("Wrong xml schema detected. Unexpected tag \"" + name + "\"")
121#define logWarning_deprecated logWarning("Wrong/deprecated content detected but successfully loaded. Please re-export the SSP file to avoid this message.")
oms::Log::Internal::DebugEnabled
bool DebugEnabled()
Definition Logging.cpp:207
oms::Log::Internal::Info
void Info(const std::string &msg)
Definition Logging.cpp:164
oms::Log::Internal::Error
oms_status_enu_t Error(const std::string &msg, const std::string &function)
Definition Logging.cpp:191
oms::Log::Internal::Trace
void Trace(const std::string &function, const std::string &file, const long line)
Definition Logging.cpp:232
oms::Log::Internal::Debug
void Debug(const std::string &msg)
Definition Logging.cpp:212
oms::Log::Internal::TraceEnabled
bool TraceEnabled()
Definition Logging.cpp:227
oms::Log::Internal::Warning
oms_status_enu_t Warning(const std::string &msg)
Definition Logging.cpp:176
oms::Log::SetLoggingLevel
oms_status_enu_t SetLoggingLevel(int logLevel)
Definition Logging.cpp:287
oms::Log::ProgressBar
void ProgressBar(double start, double stop, double value)
Definition Logging.cpp:317
oms::Log::TerminateBar
void TerminateBar()
Definition Logging.cpp:345
oms::Log::SetCallback
void SetCallback(void(*cb)(oms_message_type_enu_t type, const char *message))
Definition Logging.cpp:312
oms::Log::SetLogFile
oms_status_enu_t SetLogFile(const std::string &filename)
Definition Logging.cpp:249
oms::Log::GetLoggingLevel
const int GetLoggingLevel()
Definition Logging.cpp:302
oms::Log::SetMaxLogFileSize
void SetMaxLogFileSize(const unsigned long size)
Definition Logging.cpp:307
oms
Definition AlgLoop.h:49