blob: b098865892afe51f6899449b7cda5f0c4bfe52f6 [file] [log] [blame]
Brian Silvermancb5da1f2015-12-05 22:19:58 -05001#ifndef AOS_COMMON_LOGGING_PRINTF_FORMATS_H_
2#define AOS_COMMON_LOGGING_PRINTF_FORMATS_H_
Brian Silvermana7234c62014-03-24 20:23:25 -07003
4#include "aos/common/macros.h"
5
6// This file has printf(3) formats and corresponding arguments for printing out
7// times and log messages.
8// They are all split out as macros because there are 2 things that want to
9// print using the same format: log_displayer and PrintMessage in
Brian Silvermancb5da1f2015-12-05 22:19:58 -050010// implementations.cc.
Brian Silvermana7234c62014-03-24 20:23:25 -070011
12#define AOS_TIME_FORMAT \
Brian Silvermand81d7fd2015-02-09 01:25:28 -050013 "%010" PRId32 ".%0" STRINGIFY(AOS_TIME_NSECONDS_DIGITS) PRId32 "s"
Brian Silvermana7234c62014-03-24 20:23:25 -070014#define AOS_TIME_ARGS(sec, nsec) \
15 sec, (nsec + (AOS_TIME_NSECONDS_DENOMINATOR / 2)) / \
16 AOS_TIME_NSECONDS_DENOMINATOR
17
18#define AOS_LOGGING_BASE_FORMAT \
19 "%.*s(%" PRId32 ")(%05" PRIu16 "): %-7s at " AOS_TIME_FORMAT ": "
20#define AOS_LOGGING_BASE_ARGS(name_length, name, source, sequence, level, sec, \
21 nsec) \
22 static_cast<int>(name_length), name, source, sequence, \
23 ::aos::logging::log_str(level), AOS_TIME_ARGS(sec, nsec)
24
25// These 2 define how many digits we use to print out the nseconds fields of
26// times. They have to stay matching.
Brian Silverman44f09e72014-12-28 16:27:50 -080027#define AOS_TIME_NSECONDS_DIGITS 6
Brian Silverman54a368e2015-02-14 20:05:33 -050028#define AOS_TIME_NSECONDS_DENOMINATOR 1000
Brian Silvermana7234c62014-03-24 20:23:25 -070029
Brian Silvermancb5da1f2015-12-05 22:19:58 -050030#endif // AOS_COMMON_LOGGING_PRINTF_FORMATS_H_