From cecfeed61e8bcb4b53c2ed8e1b26d8c8af38b8e3 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 14 Sep 2019 03:40:47 +0300 Subject: libcamera: Switch to the std::chrono API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the clock_gettime()-based API with durations expressed as integers with the std::chrono API. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/log.cpp | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'src/libcamera/log.cpp') 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 #include #include -#include #include #include #include @@ -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; -- cgit v1.2.1