toolkit/crashreporter/google-breakpad/src/common/logging.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/common/logging.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,182 @@
     1.4 +// Copyright (c) 2007, Google Inc.
     1.5 +// All rights reserved.
     1.6 +//
     1.7 +// Redistribution and use in source and binary forms, with or without
     1.8 +// modification, are permitted provided that the following conditions are
     1.9 +// met:
    1.10 +//
    1.11 +//     * Redistributions of source code must retain the above copyright
    1.12 +// notice, this list of conditions and the following disclaimer.
    1.13 +//     * Redistributions in binary form must reproduce the above
    1.14 +// copyright notice, this list of conditions and the following disclaimer
    1.15 +// in the documentation and/or other materials provided with the
    1.16 +// distribution.
    1.17 +//     * Neither the name of Google Inc. nor the names of its
    1.18 +// contributors may be used to endorse or promote products derived from
    1.19 +// this software without specific prior written permission.
    1.20 +//
    1.21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.24 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.25 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.27 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.28 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.29 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.30 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.31 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.32 +
    1.33 +// logging.h: Breakpad logging
    1.34 +//
    1.35 +// Breakpad itself uses Breakpad logging with statements of the form:
    1.36 +//   BPLOG(severity) << "message";
    1.37 +// severity may be INFO, ERROR, or other values defined in this file.
    1.38 +//
    1.39 +// BPLOG is an overridable macro so that users can customize Breakpad's
    1.40 +// logging.  Left at the default, logging messages are sent to stderr along
    1.41 +// with a timestamp and the source code location that produced a message.
    1.42 +// The streams may be changed by redefining BPLOG_*_STREAM, the logging
    1.43 +// behavior may be changed by redefining BPLOG_*, and the entire logging
    1.44 +// system may be overridden by redefining BPLOG(severity).  These
    1.45 +// redefinitions may be passed to the preprocessor as a command-line flag
    1.46 +// (-D).
    1.47 +//
    1.48 +// If an additional header is required to override Breakpad logging, it can
    1.49 +// be specified by the BP_LOGGING_INCLUDE macro.  If defined, this header
    1.50 +// will #include the header specified by that macro.
    1.51 +//
    1.52 +// If any initialization is needed before logging, it can be performed by
    1.53 +// a function called through the BPLOG_INIT macro.  Each main function of
    1.54 +// an executable program in the Breakpad processor library calls
    1.55 +// BPLOG_INIT(&argc, &argv); before any logging can be performed; define
    1.56 +// BPLOG_INIT appropriately if initialization is required.
    1.57 +//
    1.58 +// Author: Mark Mentovai
    1.59 +
    1.60 +#ifndef PROCESSOR_LOGGING_H__
    1.61 +#define PROCESSOR_LOGGING_H__
    1.62 +
    1.63 +#include <iostream>
    1.64 +#include <sstream>
    1.65 +#include <string>
    1.66 +
    1.67 +#include "common/using_std_string.h"
    1.68 +#include "google_breakpad/common/breakpad_types.h"
    1.69 +
    1.70 +#ifdef BP_LOGGING_INCLUDE
    1.71 +#include BP_LOGGING_INCLUDE
    1.72 +#endif  // BP_LOGGING_INCLUDE
    1.73 +
    1.74 +#ifndef THIRD_PARTY_BREAKPAD_GOOGLE_GLUE_LOGGING_H_
    1.75 +namespace base_logging {
    1.76 +
    1.77 +// The open-source copy of logging.h has diverged from Google's internal copy
    1.78 +// (temporarily, at least).  To support the transition to structured logging
    1.79 +// a definition for base_logging::LogMessage is needed, which is a ostream-
    1.80 +// like object for streaming arguments to construct a log message.
    1.81 +typedef std::ostream LogMessage;
    1.82 +
    1.83 +}  // namespace base_logging
    1.84 +#endif  // THIRD_PARTY_BREAKPAD_GOOGLE_GLUE_LOGGING_H_
    1.85 +
    1.86 +namespace google_breakpad {
    1.87 +
    1.88 +// These are defined in Microsoft headers.
    1.89 +#ifdef SEVERITY_ERROR
    1.90 +#undef SEVERITY_ERROR
    1.91 +#endif
    1.92 +
    1.93 +#ifdef ERROR
    1.94 +#undef ERROR
    1.95 +#endif
    1.96 +
    1.97 +class LogStream {
    1.98 + public:
    1.99 +  enum Severity {
   1.100 +    SEVERITY_INFO,
   1.101 +    SEVERITY_ERROR
   1.102 +  };
   1.103 +
   1.104 +  // Begin logging a message to the stream identified by |stream|, at the
   1.105 +  // indicated severity.  The file and line parameters should be set so as to
   1.106 +  // identify the line of source code that is producing a message.
   1.107 +  LogStream(std::ostream &stream, Severity severity,
   1.108 +            const char *file, int line);
   1.109 +
   1.110 +  // Finish logging by printing a newline and flushing the output stream.
   1.111 +  ~LogStream();
   1.112 +
   1.113 +  // Accumulate text in the str_.  It will be emitted to stream_ when
   1.114 +  // the object is destructed.
   1.115 +  template<typename T> std::ostream& operator<<(const T &t) {
   1.116 +    return str_ << t;
   1.117 +  }
   1.118 +
   1.119 + private:
   1.120 +  std::ostream &stream_;
   1.121 +  std::ostringstream str_;
   1.122 +
   1.123 +  // Disallow copy constructor and assignment operator
   1.124 +  explicit LogStream(const LogStream &that);
   1.125 +  void operator=(const LogStream &that);
   1.126 +};
   1.127 +
   1.128 +// This class is used to explicitly ignore values in the conditional logging
   1.129 +// macros.  This avoids compiler warnings like "value computed is not used"
   1.130 +// and "statement has no effect".
   1.131 +class LogMessageVoidify {
   1.132 + public:
   1.133 +  LogMessageVoidify() {}
   1.134 +
   1.135 +  // This has to be an operator with a precedence lower than << but higher
   1.136 +  // than ?:
   1.137 +  void operator&(base_logging::LogMessage &) {}
   1.138 +};
   1.139 +
   1.140 +// Returns number formatted as a hexadecimal string, such as "0x7b".
   1.141 +string HexString(uint32_t number);
   1.142 +string HexString(uint64_t number);
   1.143 +string HexString(int number);
   1.144 +
   1.145 +// Returns the error code as set in the global errno variable, and sets
   1.146 +// error_string, a required argument, to a string describing that error
   1.147 +// code.
   1.148 +int ErrnoString(string *error_string);
   1.149 +
   1.150 +}  // namespace google_breakpad
   1.151 +
   1.152 +// Useful for doing exponential backoff of error reporting
   1.153 +bool is_power_of_2(uint64_t);
   1.154 +
   1.155 +#ifndef BPLOG_INIT
   1.156 +#define BPLOG_INIT(pargc, pargv)
   1.157 +#endif  // BPLOG_INIT
   1.158 +
   1.159 +#ifndef BPLOG
   1.160 +#define BPLOG(severity) BPLOG_ ## severity
   1.161 +#endif  // BPLOG
   1.162 +
   1.163 +#ifndef BPLOG_INFO
   1.164 +#ifndef BPLOG_INFO_STREAM
   1.165 +#define BPLOG_INFO_STREAM std::clog
   1.166 +#endif  // BPLOG_INFO_STREAM
   1.167 +#define BPLOG_INFO google_breakpad::LogStream(BPLOG_INFO_STREAM, \
   1.168 +                       google_breakpad::LogStream::SEVERITY_INFO, \
   1.169 +                       __FILE__, __LINE__)
   1.170 +#endif  // BPLOG_INFO
   1.171 +
   1.172 +#ifndef BPLOG_ERROR
   1.173 +#ifndef BPLOG_ERROR_STREAM
   1.174 +#define BPLOG_ERROR_STREAM std::cerr
   1.175 +#endif  // BPLOG_ERROR_STREAM
   1.176 +#define BPLOG_ERROR google_breakpad::LogStream(BPLOG_ERROR_STREAM, \
   1.177 +                        google_breakpad::LogStream::SEVERITY_ERROR, \
   1.178 +                        __FILE__, __LINE__)
   1.179 +#endif  // BPLOG_ERROR
   1.180 +
   1.181 +#define BPLOG_IF(severity, condition) \
   1.182 +    !(condition) ? (void) 0 : \
   1.183 +                   google_breakpad::LogMessageVoidify() & BPLOG(severity)
   1.184 +
   1.185 +#endif  // PROCESSOR_LOGGING_H__

mercurial