Add print in console option

testing
marcelb 1 year ago
parent 993869bbc3
commit 8ac79b5a5d
  1. 3
      .vscode/settings.json
  2. 5
      README.md
  3. 3
      lib/log.hpp
  4. 9
      src/log.cpp

@ -3,6 +3,7 @@
"iostream": "cpp", "iostream": "cpp",
"iosfwd": "cpp", "iosfwd": "cpp",
"fstream": "cpp", "fstream": "cpp",
"*.tcc": "cpp" "*.tcc": "cpp",
"ostream": "cpp"
} }
} }

@ -0,0 +1,5 @@
# A simple Logging library for C++
Logging errors to a file, daily file rotation, date and time stamps. Configurable record structure etc.

@ -14,12 +14,13 @@ class log {
public: public:
string dir; string dir;
bool isKeepOpen; bool isKeepOpen;
bool printInConsole;
ofstream logfile; ofstream logfile;
struct tm * moment; struct tm * moment;
uint day; uint day;
string path; string path;
log (string _dir, bool _isKeepOpen = true); log (string _dir, bool _isKeepOpen = true, bool _printInConsole = false);
bool isdir(); bool isdir();
bool open(); bool open();

@ -1,8 +1,9 @@
#include "../lib/log.hpp" #include "../lib/log.hpp"
log::log(string _dir, bool _isKeepOpen) { log::log(string _dir, bool _isKeepOpen, bool _printInConsole = false) {
dir = _dir; dir = _dir;
isKeepOpen = _isKeepOpen; isKeepOpen = _isKeepOpen;
printInConsole = _printInConsole;
if (!isdir()) { if (!isdir()) {
cout << "Eror log dir path invalid!" << endl; cout << "Eror log dir path invalid!" << endl;
@ -44,6 +45,10 @@ void log::setMoment() {
} }
void log::put(string logline) { void log::put(string logline) {
if (printInConsole) {
cout << logline << endl;
}
setMoment(); setMoment();
setPrefix(logline); setPrefix(logline);
@ -68,10 +73,8 @@ void log::put(string logline) {
} }
} }
cout << logline << endl;
logfile << logline << endl; logfile << logline << endl;
if (!isKeepOpen && logfile.is_open()) { if (!isKeepOpen && logfile.is_open()) {
loose(); loose();
} }

Loading…
Cancel
Save