-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog.hpp
More file actions
64 lines (56 loc) · 1.49 KB
/
Log.hpp
File metadata and controls
64 lines (56 loc) · 1.49 KB
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
/*****************************************************************************/
/*!
\file Log.hpp
\author Yeongki Baek
\par email: yeongki.baek\@digipen.edu
\date 08/01/2017
\brief
This is the interface file for the module
Copyright 2017, Digipen Institute of Technology
*/
/*****************************************************************************/
#pragma once
#include <ostream>
#include <chrono>
#include <fstream>
#ifndef NDEBUG
extern std::chrono::time_point<std::chrono::system_clock> performancetimer_start, performancetimer_end;
#ifdef _WIN32
#define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#else
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#endif
#define START() performancetimer_start = std::chrono::system_clock::now()
struct tracer
{
std::ofstream fout;
std::ostream & cout;
tracer(std::ostream & cout, char const * file, int line, char const * fnc);
~tracer();
template<typename TF, typename ... TR>
void write(TF const& f, TR const& ... rest)
{
write_debug_output(cout, f);
cout << " ";
fout << " ";
write(rest...);
}
template<typename TF>
void write(TF const& f)
{
write_debug_output(cout, f);
}
void write();
template<typename TF>
void write_debug_output(std::ostream & cout, TF const& f)
{
cout << f;
fout << f;
}
};
#define LOG(...) tracer( std::cout, __FILENAME__, __LINE__, __func__ ).write( __VA_ARGS__ )
#else
#define LOG(...)
#define START()
#define END()
#endif