Add print in console option

testing
marcelb 2 years 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",
"iosfwd": "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:
string dir;
bool isKeepOpen;
bool printInConsole;
ofstream logfile;
struct tm * moment;
uint day;
string path;
log (string _dir, bool _isKeepOpen = true);
log (string _dir, bool _isKeepOpen = true, bool _printInConsole = false);
bool isdir();
bool open();

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

Loading…
Cancel
Save