Chronos 0.0
A advanced 2D rendering and animation system
Loading...
Searching...
No Matches
logging.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2024 Rahul Satish Vadhyar
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20SOFTWARE.
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
33static inline std::string getFileName(const std::string& path)
34{
35 std::filesystem::path p(path);
36 return p.filename().string();
37}
38
39static 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
static std::string getFileName(const std::string &path)
Definition logging.hpp:33
static std::string getTimestamp()
Definition logging.hpp:39