blob: 1fd29336d7b6edb046888df79c46c3379d86c5bc [file] [log] [blame]
kloveless@chromium.org1d82e822013-04-10 21:32:321// Copyright (c) 2013 The Chromium 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 "gpu/command_buffer/service/logger.h"
6
7#include "base/command_line.h"
8#include "base/logging.h"
avi@chromium.orgf4390962013-06-11 07:29:229#include "base/strings/string_number_conversions.h"
kloveless@chromium.org1d82e822013-04-10 21:32:3210#include "gpu/command_buffer/common/debug_marker_manager.h"
11#include "gpu/command_buffer/service/gpu_switches.h"
12
13namespace gpu {
14namespace gles2 {
15
16Logger::Logger(const DebugMarkerManager* debug_marker_manager)
17 : debug_marker_manager_(debug_marker_manager),
18 log_message_count_(0),
19 log_synthesized_gl_errors_(true) {
20 Logger* this_temp = this;
gman@chromium.org40de8512013-05-28 20:15:0021 this_in_hex_ = std::string("GroupMarkerNotSet(crbug.com/242999)!:") +
22 base::HexEncode(&this_temp, sizeof(this_temp));
kloveless@chromium.org1d82e822013-04-10 21:32:3223}
24
25Logger::~Logger() {}
26
27void Logger::LogMessage(
28 const char* filename, int line, const std::string& msg) {
29 if (log_message_count_ < kMaxLogMessages ||
30 CommandLine::ForCurrentProcess()->HasSwitch(
31 switches::kDisableGLErrorLimit)) {
gman@chromium.org40de8512013-05-28 20:15:0032 std::string prefixed_msg(std::string("[") + GetLogPrefix() + "]" + msg);
kloveless@chromium.org1d82e822013-04-10 21:32:3233 ++log_message_count_;
34 // LOG this unless logging is turned off as any chromium code that
35 // generates these errors probably has a bug.
36 if (log_synthesized_gl_errors_) {
37 ::logging::LogMessage(
gman@chromium.org40de8512013-05-28 20:15:0038 filename, line, ::logging::LOG_ERROR).stream() << prefixed_msg;
kloveless@chromium.org1d82e822013-04-10 21:32:3239 }
40 if (!msg_callback_.is_null()) {
gman@chromium.org40de8512013-05-28 20:15:0041 msg_callback_.Run(0, prefixed_msg);
kloveless@chromium.org1d82e822013-04-10 21:32:3242 }
43 } else {
44 if (log_message_count_ == kMaxLogMessages) {
45 ++log_message_count_;
46 LOG(ERROR)
47 << "Too many GL errors, not reporting any more for this context."
48 << " use --disable-gl-error-limit to see all errors.";
49 }
50 }
51}
52
53const std::string& Logger::GetLogPrefix() const {
54 const std::string& prefix(debug_marker_manager_->GetMarker());
55 return prefix.empty() ? this_in_hex_ : prefix;
56}
57
58void Logger::SetMsgCallback(const MsgCallback& callback) {
59 msg_callback_ = callback;
60}
61
62} // namespace gles2
63} // namespace gpu
64