Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a4f103d0c8 | |||
| bb99d8d812 | |||
| 1e6fecb7bd | |||
| 88520915dc |
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
#include <boost/asio/io_context.hpp>
|
||||
|
||||
// IO Contextct
|
||||
using IoContext = boost::asio::io_context;
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
// TCP
|
||||
using TcpSocket = boost::asio::ip::tcp::socket;
|
||||
using TcpAcceptor = boost::asio::ip::tcp::acceptor;
|
||||
using TcpEndpoint = boost::asio::ip::tcp::endpoint;
|
||||
using TcpResolver = boost::asio::ip::tcp::resolver;
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
// Timers
|
||||
using SteadyTimer = boost::asio::steady_timer;
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
// Error handling
|
||||
using ErrorCode = boost::system::error_code;
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
// Fixed-width unsigned integers
|
||||
using u8 = std::uint8_t;
|
||||
using u32 = std::uint32_t;
|
||||
using u64 = std::uint64_t;
|
||||
@@ -0,0 +1,63 @@
|
||||
#include "logger.hpp"
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time_io.hpp>
|
||||
|
||||
void Logger::init(bool toConsole, const std::string_view filePath)
|
||||
{
|
||||
using namespace boost::log;
|
||||
using namespace boost::posix_time;
|
||||
|
||||
add_common_attributes();
|
||||
|
||||
if (toConsole) {
|
||||
add_console_log(
|
||||
std::clog,
|
||||
keywords::format =
|
||||
(expressions::stream
|
||||
<< "["
|
||||
<< expressions::attr<boost::posix_time::ptime>("TimeStamp")
|
||||
<< "] "
|
||||
<< "<" << trivial::severity << "> " << expressions::smessage)
|
||||
);
|
||||
}
|
||||
|
||||
if (!filePath.empty()) {
|
||||
add_file_log(
|
||||
keywords::file_name = filePath,
|
||||
keywords::auto_flush = true,
|
||||
keywords::format =
|
||||
(expressions::stream
|
||||
<< "["
|
||||
<< expressions::attr<boost::posix_time::ptime>("TimeStamp")
|
||||
<< "] "
|
||||
<< "<" << trivial::severity << "> " << expressions::smessage)
|
||||
);
|
||||
}
|
||||
|
||||
core::get()->set_filter(trivial::severity >= trivial::info);
|
||||
}
|
||||
|
||||
void Logger::info(const std::string_view msg)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(info) << msg;
|
||||
}
|
||||
|
||||
void Logger::warn(const std::string_view msg)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(warning) << msg;
|
||||
}
|
||||
|
||||
void Logger::error(const std::string_view msg)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error) << msg;
|
||||
}
|
||||
|
||||
void Logger::debug(const std::string_view msg)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(debug) << msg;
|
||||
}
|
||||
|
||||
void Logger::fatal(const std::string_view msg)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(fatal) << msg;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/log/core.hpp>
|
||||
#include <boost/log/expressions.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||
#include <boost/log/utility/setup/console.hpp>
|
||||
#include <boost/log/utility/setup/file.hpp>
|
||||
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
static void
|
||||
init(bool toConsole = true, const std::string_view filePath = "");
|
||||
|
||||
static void info(const std::string_view msg);
|
||||
static void warn(const std::string_view msg);
|
||||
static void error(const std::string_view msg);
|
||||
static void debug(const std::string_view msg);
|
||||
static void fatal(const std::string_view msg);
|
||||
};
|
||||
Reference in New Issue
Block a user