MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / log

Function log

src/logging.cpp:39–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39LAMBDA_RUNTIME_API
40void log(verbosity v, char const* tag, char const* msg, va_list args)
41{
42 va_list copy;
43 va_copy(copy, args);
44 const int sz = vsnprintf(nullptr, 0, msg, args) + 1;
45 if (sz < 0) {
46 puts("error occurred during log formatting!\n");
47 va_end(copy);
48 return;
49 }
50 constexpr int max_stack_buffer_size = 512;
51 std::array<char, max_stack_buffer_size> buf;
52 char* out = buf.data();
53 if (sz >= max_stack_buffer_size) {
54 out = new char[sz];
55 }
56
57 vsnprintf(out, sz, msg, copy);
58 va_end(copy);
59 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
60 std::chrono::high_resolution_clock::now().time_since_epoch());
61 printf("%s [%lld] %s %s\n", get_prefix(v), static_cast<long long>(ms.count()), tag, out);
62 // stdout is not line-buffered when redirected (for example to a file or to another process) so we must flush it
63 // manually.
64 fflush(stdout);
65 if (out != buf.data()) {
66 delete[] out;
67 }
68}
69} // namespace logging
70} // namespace aws

Callers 3

log_errorFunction · 0.85
log_infoFunction · 0.85
log_debugFunction · 0.85

Calls 1

get_prefixFunction · 0.85

Tested by

no test coverage detected