87 lines
1.8 KiB
C++
87 lines
1.8 KiB
C++
#ifndef OUTPUT_HPP
|
|
#define OUTPUT_HPP
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <ostream>
|
|
|
|
namespace dropshell {
|
|
|
|
/*
|
|
|
|
output.hpp and output.cpp - simple output helpers.
|
|
|
|
Defines ostreams:
|
|
|
|
debug, info, warning, error.
|
|
|
|
These ostreams can be used with C++23 print and println, e.g.
|
|
std::println(debug, "funny variable: {}={}","my_var",my_var);
|
|
|
|
Also defines a few helper functions:
|
|
|
|
PrintDebug(const std::string& msg); // equivalent to std::println(debug, msg);
|
|
PrintInfo(const std::string& msg); // equivalent to std::println(info, msg);
|
|
PrintWarning(const std::string& msg); // equivalent to std::println(warning, msg);
|
|
PrintError(const std::string& msg); // equivalent to std::println(error, msg);
|
|
|
|
Output for these streams for each line is formatted as:
|
|
[DBG] <message>
|
|
[INF] <message>
|
|
[WRN] <message>
|
|
[ERR] <message>
|
|
|
|
The output is coloured, and the tag is printed in grey.
|
|
|
|
In addition, when not using any of the above, helper routines for coloring the output of cout and cerr are provided.
|
|
|
|
SetColour(std::ostream& os, sColour colour);
|
|
|
|
Where sColour is an enum:
|
|
enum class sColour {
|
|
RESET,
|
|
DEBUG,
|
|
INFO,
|
|
WARNING,
|
|
ERROR
|
|
};
|
|
|
|
|
|
*/
|
|
|
|
// Output streams for different log levels
|
|
extern std::ostream& debug;
|
|
extern std::ostream& info;
|
|
extern std::ostream& warning;
|
|
extern std::ostream& error;
|
|
|
|
extern std::ostream& rawout;
|
|
extern std::ostream& rawerr;
|
|
|
|
// Enum for colours
|
|
enum class sColour {
|
|
RESET,
|
|
DEBUG,
|
|
INFO,
|
|
WARNING,
|
|
ERROR
|
|
};
|
|
std::ostream& colourstream(sColour colour);
|
|
|
|
// Set colour for a stream
|
|
void SetColour(sColour colour, std::ostream& os = std::cerr);
|
|
|
|
class SwitchColour
|
|
{
|
|
public:
|
|
SwitchColour(sColour colour, std::ostream& os = std::cerr);
|
|
~SwitchColour();
|
|
private:
|
|
std::ostream& os_;
|
|
sColour colour_;
|
|
};
|
|
|
|
} // namespace dropshell
|
|
|
|
#endif // OUTPUT_HPP
|