OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 "mojo/public/cpp/environment/logging.h" | |
6 | |
7 #include <stdint.h> | |
8 | |
9 #include "mojo/public/cpp/environment/environment.h" | |
10 | |
11 namespace mojo { | |
12 namespace internal { | |
13 | |
14 namespace { | |
15 | |
16 // Gets a pointer to the filename portion of |s|. Assumes that the filename | |
17 // follows the last slash or backslash in |s|, or is |s| if no slash or | |
18 // backslash is present. | |
19 // | |
20 // E.g., a pointer to "foo.cc" is returned for the following inputs: "foo.cc", | |
21 // "./foo.cc", ".\foo.cc", "/absolute/path/to/foo.cc", | |
22 // "relative/path/to/foo.cc", "C:\absolute\path\to\foo.cc", etc. | |
23 const char* GetFilename(const char* s) { | |
24 const char* rv = s; | |
25 while (*s) { | |
26 if (*s == '/' || *s == '\\') | |
27 rv = s + 1; | |
28 s++; | |
29 } | |
30 return rv; | |
31 } | |
32 | |
33 } // namespace | |
34 | |
35 // TODO(vtl): Maybe we should preserve the full path and strip it out at a | |
36 // different level instead? | |
37 LogMessage::LogMessage(MojoLogLevel log_level, const char* file, int line) | |
38 : log_level_(log_level), file_(GetFilename(file)), line_(line) { | |
39 } | |
40 | |
41 LogMessage::~LogMessage() { | |
42 Environment::GetDefaultLogger()->LogMessage( | |
43 log_level_, file_, static_cast<uint32_t>(line_), stream_.str().c_str()); | |
44 } | |
45 | |
46 } // namespace internal | |
47 } // namespace mojo | |
OLD | NEW |