Size: 1578 bytes.


 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
// cs/log.hh
#ifndef CS_LOG_HH
#define CS_LOG_HH

#include <stdio.h>

#include <iomanip>
#include <iostream>
#include <map>
#include <ostream>
#include <string>

#include "cs/util/time.hh"

#define LOG_PRETTY_FUNCTION false
#if LOG_PRETTY_FUNCTION
#define LOG(level)                                      \
  std::cout << "["                                      \
            << cs::util::time::NowAsISO8601TimeUTC()    \
            << "] [" << std::setw(7) << std::left       \
            << #level << "] [" << __FILE__ << ":"       \
            << __LINE__ << "] [" << __PRETTY_FUNCTION__ \
            << "] "
#else
#define LOG(level)                                   \
  std::cout << "["                                   \
            << cs::util::time::NowAsISO8601TimeUTC() \
            << "] [" << std::setw(7) << std::left    \
            << #level << "] [" << __FILE__ << ":"    \
            << __LINE__ << "] "
#endif  // LOG_PRETTY_FUNCTION

#define ENDL std::endl << std::flush

namespace cs::log {

struct StringMapStreamView {
  const std::map<std::string, std::string>& value;
};

inline std::ostream& operator<<(
    std::ostream& os, const StringMapStreamView& view) {
  os << "{";
  bool first = true;
  for (const auto& kv : view.value) {
    if (!first) {
      os << ", ";
    } else {
      first = false;
    }
    os << "<key=" << kv.first << ", value=" << kv.second
       << ">";
  }
  os << "}";
  return os;
}

}  // namespace cs::log

#define STREAM_STRING_MAP(map_expr) \
  ::cs::log::StringMapStreamView { map_expr }

#endif  // CS_LOG_HH
v0 (commit) © 2025 @p13i.io | Load balancer proxied to: cs-code-viewer-1:8080 in 15ms.