Chronos
0.0
A advanced 2D rendering and animation system
Loading...
Searching...
No Matches
logging.hpp
Go to the documentation of this file.
1
/*
2
Copyright (c) 2024 Rahul Satish Vadhyar
3
4
Permission is hereby granted, free of charge, to any person obtaining a copy
5
of this software and associated documentation files (the "Software"), to deal
6
in the Software without restriction, including without limitation the rights
7
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
copies of the Software, and to permit persons to whom the Software is
9
furnished to do so, subject to the following conditions:
10
11
The above copyright notice and this permission notice shall be included in all
12
copies or substantial portions of the Software.
13
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
SOFTWARE.
21
*/
22
#pragma once
23
#include <iostream>
24
#include <filesystem>
25
#include <chrono>
26
#include <iomanip>
27
#include <sstream>
28
// 0 - nothing
29
// 1 - additional info on errors
30
// 2 - basic info
31
// 3 - verbose
32
// 4 - includes frame fraw
33
static
inline
std::string
getFileName
(
const
std::string& path)
34
{
35
std::filesystem::path p(path);
36
return
p.filename().string();
37
}
38
39
static
inline
std::string
getTimestamp
()
40
{
41
auto
now = std::chrono::system_clock::now();
42
auto
now_ns = std::chrono::duration_cast<std::chrono::milliseconds>(
43
now.time_since_epoch())
44
.count();
45
std::ostringstream oss;
46
oss << now_ns;
47
return
oss.str();
48
}
49
50
#ifdef CHRONOS_ENABLE_LOGGING
51
#define S1(x) #x
52
#define S2(x) S1(x)
53
#define LOCATION __FILE__ ":" S2(__LINE__)
54
#define LOG(LEVEL, MESSAGE) \
55
if (LEVEL <= CHRONOS_ENABLE_LOGGING) { \
56
std::cout << "[Chronos][" << getFileName(LOCATION) << "]" << "[" \
57
<< getTimestamp() << "]" << ": " << MESSAGE << std::endl; \
58
}
59
#else
60
#define LOG(LEVEL, MESSAGE)
61
#endif
getFileName
static std::string getFileName(const std::string &path)
Definition
logging.hpp:33
getTimestamp
static std::string getTimestamp()
Definition
logging.hpp:39
Source
Common
logging.hpp
Generated by
1.9.8