Compare commits
10 Commits
Prerelease
...
main
Author | SHA1 | Date | |
---|---|---|---|
6836cab537 | |||
e618fd9b31 | |||
884f23f79e | |||
cf4e19e340 | |||
12d3714eda | |||
f3cec87518 | |||
7c9a3bddc8 | |||
16a2b8ead0 | |||
82fb6c64ca | |||
b3dbd1b556 |
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.18..27)
|
||||
cmake_minimum_required(VERSION 3.18..3.27)
|
||||
PROJECT(jlog
|
||||
VERSION 1.0
|
||||
LANGUAGES CXX
|
||||
@@ -23,12 +23,12 @@ include_directories("include")
|
||||
|
||||
CPMAddPackage(
|
||||
NAME Event
|
||||
URL https://git.redacted.cc/josh/Event/archive/Release-10.zip
|
||||
URL https://git.redacted.cc/josh/Event/archive/Release-12.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME mcolor
|
||||
URL https://git.redacted.cc/maxine/mcolor/archive/Prerelease-4.zip
|
||||
URL https://git.redacted.cc/maxine/mcolor/archive/Release-1.zip
|
||||
)
|
||||
|
||||
if (UNIX)
|
||||
|
@@ -1,18 +1,18 @@
|
||||
#pragma once
|
||||
#include "fstream"
|
||||
#include "iostream"
|
||||
#include "source_location"
|
||||
#include "Token.hpp"
|
||||
#include "Timestamp.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <source_location>
|
||||
#include <jlog/Token.hpp>
|
||||
#include <jlog/Timestamp.hpp>
|
||||
#include <Event.h>
|
||||
|
||||
namespace jlog {
|
||||
class Logger {
|
||||
public:
|
||||
|
||||
Logger(std::ostream &stream = std::cout) : os{stream} {};
|
||||
public:
|
||||
void
|
||||
operator()(const std::string &message, const std::source_location &location = std::source_location::current(),
|
||||
void operator()(const std::string &message, const std::source_location &location = std::source_location::current(),
|
||||
const Timestamp &ts = Timestamp()) {
|
||||
if (Enable)
|
||||
Log(message, location, ts);
|
||||
@@ -47,10 +47,7 @@ namespace jlog {
|
||||
const Timestamp &ts = Timestamp()) {
|
||||
if (!Enable)
|
||||
return;
|
||||
// Disable color on Windows. I've been trying my best to keep this macro hidden from the user. - maxine
|
||||
#ifdef WIN32
|
||||
IncludeColor = false;
|
||||
#endif
|
||||
|
||||
if (IncludeTimestamp) {
|
||||
Timestamp ts;
|
||||
os << token{std::format(
|
||||
@@ -127,6 +124,7 @@ namespace jlog {
|
||||
|
||||
class CompoundLogger : protected ConsoleLogger, protected FileLogger {
|
||||
public:
|
||||
Event<std::string, Color4> OnLog;
|
||||
explicit CompoundLogger(const std::string &context, std::ofstream &file) : ConsoleLogger(context),
|
||||
FileLogger(context, file) {};
|
||||
public:
|
||||
@@ -137,6 +135,7 @@ namespace jlog {
|
||||
virtual void
|
||||
Log(const std::string &message, const std::source_location &location = std::source_location::current(),
|
||||
const Timestamp &ts = Timestamp()) {
|
||||
OnLog.Invoke(message, messageColor);
|
||||
ConsoleLogger::Log(message, location, ts);
|
||||
FileLogger::Log(message, location, ts);
|
||||
}
|
||||
@@ -187,4 +186,38 @@ namespace jlog {
|
||||
extern GenericLogger Fatal;
|
||||
extern GenericLogger Verbose;
|
||||
extern GenericLogger Debug;
|
||||
|
||||
class LibraryLogger {
|
||||
public:
|
||||
LibraryLogger(const std::string libname) :
|
||||
Info {libname + "::" + "info", GlobalLogFile, Colors::Green, Colors::Gray, Colors::Gray, Colors::Green, Colors::White},
|
||||
Warning {libname + "::" + "warning", GlobalLogFile, Colors::Yellow, Colors::Gray, Colors::Gray, Colors::Yellow, Colors::White},
|
||||
Error {libname + "::" + "error", GlobalLogFile, Colors::Red, Colors::Gray, Colors::Gray, Colors::Red, Colors::White},
|
||||
Fatal {libname + "::" + "fatal", GlobalLogFile, Colors::Reds::Crimson, Colors::Gray, Colors::Gray, Colors::Reds::Crimson, Colors::White},
|
||||
Verbose {libname + "::" + "verbose", GlobalLogFile, Colors::Blue, Colors::Gray, Colors::Gray, Colors::Blue, Colors::White},
|
||||
Debug {libname + "::" + "debug", GlobalLogFile, Colors::Purples::Purple, Colors::Gray, Colors::Gray, Colors::Purples::Purple, Colors::White}
|
||||
{}
|
||||
public:
|
||||
GenericLogger Info;// {"info", GlobalLogFile, Colors::Green, Colors::Gray, Colors::Gray, Colors::Green, Colors::White};
|
||||
GenericLogger Warning;// {"warning", GlobalLogFile, Colors::Yellow, Colors::Gray, Colors::Gray, Colors::Yellow, Colors::White};
|
||||
GenericLogger Error;// {"error", GlobalLogFile, Colors::Red, Colors::Gray, Colors::Gray, Colors::Red, Colors::White};
|
||||
GenericLogger Fatal;// {"fatal", GlobalLogFile, Colors::Reds::Crimson, Colors::Gray, Colors::Gray, Colors::Reds::Crimson, Colors::White};
|
||||
GenericLogger Verbose;// {"verbose", GlobalLogFile, Colors::Blue, Colors::Gray, Colors::Gray, Colors::Blue, Colors::White};
|
||||
GenericLogger Debug;// {"debug", GlobalLogFile, Colors::Purples::Purple, Colors::Gray, Colors::Gray, Colors::Purples::Purple, Colors::White};
|
||||
public:
|
||||
void EnableAll(bool b) {
|
||||
Info.EnableConsole(b);
|
||||
Info.EnableFile(b);
|
||||
Warning.EnableConsole(b);
|
||||
Warning.EnableFile(b);
|
||||
Error.EnableConsole(b);
|
||||
Error.EnableFile(b);
|
||||
Fatal.EnableConsole(b);
|
||||
Fatal.EnableFile(b);
|
||||
Verbose.EnableConsole(b);
|
||||
Verbose.EnableFile(b);
|
||||
Debug.EnableConsole(b);
|
||||
Debug.EnableFile(b);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -7,13 +7,13 @@ namespace jlog {
|
||||
public:
|
||||
Timestamp();
|
||||
public:
|
||||
std::chrono::year Year() {return y;};
|
||||
std::chrono::month Month() {return m;};
|
||||
std::chrono::day Day() {return d;}
|
||||
std::chrono::duration<long, std::ratio<3600>> Hour() {return h;};
|
||||
std::chrono::duration<long, std::ratio<60>> Minute() {return M;};
|
||||
std::chrono::duration<long> Second() {return s;};
|
||||
std::chrono::duration<long, std::ratio<1, 1000>> Millisecond() {return ms;};
|
||||
[[nodiscard]] std::chrono::year Year() const {return y;};
|
||||
[[nodiscard]] std::chrono::month Month() const {return m;};
|
||||
[[nodiscard]] std::chrono::day Day() const {return d;}
|
||||
[[nodiscard]] std::chrono::duration<long, std::ratio<3600>> Hour() const {return h;};
|
||||
[[nodiscard]] std::chrono::duration<long, std::ratio<60>> Minute() const {return M;};
|
||||
[[nodiscard]] std::chrono::duration<long> Second() const {return s;};
|
||||
[[nodiscard]] std::chrono::duration<long, std::ratio<1, 1000>> Millisecond() const {return ms;};
|
||||
private:
|
||||
std::chrono::year y;
|
||||
std::chrono::month m;
|
||||
|
@@ -1,8 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
#include <mcolor.h>
|
||||
#include "Colors.hpp"
|
||||
#include <Colors.hpp>
|
||||
|
||||
namespace jlog {
|
||||
using namespace mcolor;
|
||||
|
18
main.cpp
18
main.cpp
@@ -6,10 +6,9 @@
|
||||
// This work is dedicated to the public domain.
|
||||
#include "jlog/Logger.hpp"
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
mcolor::windowsSaneify();
|
||||
jlog::GenericLogger Demo("demo", jlog::GlobalLogFile);
|
||||
Demo("No new demo yet");
|
||||
jlog::Info("dsadsd");
|
||||
@@ -18,6 +17,21 @@ int main()
|
||||
jlog::Fatal("dsadsd");
|
||||
jlog::Verbose("dsadsd");
|
||||
jlog::Debug("dsadsd");
|
||||
jlog::LibraryLogger libtest("JLog");
|
||||
libtest.Info("A");
|
||||
libtest.Warning("B");
|
||||
libtest.Debug("C");
|
||||
libtest.Error("D");
|
||||
libtest.Fatal("E");
|
||||
libtest.Verbose("G");
|
||||
libtest.EnableAll(false);
|
||||
libtest.Info("A2");
|
||||
libtest.Warning("B2");
|
||||
libtest.Debug("C2");
|
||||
libtest.Error("D2");
|
||||
libtest.Fatal("E2");
|
||||
libtest.Verbose("G2");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "jlog/Token.hpp"
|
||||
#include <jlog/Token.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace jlog {
|
||||
std::string token::Stringer(bool includeColor) {
|
||||
|
Reference in New Issue
Block a user