Netwhere
 All Classes Pages
logger.hpp
1 /*
2  * Copyright (c) 2017, Ben Smith
3  * All rights reserved.
4  *
5  */
6 
7 #ifndef __LOGGER_H__
8 #define __LOGGER_H__
9 
16 #include <time.h>
17 #include <iostream>
18 #include <string>
19 
20 template<typename T>
21 void log(const T& message) {
22  char now_str[256];
23  time_t now = time(nullptr);
24  strftime(now_str, sizeof(now_str), "[%F %T]", localtime(&now));
25 
26  std::cerr << now_str << " -- " << message << std::endl;
27 }
28 
29 #ifdef ENABLE_LOGGING
30 #define LOG(x) log(x);
31 #else
32 #define LOG(x)
33 #endif
34 
35 #endif
36