diff --git a/lib/log.hpp b/lib/log.hpp index 88b98b6..6f55987 100644 --- a/lib/log.hpp +++ b/lib/log.hpp @@ -14,6 +14,7 @@ typedef unsigned int uint; #endif namespace marcelb { +namespace logging { using namespace std; @@ -81,6 +82,7 @@ class log { ~log(); }; +} } #endif \ No newline at end of file diff --git a/src/log.cpp b/src/log.cpp index 624b4c1..7fba7b1 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -1,6 +1,9 @@ #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; isKeepOpen = _isKeepOpen; 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; return stat(dir.c_str(), &sb) == 0; } -bool marcelb::log::open() { +bool log::open() { logfile = ofstream (path, ios_base::app); return logfile.is_open(); } -void marcelb::log::loose() { +void log::loose() { logfile.close(); } -void marcelb::log::setMoment() { +void log::setMoment() { time_t rawtime; time (&rawtime); moment = localtime (&rawtime); } -void marcelb::log::put(string logline) { +void log::put(string logline) { io.lock(); if (printInConsole) { 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] != '/') { dir.push_back('/'); } @@ -90,7 +93,7 @@ void marcelb::log::setPath() { 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; hour << setw(2) << setfill('0') << moment->tm_hour; min << setw(2) << setfill('0') << moment->tm_min; @@ -100,7 +103,10 @@ void marcelb::log::setPrefix(string &logline) { logline = _logline; } -marcelb::log::~log() { +log::~log() { loose(); } + +} +} diff --git a/test/test.cpp b/test/test.cpp index f609f90..569f25b 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -3,7 +3,7 @@ #include "../lib/log.hpp" using namespace std; -using namespace marcelb; +using namespace marcelb::logging; log mylog("../example", false); diff --git a/test/test.o b/test/test.o index 5f88533..9db9de7 100755 Binary files a/test/test.o and b/test/test.o differ