Skip to content

Commit a6b77c6

Browse files
committed
Fix a few minor logging issues
1 parent 2beedaa commit a6b77c6

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

include/aws/logging/logging.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ enum class verbosity {
2727

2828
void log(verbosity v, char const* tag, char const* msg, va_list args);
2929

30-
[[gnu::format(printf, 2, 3)]] static inline void log_error(char const* tag, char const* msg, ...)
30+
[[gnu::format(printf, 2, 3)]] inline void log_error(char const* tag, char const* msg, ...)
3131
{
3232
va_list args;
3333
va_start(args, msg);
@@ -37,7 +37,7 @@ void log(verbosity v, char const* tag, char const* msg, va_list args);
3737
(void)msg;
3838
}
3939

40-
[[gnu::format(printf, 2, 3)]] static inline void log_info(char const* tag, char const* msg, ...)
40+
[[gnu::format(printf, 2, 3)]] inline void log_info(char const* tag, char const* msg, ...)
4141
{
4242
#if AWS_LAMBDA_LOG >= 1
4343
va_list args;
@@ -50,7 +50,7 @@ void log(verbosity v, char const* tag, char const* msg, va_list args);
5050
#endif
5151
}
5252

53-
[[gnu::format(printf, 2, 3)]] static inline void log_debug(char const* tag, char const* msg, ...)
53+
[[gnu::format(printf, 2, 3)]] inline void log_debug(char const* tag, char const* msg, ...)
5454
{
5555
#if AWS_LAMBDA_LOG >= 2
5656
va_list args;

src/logging.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ static inline char const* get_prefix(verbosity v)
3939
LAMBDA_RUNTIME_API
4040
void log(verbosity v, char const* tag, char const* msg, va_list args)
4141
{
42+
FILE* const stream = v == verbosity::error ? stderr : stdout;
4243
va_list copy;
4344
va_copy(copy, args);
4445
const int sz = vsnprintf(nullptr, 0, msg, args) + 1;
4546
if (sz < 0) {
46-
puts("error occurred during log formatting!\n");
47+
fprintf(stderr, "error occurred during log formatting!\n");
4748
va_end(copy);
4849
return;
4950
}
@@ -58,10 +59,10 @@ void log(verbosity v, char const* tag, char const* msg, va_list args)
5859
va_end(copy);
5960
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
6061
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+
fprintf(stream, "%s [%lld] %s %s\n", get_prefix(v), static_cast<long long>(ms.count()), tag, out);
6263
// stdout is not line-buffered when redirected (for example to a file or to another process) so we must flush it
6364
// manually.
64-
fflush(stdout);
65+
fflush(stream);
6566
if (out != buf.data()) {
6667
delete[] out;
6768
}

0 commit comments

Comments
 (0)