print errno

This commit is contained in:
mrbesen 2023-11-19 17:26:04 +01:00
parent 6ba52c9f45
commit c5274a56b8
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 13 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include <array>
#include <chrono> // date/time
#include <cstring>
#include <fstream> // ofstream (logging to file)
#include <iostream> // std::ostream, std::cout, std::cin
#include <memory> // std::unique_ptr
@ -284,6 +285,12 @@ void setColoredOutput(bool enabled) {
dynamic_cast<ConsoleOutput&>(*outputs.at(0)).setColoredOutput(enabled); // has to exist
}
const PrintErrno err;
std::ostream& operator<<(std::ostream& str, const PrintErrno&) {
return str << strerror(errno) << " (" << errno << ')';
}
std::ostream& operator<<(std::ostream& str, const FileSize& fs) {
static const char PREFIX[] {' ', 'K', 'M', 'G', 'T', 'P', 'E'};
static const uint_fast8_t PREFIXCOUNT = 7;

6
Log.h
View File

@ -127,6 +127,12 @@ private:
friend std::ostream& operator<<(std::ostream& str, const FileSize& fs);
};
struct PrintErrno {};
extern const PrintErrno err;
std::ostream& operator<<(std::ostream& str, const PrintErrno&);
std::ostream& operator<<(std::ostream& str, const FileSize& fs);
// copy Level values in Log namespace