diff --git a/examples/platforms/posix/logging.c b/examples/platforms/posix/logging.c index 7ef82d376..20bd3598d 100644 --- a/examples/platforms/posix/logging.c +++ b/examples/platforms/posix/logging.c @@ -34,7 +34,10 @@ #include #include #include -#include + +#ifndef _WIN32 +#include +#endif #include @@ -48,8 +51,6 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) { - struct timeval tv; - char timeString[40]; char logString[512]; unsigned int offset; int charsWritten; @@ -57,10 +58,7 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat offset = 0; - gettimeofday(&tv, NULL); - strftime(timeString, sizeof(timeString), "%Y-%m-%d %H:%M:%S", localtime(&tv.tv_sec)); - - LOG_PRINTF("%s.%06d ", timeString, (uint32_t)tv.tv_usec); + LOG_PRINTF("[%d] ", NODE_ID); va_start(args, aFormat); charsWritten = vsnprintf(&logString[offset], sizeof(logString) - offset, aFormat, args); @@ -69,7 +67,11 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat VerifyOrExit(charsWritten >= 0, logString[offset] = 0); exit: - fprintf(stderr, "%s\r\n", logString); +#ifndef _WIN32 + syslog(LOG_CRIT, "%s", logString); +#else + printf("%s\r\n", logString); +#endif (void)aLogLevel; (void)aLogRegion; diff --git a/examples/platforms/posix/platform.c b/examples/platforms/posix/platform.c index eb181eea5..ec7e2d495 100644 --- a/examples/platforms/posix/platform.c +++ b/examples/platforms/posix/platform.c @@ -41,6 +41,11 @@ #include #include +#ifndef _WIN32 +#include +#include +#endif + #include #include #include @@ -58,6 +63,11 @@ void PlatformInit(int argc, char *argv[]) exit(EXIT_FAILURE); } +#ifndef _WIN32 + openlog(basename(argv[0]), LOG_PID, LOG_USER); + setlogmask(setlogmask(0) & LOG_UPTO(LOG_NOTICE)); +#endif + NODE_ID = (uint32_t)strtol(argv[1], &endptr, 0); if (*endptr != '\0')