Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9ccabcd1eb | |||
| aeeb22d351 | |||
| a4f103d0c8 | |||
| bb99d8d812 | |||
| 1e6fecb7bd | |||
| 88520915dc |
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
// Alias for raw byte buffer
|
||||
using ByteBuffer = std::vector<std::uint8_t>;
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// Sequential file chunk index
|
||||
using ChunkIndex = std::uint32_t;
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// File total size in bytes
|
||||
using FileSize = std::uint64_t;
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// Wire length prefix type for a single framed message (big-endian on the wire)
|
||||
using FrameLength = std::uint32_t;
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// Client, group, or message ID
|
||||
using Id = std::uint64_t;
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/asio/io_context.hpp>
|
||||
|
||||
// IO Context
|
||||
using IoContext = boost::asio::io_context;
|
||||
@@ -0,0 +1,9 @@
|
||||
#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,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
// Timers
|
||||
using SteadyTimer = boost::asio::steady_timer;
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
// Error handling
|
||||
using ErrorCode = boost::system::error_code;
|
||||
@@ -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