Compare commits
No commits in common. "dev" and "loglevel" have entirely different histories.
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,4 +1,3 @@
|
|||||||
.vscode
|
.vscode
|
||||||
example
|
example/*
|
||||||
test/*.o
|
test/*.o
|
||||||
build
|
|
@ -1,30 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
|
||||||
|
|
||||||
project(log)
|
|
||||||
|
|
||||||
# Postavi verziju projekta
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
||||||
|
|
||||||
# Pronađi Boost biblioteku (ako nije uobičajeni direktorijum, postavi put)
|
|
||||||
# find_package(Boost REQUIRED COMPONENTS system)
|
|
||||||
|
|
||||||
# Dodaj direktorijume sa zaglavljima
|
|
||||||
include_directories(lib)
|
|
||||||
|
|
||||||
# Dodaj biblioteku
|
|
||||||
add_library(log STATIC
|
|
||||||
src/log.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
# # Linkaj log biblioteku sa Boost-om
|
|
||||||
# target_link_libraries(log Boost::system)
|
|
||||||
|
|
||||||
# Dodaj testove
|
|
||||||
add_subdirectory(test)
|
|
||||||
|
|
||||||
|
|
||||||
# Instaliraj biblioteku
|
|
||||||
# install(TARGETS log DESTINATION lib)
|
|
||||||
# install(FILES lib/log.hpp lib/define.hpp lib/engine.hpp lib/filesystem.hpp lib/timers.hpp lib/trigger.hpp DESTINATION include/log)
|
|
||||||
#
|
|
1
example/2023-05-21.log
Normal file
1
example/2023-05-21.log
Normal file
@ -0,0 +1 @@
|
|||||||
|
23:08:58 [EVENT] Start loging
|
3
example/2023-07-27.log
Normal file
3
example/2023-07-27.log
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
18:29:30 [EVENT] Start loging
|
||||||
|
18:29:44 [EVENT] Start loging
|
||||||
|
18:29:47 [EVENT] Start loging
|
5
example/2023-5-20.log
Normal file
5
example/2023-5-20.log
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[EVENT] Start loging
|
||||||
|
[EVENT] Start loging
|
||||||
|
10:58:12 [EVENT] Start loging
|
||||||
|
10:59:19 [EVENT] Start loging
|
||||||
|
11:00:17 [EVENT] Start loging
|
2
example/2023-5-21.log
Normal file
2
example/2023-5-21.log
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
11:00:58 [EVENT] Start loging
|
||||||
|
13:02:17 [EVENT] Start loging
|
@ -14,7 +14,6 @@
|
|||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
#endif
|
#endif
|
||||||
namespace marcelb {
|
namespace marcelb {
|
||||||
namespace logging {
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -117,7 +116,6 @@ class log {
|
|||||||
~log();
|
~log();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
34
src/log.cpp
34
src/log.cpp
@ -1,9 +1,6 @@
|
|||||||
#include "../lib/log.hpp"
|
#include "../lib/log.hpp"
|
||||||
|
|
||||||
namespace marcelb {
|
marcelb::log::log(string _dir, Level _loglevel, bool _isKeepOpen, bool _printInConsole) {
|
||||||
namespace logging {
|
|
||||||
|
|
||||||
log::log(string _dir, Level _loglevel, bool _isKeepOpen, bool _printInConsole) {
|
|
||||||
dir = _dir;
|
dir = _dir;
|
||||||
loglevel = _loglevel;
|
loglevel = _loglevel;
|
||||||
isKeepOpen = _isKeepOpen;
|
isKeepOpen = _isKeepOpen;
|
||||||
@ -25,28 +22,28 @@ log::log(string _dir, Level _loglevel, bool _isKeepOpen, bool _printInConsole) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool log::isdir() {
|
bool marcelb::log::isdir() {
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
return stat(dir.c_str(), &sb) == 0;
|
return stat(dir.c_str(), &sb) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool log::open() {
|
bool marcelb::log::open() {
|
||||||
logfile = ofstream (path, ios_base::app);
|
logfile = ofstream (path, ios_base::app);
|
||||||
return logfile.is_open();
|
return logfile.is_open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void log::loose() {
|
void marcelb::log::loose() {
|
||||||
logfile.close();
|
logfile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void log::setMoment() {
|
void marcelb::log::setMoment() {
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
time (&rawtime);
|
time (&rawtime);
|
||||||
moment = localtime (&rawtime);
|
moment = localtime (&rawtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void log::put(string logline, Level _level) {
|
void marcelb::log::put(string logline, Level _level) {
|
||||||
if (_level < loglevel) {
|
if (_level < loglevel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -86,7 +83,7 @@ void log::put(string logline, Level _level) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void log::setPath() {
|
void marcelb::log::setPath() {
|
||||||
if (dir[dir.length()-1] != '/') {
|
if (dir[dir.length()-1] != '/') {
|
||||||
dir.push_back('/');
|
dir.push_back('/');
|
||||||
}
|
}
|
||||||
@ -97,7 +94,7 @@ void 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 log::setPrefix(string &logline, Level &_level) {
|
void marcelb::log::setPrefix(string &logline, Level &_level) {
|
||||||
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;
|
||||||
@ -128,31 +125,28 @@ void log::setPrefix(string &logline, Level &_level) {
|
|||||||
logline = _logline + logline;
|
logline = _logline + logline;
|
||||||
}
|
}
|
||||||
|
|
||||||
void log::debug(string logline) {
|
void marcelb::log::debug(string logline) {
|
||||||
put(logline, DEBUG);
|
put(logline, DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
void log::info(string logline) {
|
void marcelb::log::info(string logline) {
|
||||||
put(logline, INFO);
|
put(logline, INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
void log::warning(string logline) {
|
void marcelb::log::warning(string logline) {
|
||||||
put(logline, WARNING);
|
put(logline, WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
void log::error(string logline) {
|
void marcelb::log::error(string logline) {
|
||||||
put(logline, ERROR);
|
put(logline, ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void log::fatal(string logline) {
|
void marcelb::log::fatal(string logline) {
|
||||||
put(logline, FATAL);
|
put(logline, FATAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
log::~log() {
|
marcelb::log::~log() {
|
||||||
loose();
|
loose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
add_executable(log_test test.cpp)
|
|
||||||
|
|
||||||
target_link_libraries(log_test log)
|
|
@ -3,9 +3,9 @@
|
|||||||
#include "../lib/log.hpp"
|
#include "../lib/log.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace marcelb::logging;
|
using namespace marcelb;
|
||||||
|
|
||||||
log mylog("../example", Level::INFO, false);
|
log mylog("../example", Level::FATAL, false);
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
mylog.debug("Start debug loging");
|
mylog.debug("Start debug loging");
|
||||||
|
BIN
test/test.o
Executable file
BIN
test/test.o
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user