26 #ifndef CASADI_LOGGER_HPP
27 #define CASADI_LOGGER_HPP
29 #include <casadi/core/casadi_export.h>
51 static void (*writeFun)(
const char* s, std::streamsize num,
bool error);
54 static void (*flush)(
bool error);
60 static void writeDefault(
const char* s, std::streamsize num,
bool error) {
62 std::cerr.write(s, num);
64 std::cout.write(s, num);
71 std::cerr << std::flush;
73 std::cout << std::flush;
78 static void writeIgnore(
const char* s, std::streamsize num,
bool error) {
82 template<
bool Err>
static void write(
const char* s, std::streamsize num) {
84 WriteFunThreadSafe(s, num, Err);
88 template<
bool Err>
static void writeCh(
char ch) {
93 template<
bool Err>
class Streambuf :
public std::streambuf {
98 if (ch != traits_type::eof()) {
99 writeCh<Err>(
static_cast<char>(ch));
103 std::streamsize
xsputn(
const char* s, std::streamsize num)
override {
108 FlushThreadSafe(Err);
114 template<
bool Err>
class Stream :
public std::ostream {
123 CASADI_EXPORT std::ostream&
uout();
126 CASADI_EXPORT std::ostream&
uerr();
131 CASADI_EXPORT
int casadi_printf(
const char *fmt, ...);
std::streamsize xsputn(const char *s, std::streamsize num) override
int_type overflow(int_type ch) override
Keeps track of logging output to screen and/or files.
static void write(const char *s, std::streamsize num)
Print output message.
static void writeCh(char ch)
Print log message, single character.
static void flushDefault(bool error)
By default, flush std::cout or std::cerr.
static void writeDefault(const char *s, std::streamsize num, bool error)
By default, print to std::cout or std::cerr.
static void WriteFunThreadSafe(const char *s, std::streamsize num, bool error)
static void writeIgnore(const char *s, std::streamsize num, bool error)
Ignore output.
static void FlushThreadSafe(bool error)
CASADI_EXPORT std::ostream & uout()
CASADI_EXPORT std::ostream & uerr()