diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-09-14 03:40:47 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-09-14 15:05:45 +0300 |
commit | cecfeed61e8bcb4b53c2ed8e1b26d8c8af38b8e3 (patch) | |
tree | 783fca9b32651efdca054ad152528b40f2566a74 /src/libcamera/log.cpp | |
parent | 98dff063f2f497434978a46f9a676307365fd878 (diff) |
libcamera: Switch to the std::chrono API
Replace the clock_gettime()-based API with durations expressed as
integers with the std::chrono API.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/libcamera/log.cpp')
-rw-r--r-- | src/libcamera/log.cpp | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp index 91f7c3ee..51f9f86b 100644 --- a/src/libcamera/log.cpp +++ b/src/libcamera/log.cpp @@ -11,7 +11,6 @@ #include <cstdlib> #include <ctime> #include <fstream> -#include <iomanip> #include <iostream> #include <list> #include <string.h> @@ -78,17 +77,6 @@ static int log_severity_to_syslog(LogSeverity severity) } } -static std::string log_timespec_to_string(const struct timespec ×tamp) -{ - std::ostringstream ossTimestamp; - ossTimestamp.fill('0'); - ossTimestamp << "[" << timestamp.tv_sec / (60 * 60) << ":" - << std::setw(2) << (timestamp.tv_sec / 60) % 60 << ":" - << std::setw(2) << timestamp.tv_sec % 60 << "." - << std::setw(9) << timestamp.tv_nsec << "]"; - return ossTimestamp.str(); -} - static const char *log_severity_name(LogSeverity severity) { static const char *const names[] = { @@ -216,10 +204,10 @@ void LogOutput::writeSyslog(const LogMessage &msg) void LogOutput::writeStream(const LogMessage &msg) { - std::string str = std::string(log_timespec_to_string(msg.timestamp()) + - log_severity_name(msg.severity()) + " " + + std::string str = "[" + utils::time_point_to_string(msg.timestamp()) + + "]" + log_severity_name(msg.severity()) + " " + msg.category().name() + " " + msg.fileInfo() + " " + - msg.msg()); + msg.msg(); stream_->write(str.c_str(), str.size()); stream_->flush(); } @@ -777,7 +765,7 @@ LogMessage::LogMessage(LogMessage &&other) void LogMessage::init(const char *fileName, unsigned int line) { /* Log the timestamp, severity and file information. */ - clock_gettime(CLOCK_MONOTONIC, ×tamp_); + timestamp_ = utils::clock::now(); std::ostringstream ossFileInfo; ossFileInfo << utils::basename(fileName) << ":" << line; |