-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSource.cpp
42 lines (32 loc) · 1.6 KB
/
Source.cpp
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
#include <iostream>
#include <string>
#define SBLOGGER_LOG_LEVEL SBLOGGER_LEVEL_TRACE
#include "SmallBetterLogger.hpp"
int main()
{
// Declarations (Logger)
sblogger::StreamLogger l; // Simplest way to make a logger
sblogger::stream_logger logErr(sblogger::StreamType::STDERR, "[%F %T][%^er]"); // Set stream type and custom format
sblogger::logger* logLog = new sblogger::StreamLogger(sblogger::StreamType::STDLOG, "[Log]"); // Making use of the abstract class
// Declarations (FileLogger)
sblogger::FileLogger fileLogger("example.log", "[File Log]");
//sblogger::FileLogger fileLogger2(" .txt", "[File Log]"); // Will throw error since filename is empty
// Basic calls (Logger)
l.WriteLine("This is a normal log to STDOUT.");
l.WriteLine();
l.Indent(); // Add indent to stylize logs
l.WriteLine(std::string("Hello, {0}!"), "World"); // Message to be writen can also be a variable of type std::string
l.Dedent(); // Remove indent at any time from the logger
l.Write("I am {0} and {1} years old.{2} {0}", "Michael", 28); // If you give more placeholders than parameters, they are just writen as is
l.Write("{0}", "\n", "hey"); // If you give more parameters, they are just ignored
logErr.WriteLine("stderr");
logLog->WriteLine("stdlog");
// Basic calls (FileLogger)
fileLogger.ClearLogs(); // This will clear the log file utilised by the FileLogger
fileLogger.WriteLine("This is a test."); // All methods previously shown can also be used with files
fileLogger.Indent();
fileLogger.Write("Hello World!");
delete logLog;
std::cin.get();
return 0;
}