• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "bsdiff/logging.h"
6 
7 #include <ctime>
8 
LogMessage(const char * file,unsigned int line,const char * severity)9 LogMessage::LogMessage(const char* file,
10                        unsigned int line,
11                        const char* severity)
12     : LogMessage(file, line, severity, -1) {}
13 
14 
LogMessage(const char * file,unsigned int line,const char * severity,int error)15 LogMessage::LogMessage(const char* file,
16                        unsigned int line,
17                        const char* severity,
18                        int error)
19     : error_(error) {
20   std::time_t t = std::time(nullptr);
21   char timestamp[32];
22   strftime(timestamp, sizeof(timestamp), "%m-%d %H:%M:%S", std::localtime(&t));
23 
24   stream_ << severity << " " << timestamp << " " << file << ":" << line << ": ";
25 }
26 
~LogMessage()27 LogMessage::~LogMessage() {
28   if (error_ != -1) {
29     stream_ << ": " << strerror(error_);
30   }
31   std::cerr << stream_.str() << std::endl;
32 }
33