-
Notifications
You must be signed in to change notification settings - Fork 0
/
TLogger.h
120 lines (104 loc) · 3.8 KB
/
TLogger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#pragma once // This worked on older versions of the compiler including it,
//if something goes wrong try removing this
#ifndef TLOGGER
#define TLOGGER
#include <iostream>
#include <string>
#include <queue>
#include <thread>
#include <ctime>
#include <sstream>
#include <fstream>
#include <vector>
#include <windows.h>
#include <chrono>
#include <map>
#include <thread>
using namespace std;
wstring s2ws(const std::string& s); // used to fix problems after updating the compiler
// Takes a simple string and converts it to a wstring.
//vector<string> compressed_words;
enum severity_levels
{
always, // Most basic of a log
basic, // Means we are logging actual information veruses debugging logs
info, // Can mean anything other then something has happened
debug, // Means something has happened - (good or bad)
success, // Means something good has happened
warning, // Means something bad might happen
error, // Means something bad has happened but will not crash the program
critical // Means something bad has happened and will crash the program
};
class logging
{
/*
This class is designed for taking input and outputting it into a file
The program will work with 2 threads.
One thread will exist only to remove the bottle neck of writing to file
The only issue is there is a suttle delay when making the new thread
Another issue is that there is a chance that there isnt enough room for
all the threads. If the computer cant handle 2 threads then this logger
might not be the best.
The way this program works is that you create the function
You can define the program, you dont have to initalize anything
You can instantly start adding lines to the file.
The only thing is nothing will actually be written unless you
call the function init()
This function will start the other thread to start writing to
the file.
*/
private:
//------------------- Variables
bool alive = true;
bool occured = false;
string directory_location = "Recorded Logs";
queue<string> log_queue;
queue<vector<char>> log_queue_2;
thread writing_thread;
string thread_name = "Writing Thread";
string log_format = "%D %T %F %L %S : %M";
// %D = Date and Time
// %T = Thread Name
// %F = File Name-
// %S = Severity
// %L = Line Number
// %M = Message
char between_variable = 'œ';
string null_string = "œ";
string previous_date = "None";
vector<string> file_keys;
vector<ofstream> file_values;
unsigned int maxium_compressed_string_length = 0;
vector<string> shortened_strings; // This is where each set of characters is stored that will be shortened.
//------------------- Functions
void writing_function(void);
string get_date_and_time(void);
string file_name_only(string file_location);
string int_2_str(long long number);
vector<string> find_order(void);
vector<char> return_compressed_string(string home_string);
string return_decompresed_string(vector<char> compressed_string);
public:
logging();
~logging();
void init(void); // Starts the logging process
void kill(void); // Ends the logging process
void __addline__(string line, string file_name, int line_numbet, severity_levels level = basic);
#define addline(line, level) __addline__(line, __FILE__, __LINE__, level) // This is the one you want to call.
void change_format(string new_format);
void change_thread_name(string new_name);
void change_directory(string new_directory);
void change_compression(bool is_compression_true);
bool get_shortened_string(void);
};
class thread_names
{// The entire purpose of this tread is to organize threads
private:
map<thread::id, string> names;
public:
thread_names();
~thread_names();
void name_the_thread(string name);
string get_thread_name(void);
};
#endif // !TLOGGER