Edit namespaces

namespace2
marcelb 8 months ago
parent db7f8ebd92
commit b06129f345
  1. 2
      lib/log.hpp
  2. 24
      src/log.cpp
  3. 2
      test/test.cpp
  4. BIN
      test/test.o

@ -14,6 +14,7 @@
typedef unsigned int uint; typedef unsigned int uint;
#endif #endif
namespace marcelb { namespace marcelb {
namespace logging {
using namespace std; using namespace std;
@ -81,6 +82,7 @@ class log {
~log(); ~log();
}; };
}
} }
#endif #endif

@ -1,6 +1,9 @@
#include "../lib/log.hpp" #include "../lib/log.hpp"
marcelb::log::log(string _dir, bool _isKeepOpen, bool _printInConsole) { namespace marcelb {
namespace logging {
log::log(string _dir, bool _isKeepOpen, bool _printInConsole) {
dir = _dir; dir = _dir;
isKeepOpen = _isKeepOpen; isKeepOpen = _isKeepOpen;
printInConsole = _printInConsole; printInConsole = _printInConsole;
@ -21,28 +24,28 @@ marcelb::log::log(string _dir, bool _isKeepOpen, bool _printInConsole) {
} }
bool marcelb::log::isdir() { bool log::isdir() {
struct stat sb; struct stat sb;
return stat(dir.c_str(), &sb) == 0; return stat(dir.c_str(), &sb) == 0;
} }
bool marcelb::log::open() { bool log::open() {
logfile = ofstream (path, ios_base::app); logfile = ofstream (path, ios_base::app);
return logfile.is_open(); return logfile.is_open();
} }
void marcelb::log::loose() { void log::loose() {
logfile.close(); logfile.close();
} }
void marcelb::log::setMoment() { void log::setMoment() {
time_t rawtime; time_t rawtime;
time (&rawtime); time (&rawtime);
moment = localtime (&rawtime); moment = localtime (&rawtime);
} }
void marcelb::log::put(string logline) { void log::put(string logline) {
io.lock(); io.lock();
if (printInConsole) { if (printInConsole) {
cout << logline << endl; cout << logline << endl;
@ -79,7 +82,7 @@ void marcelb::log::put(string logline) {
} }
void marcelb::log::setPath() { void log::setPath() {
if (dir[dir.length()-1] != '/') { if (dir[dir.length()-1] != '/') {
dir.push_back('/'); dir.push_back('/');
} }
@ -90,7 +93,7 @@ void marcelb::log::setPath() {
path = dir + to_string(moment->tm_year+1900) + '-' + mon.str() + '-' + _day.str() + ".log"; path = dir + to_string(moment->tm_year+1900) + '-' + mon.str() + '-' + _day.str() + ".log";
} }
void marcelb::log::setPrefix(string &logline) { void log::setPrefix(string &logline) {
stringstream hour, min, sec; stringstream hour, min, sec;
hour << setw(2) << setfill('0') << moment->tm_hour; hour << setw(2) << setfill('0') << moment->tm_hour;
min << setw(2) << setfill('0') << moment->tm_min; min << setw(2) << setfill('0') << moment->tm_min;
@ -100,7 +103,10 @@ void marcelb::log::setPrefix(string &logline) {
logline = _logline; logline = _logline;
} }
marcelb::log::~log() { log::~log() {
loose(); loose();
} }
}
}

@ -3,7 +3,7 @@
#include "../lib/log.hpp" #include "../lib/log.hpp"
using namespace std; using namespace std;
using namespace marcelb; using namespace marcelb::logging;
log mylog("../example", false); log mylog("../example", false);

Binary file not shown.
Loading…
Cancel
Save