libtasks Documentation
1.6
Main Page
Namespaces
Classes
Files
File List
File Members
logging.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2013-2014 ADTECH GmbH
3
* Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4
*
5
* Author: Andreas Pohl
6
*/
7
8
#ifndef _TASKS_LOGGING_H_
9
#define _TASKS_LOGGING_H_
10
11
#include <iostream>
12
#include <iomanip>
13
#include <thread>
14
#include <vector>
15
16
#ifdef LOGMUTEX
17
#include <mutex>
18
namespace
tasks {
19
extern
std::mutex g_log_mutex;
20
}
21
#define _LOGMUTEX std::lock_guard<std::mutex> _log_lock(tasks::g_log_mutex)
22
#else
23
#define _LOGMUTEX
24
#endif
25
26
#ifdef _WITH_PUT_TIME
27
#define ttime_init \
28
std::time_t t = std::time(nullptr); \
29
std::tm tm = *std::localtime(&t);
30
#define tput_time(t, f) std::put_time(t, f)
31
#else
32
#define ttime_init
33
#define tput_time(t, f) ""
34
#endif
35
36
#ifndef _WITH_SHORT_LOG
37
#define _LOGDBGINFO \
38
" " << std::setw(14) << std::this_thread::get_id() << " " << std::setw(16) << __FILE__ << ":" << std::setw(3) \
39
<< std::setfill('0') << __LINE__
40
#else
41
#define _LOGDBGINFO ""
42
#endif
43
44
#define tlog(s, m) \
45
{ \
46
ttime_init; \
47
_LOGMUTEX; \
48
s << "[" << tput_time(&tm, "%h %e %T") << _LOGDBGINFO << "] " << std::setfill(' ') << m << std::flush; \
49
}
50
51
#ifdef _DEBUG_OUTPUT
52
#define tdbg(m) tlog(std::clog, m)
53
#else
54
#define tdbg(m)
55
#endif
56
57
#define terr(m) tlog(std::clog, m)
58
59
#endif // _TASKS_LOGGING_H_
include
tasks
logging.h
Generated by
1.8.6