GitWatcherBot 1.0.0
A Telegram Bot that notifies you when a new change is made in your repositories (issues, pull requests, stars, forks, and watches)
Loading...
Searching...
No Matches
Log.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <cstring>
6#include <ctime>
7#include <sqlite_orm/sqlite_orm.h>
8#include <tgbotxx/utils/DateTimeUtils.hpp>
9#include <tgbotxx/utils/FileUtils.hpp>
10#include <source_location>
11
12namespace models {
13
14 struct Log {
15 std::int64_t id{};
16 std::string severity; // TRACE, INFO, WARN, ERROR..
17 std::string shortMessage; // Summary
18 std::string longMessage; // Larger text, dump of json of update for example
19 std::time_t timestamp{};
20 // source location
21 std::string filename;
22 std::uint_least32_t line{};
23 std::uint_least32_t column{};
24 std::string functionName;
25
26 static auto table() {
27 using namespace sqlite_orm;
28 return make_table("Logs",
29 make_column("id", &Log::id, primary_key().autoincrement()),
30 make_column("severity", &Log::severity),
31 make_column("shortMessage", &Log::shortMessage),
32 make_column("longMessage", &Log::longMessage, default_value("")),
33 make_column("timestamp", &Log::timestamp),
34 make_column("filename", &Log::filename),
35 make_column("line", &Log::line),
36 make_column("column", &Log::column),
37 make_column("functionName", &Log::functionName)
38 );
39 }
40
41 Log() = default;
42
43 Log(const std::string &sev, const std::string &shortMsg, const std::string &longMsg = "", const std::source_location& here = std::source_location::current()) {
44 severity = sev;
45 shortMessage = shortMsg;
46 longMessage = longMsg;
47 timestamp = std::time(nullptr);
48 filename = here.file_name();
49 line = here.line();
50 column = here.column();
51 functionName = here.function_name();
52 }
53
54
55 std::string toString() const noexcept {
56 std::ostringstream oss{};
57 oss << fs::path(filename).filename().string() << ':' << line << ':' << column << " [" << functionName << "] [" << tgbotxx::DateTimeUtils::toString(timestamp) << "] [" << severity << "]: " << shortMessage;
58 return oss.str();
59 }
60 };
61}
Definition Log.hpp:12
std::string shortMessage
Definition Log.hpp:17
std::string filename
Definition Log.hpp:21
std::time_t timestamp
Definition Log.hpp:19
std::string longMessage
Definition Log.hpp:18
std::int64_t id
Definition Log.hpp:15
std::uint_least32_t line
Definition Log.hpp:22
std::string severity
Definition Log.hpp:16
Log(const std::string &sev, const std::string &shortMsg, const std::string &longMsg="", const std::source_location &here=std::source_location::current())
Definition Log.hpp:43
static auto table()
Definition Log.hpp:26
std::uint_least32_t column
Definition Log.hpp:23
std::string toString() const noexcept
Definition Log.hpp:55
Log()=default
std::string functionName
Definition Log.hpp:24