Add OnLog event to CompoundLogger
This commit is contained in:
@@ -1,18 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "fstream"
|
#include <fstream>
|
||||||
#include "iostream"
|
#include <iostream>
|
||||||
#include "source_location"
|
#include <source_location>
|
||||||
#include "Token.hpp"
|
#include <jlog/Token.hpp>
|
||||||
#include "Timestamp.hpp"
|
#include <jlog/Timestamp.hpp>
|
||||||
|
#include <Event.h>
|
||||||
|
|
||||||
namespace jlog {
|
namespace jlog {
|
||||||
class Logger {
|
class Logger {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Logger(std::ostream &stream = std::cout) : os{stream} {};
|
Logger(std::ostream &stream = std::cout) : os{stream} {};
|
||||||
public:
|
public:
|
||||||
void
|
void operator()(const std::string &message, const std::source_location &location = std::source_location::current(),
|
||||||
operator()(const std::string &message, const std::source_location &location = std::source_location::current(),
|
|
||||||
const Timestamp &ts = Timestamp()) {
|
const Timestamp &ts = Timestamp()) {
|
||||||
if (Enable)
|
if (Enable)
|
||||||
Log(message, location, ts);
|
Log(message, location, ts);
|
||||||
@@ -127,6 +127,7 @@ namespace jlog {
|
|||||||
|
|
||||||
class CompoundLogger : protected ConsoleLogger, protected FileLogger {
|
class CompoundLogger : protected ConsoleLogger, protected FileLogger {
|
||||||
public:
|
public:
|
||||||
|
Event<std::string, Color4> OnLog;
|
||||||
explicit CompoundLogger(const std::string &context, std::ofstream &file) : ConsoleLogger(context),
|
explicit CompoundLogger(const std::string &context, std::ofstream &file) : ConsoleLogger(context),
|
||||||
FileLogger(context, file) {};
|
FileLogger(context, file) {};
|
||||||
public:
|
public:
|
||||||
@@ -137,6 +138,7 @@ namespace jlog {
|
|||||||
virtual void
|
virtual void
|
||||||
Log(const std::string &message, const std::source_location &location = std::source_location::current(),
|
Log(const std::string &message, const std::source_location &location = std::source_location::current(),
|
||||||
const Timestamp &ts = Timestamp()) {
|
const Timestamp &ts = Timestamp()) {
|
||||||
|
OnLog.Invoke(message, messageColor);
|
||||||
ConsoleLogger::Log(message, location, ts);
|
ConsoleLogger::Log(message, location, ts);
|
||||||
FileLogger::Log(message, location, ts);
|
FileLogger::Log(message, location, ts);
|
||||||
}
|
}
|
||||||
|
@@ -7,13 +7,13 @@ namespace jlog {
|
|||||||
public:
|
public:
|
||||||
Timestamp();
|
Timestamp();
|
||||||
public:
|
public:
|
||||||
std::chrono::year Year() {return y;};
|
[[nodiscard]] std::chrono::year Year() const {return y;};
|
||||||
std::chrono::month Month() {return m;};
|
[[nodiscard]] std::chrono::month Month() const {return m;};
|
||||||
std::chrono::day Day() {return d;}
|
[[nodiscard]] std::chrono::day Day() const {return d;}
|
||||||
std::chrono::duration<long, std::ratio<3600>> Hour() {return h;};
|
[[nodiscard]] std::chrono::duration<long, std::ratio<3600>> Hour() const {return h;};
|
||||||
std::chrono::duration<long, std::ratio<60>> Minute() {return M;};
|
[[nodiscard]] std::chrono::duration<long, std::ratio<60>> Minute() const {return M;};
|
||||||
std::chrono::duration<long> Second() {return s;};
|
[[nodiscard]] std::chrono::duration<long> Second() const {return s;};
|
||||||
std::chrono::duration<long, std::ratio<1, 1000>> Millisecond() {return ms;};
|
[[nodiscard]] std::chrono::duration<long, std::ratio<1, 1000>> Millisecond() const {return ms;};
|
||||||
private:
|
private:
|
||||||
std::chrono::year y;
|
std::chrono::year y;
|
||||||
std::chrono::month m;
|
std::chrono::month m;
|
||||||
|
Reference in New Issue
Block a user