Peano
Loading...
Searching...
No Matches
TP_Logging.h
Go to the documentation of this file.
1#pragma once
2
3// Output and error reporting beyond Cactus:
4// A standalone approach for TwoPunctures.
5// SvenK, 2017-04-10
6
7#include <cstdarg>
8#include <string>
9#include <iostream>
10
11namespace TP {
12
20struct logger {
21 virtual void log(const std::string& msg) = 0;
22 virtual void error(const std::string& msg) = 0;
23 virtual void info(const std::string& msg) = 0;
24 virtual void warn(const std::string& msg) = 0;
25};
26
31struct std_cerr_logger : public logger {
32 void print(const std::string& msg) { std::cerr << "TP: " << msg << "\n"; }
33
34 void log(const std::string& msg) override { print(msg); }
35 void error(const std::string& msg) override { print(msg); }
36 void info(const std::string& msg) override { print(msg); }
37 void warn(const std::string& msg) override { print(msg); }
38};
39
45 // the TwoPunctures library can use this anywhere
46 void TP_LOG(const char *fmt, ...);
47 void TP_ERROR(const char *fmt, ...);
48 void TP_INFO(const char *fmt, ...);
49 void TP_WARN(const char *fmt, ...);
50
51 logger* log; // Users can set this to anything
52
56}; // struct
57
65class error: public std::exception
66{
67 const char* msg;
68 public:
69 error(const char* msg_) : msg(msg_) {}
70 virtual const char* what() const throw()
71 {
72 return msg;
73 }
74 static void unless(bool c, const char* m)
75 {
76 if (!c) throw error(m);
77 }
78 static void incase(bool c, const char* m)
79 {
80 unless(!c,m);
81 }
82};
83
84} // ns
85
const char * msg
Definition TP_Logging.h:67
static void incase(bool c, const char *m)
Definition TP_Logging.h:78
static void unless(bool c, const char *m)
Definition TP_Logging.h:74
error(const char *msg_)
Definition TP_Logging.h:69
virtual const char * what() const
Definition TP_Logging.h:70
This file contains aliases for making access to the long state vector Q as used eg.
void TP_INFO(const char *fmt,...)
void TP_ERROR(const char *fmt,...)
void TP_LOG(const char *fmt,...)
void TP_WARN(const char *fmt,...)
By inheriting this class, you can do something with output if you need.
Definition TP_Logging.h:20
virtual void warn(const std::string &msg)=0
virtual void log(const std::string &msg)=0
virtual void info(const std::string &msg)=0
virtual void error(const std::string &msg)=0
Default stdout logger, using iostream.
Definition TP_Logging.h:31
void info(const std::string &msg) override
Definition TP_Logging.h:36
void error(const std::string &msg) override
Definition TP_Logging.h:35
void print(const std::string &msg)
Definition TP_Logging.h:32
void warn(const std::string &msg) override
Definition TP_Logging.h:37
void log(const std::string &msg) override
Definition TP_Logging.h:34