-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlog_internal.h
52 lines (39 loc) · 1.19 KB
/
log_internal.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
#ifndef __ASHUFFLE_LOG_INTERNAL_H__
#define __ASHUFFLE_LOG_INTERNAL_H__
#include <cassert>
#include <fstream>
#include <iostream>
#include <absl/strings/str_format.h>
namespace ashuffle {
namespace log {
struct SourceLocation final {
SourceLocation(const std::string_view file = __builtin_FILE(),
const std::string_view function = __builtin_FUNCTION(),
unsigned line = __builtin_LINE())
: file(file), function(function), line(line) {}
const std::string_view file;
const std::string_view function;
const unsigned line;
};
std::ostream& operator<<(std::ostream&, const SourceLocation&);
// Logger is an object that owns the output file and standard formatting
// for logs.
class Logger final {
public:
Logger(){};
void SetOutput(std::ostream& output) { output_ = &output; }
std::ostream& Stream() {
static std::ofstream devnull("/dev/null");
if (output_ != nullptr) {
return *output_;
}
return devnull;
}
private:
std::ostream* output_;
};
// Fetch the default logger.
Logger& DefaultLogger();
} // namespace log
} // namespace ashuffle
#endif // __ASHUFFLE_LOG_INTERNAL_H__