Implement basic capability to log to specified file.
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
/// Developed & Maintained by Josh O'Leary
|
||||
/// This work is dedicated to the public domain.
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <format>
|
||||
@@ -40,6 +39,7 @@ namespace jlog
|
||||
std::string timestamp;
|
||||
};
|
||||
|
||||
// TODO: Fully implement logging callback.
|
||||
static Event<LogEntry> on_log = Event<LogEntry>();
|
||||
|
||||
inline std::vector<LogEntry> log_history;
|
||||
@@ -51,9 +51,13 @@ namespace jlog
|
||||
std::string delimiter = "[]";
|
||||
};
|
||||
|
||||
void set_default_logfile(const std::string& filename);
|
||||
|
||||
std::string get_timestamp();
|
||||
void log_to_console(const std::string& message);
|
||||
void log_to_file(const std::string& message);
|
||||
void log_to_file(const std::string& filename, const std::string& message);
|
||||
void log_to_stream(std::ostream stream, const std::string& message);
|
||||
|
||||
void log(std::vector<token> tokens);
|
||||
|
||||
|
@@ -5,6 +5,15 @@
|
||||
|
||||
namespace jlog
|
||||
{
|
||||
|
||||
static std::string default_logfile = "latest.log";
|
||||
|
||||
void set_default_logfile(const std::string& filename)
|
||||
{
|
||||
default_logfile = filename;
|
||||
}
|
||||
|
||||
|
||||
std::string get_timestamp()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
@@ -29,11 +38,23 @@ namespace jlog
|
||||
|
||||
void log_to_file(const std::string& message)
|
||||
{
|
||||
std::ofstream latest_log("latest.log", std::ios_base::app);
|
||||
std::ofstream latest_log(default_logfile, std::ios_base::app);
|
||||
latest_log << message;
|
||||
latest_log.close();
|
||||
}
|
||||
|
||||
void log_to_file(const std::string& filename, const std::string& message)
|
||||
{
|
||||
std::ofstream latest_log(filename, std::ios_base::app);
|
||||
latest_log << message;
|
||||
latest_log.close();
|
||||
}
|
||||
|
||||
void log_to_stream(std::ostream stream, const std::string& message)
|
||||
{
|
||||
stream << message;
|
||||
}
|
||||
|
||||
std::vector<token> trace_format(
|
||||
const std::string& func,
|
||||
const std::string& file,
|
||||
|
@@ -1,3 +1,5 @@
|
||||
|
||||
|
||||
#include <jlog/jlog.hpp>
|
||||
#include <string>
|
||||
|
||||
|
Reference in New Issue
Block a user