OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
Sergey Ulanov
2011/05/20 00:58:19
2011
garykac
2011/05/20 22:33:16
Done.
| |
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 "remoting/client/plugin/pepper_client_logger.h" | |
6 | |
7 #include <stdarg.h> // va_list | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/message_loop.h" | |
11 #include "base/stringprintf.h" | |
12 #include "remoting/client/plugin/chromoting_instance.h" | |
13 | |
14 namespace remoting { | |
15 | |
16 PepperClientLogger::PepperClientLogger(ChromotingInstance* instance) | |
17 : instance_(instance), | |
18 message_loop_(MessageLoop::current()) { | |
19 } | |
20 | |
21 PepperClientLogger::~PepperClientLogger() { | |
22 } | |
23 | |
24 // Copied from base/logging.cc. | |
25 const char* const log_severity_names[logging::LOG_NUM_SEVERITIES] = { | |
26 "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" }; | |
27 | |
28 void PepperClientLogger::va_Log(logging::LogSeverity severity, | |
29 const char* format, va_list ap) { | |
30 DCHECK(severity >= 0 && severity <= logging::LOG_NUM_SEVERITIES); | |
31 | |
32 // Based in LOG_IS_ON macro in base/logging.h. | |
33 if (severity >= ::logging::GetMinLogLevel()) { | |
34 std::string message; | |
35 base::StringAppendV(&message, format, ap); | |
36 | |
37 // Standard logging. | |
38 logging::LogMessage(__FILE__, __LINE__, severity).stream() << message; | |
39 | |
40 // Send log message to the Chromoting instance so that it can be sent to the | |
41 // client UI. | |
42 LogToClientUI(StringPrintf("LOG(%s) %s", | |
43 log_severity_names[severity], message.c_str())); | |
44 } | |
45 | |
46 va_end(ap); | |
47 } | |
48 | |
49 void PepperClientLogger::va_VLog(int verboselevel, | |
50 const char* format, | |
51 va_list ap) { | |
52 if (VLOG_IS_ON(verboselevel)) { | |
53 std::string message; | |
54 base::StringAppendV(&message, format, ap); | |
55 | |
56 // Standard verbose logging. | |
57 VLOG(verboselevel) << message; | |
58 | |
59 // Send log message to the Chromoting instance so that it can be sent to the | |
60 // client UI. | |
61 LogToClientUI(StringPrintf("VLOG(%d) %s", verboselevel, message.c_str())); | |
62 } | |
63 } | |
64 | |
65 void PepperClientLogger::LogToClientUI(const std::string& message) { | |
66 if (message_loop_ != MessageLoop::current()) { | |
67 message_loop_->PostTask( | |
68 FROM_HERE, | |
69 NewRunnableMethod(this, &PepperClientLogger::LogToClientUI, message)); | |
70 return; | |
71 } | |
72 | |
73 instance_->GetScriptableObject()->LogDebugInfo(message); | |
74 } | |
75 | |
76 } // namespace remoting | |
OLD | NEW |