split into src and lib and socket changes
* libanthracite files are now all in lib/ * anthracite-bin + anthracite-api-bin files are now all in src/ * socket split into header and source properly
This commit is contained in:
parent
fba87f3fbb
commit
71be773d49
24 changed files with 49 additions and 121 deletions
22
lib/log/log.cpp
Normal file
22
lib/log/log.cpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include "./log.hpp"
|
||||
|
||||
namespace anthracite::log {
|
||||
enum LOG_LEVEL Logger::_level = LOG_LEVEL_NONE;
|
||||
|
||||
// TODO: implement logger as a singleton to prevent duplicates
|
||||
Logger::Logger() = default;
|
||||
void Logger::initialize(enum LOG_LEVEL level) {
|
||||
_level = level;
|
||||
}
|
||||
|
||||
LogBuf::LogBuf(std::ostream& output_stream, const std::string& tag, enum LOG_LEVEL level) : _output_stream(output_stream), _tag(tag), _level(level) {}
|
||||
|
||||
int LogBuf::sync() {
|
||||
if (this->_level <= logger._level) {
|
||||
std::cout << "[" << this ->_tag << "] " << this->str();
|
||||
std::cout.flush();
|
||||
}
|
||||
this->str("");
|
||||
return 0;
|
||||
}
|
||||
};
|
53
lib/log/log.hpp
Normal file
53
lib/log/log.hpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace anthracite::log {
|
||||
enum LOG_LEVEL {
|
||||
LOG_LEVEL_NONE = 0,
|
||||
LOG_LEVEL_ERROR = 1,
|
||||
LOG_LEVEL_WARN = 2,
|
||||
LOG_LEVEL_INFO = 3,
|
||||
LOG_LEVEL_VERBOSE = 4,
|
||||
LOG_LEVEL_DEBUG = 5
|
||||
};
|
||||
|
||||
class Logger {
|
||||
friend class LogBuf;
|
||||
static enum LOG_LEVEL _level;
|
||||
public:
|
||||
|
||||
Logger();
|
||||
void initialize(enum LOG_LEVEL level);
|
||||
};
|
||||
|
||||
|
||||
class LogBuf : public std::stringbuf
|
||||
{
|
||||
std::string _tag;
|
||||
std::ostream& _output_stream;
|
||||
enum LOG_LEVEL _level;
|
||||
public:
|
||||
LogBuf(std::ostream& output_stream, const std::string& tag, enum LOG_LEVEL level);
|
||||
int sync() override;
|
||||
};
|
||||
|
||||
static class Logger logger{};
|
||||
|
||||
static class LogBuf errBuf{std::cerr, "EROR", LOG_LEVEL_ERROR};
|
||||
static std::ostream err(&errBuf);
|
||||
|
||||
static class LogBuf warnBuf{std::cerr, "WARN", LOG_LEVEL_WARN};
|
||||
static std::ostream warn(&warnBuf);
|
||||
|
||||
static class LogBuf infoBuf{std::cout, "INFO", LOG_LEVEL_INFO};
|
||||
static std::ostream info(&infoBuf);
|
||||
|
||||
static class LogBuf verboseBuf{std::cout, "VERB", LOG_LEVEL_VERBOSE};
|
||||
static std::ostream verbose(&verboseBuf);
|
||||
|
||||
static class LogBuf debugBuf{std::cout, "DEBG", LOG_LEVEL_DEBUG};
|
||||
static std::ostream debug(&debugBuf);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue