Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: experimental/windows_debugger/debugger/core/debug_logger.cc

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Native Client 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 #include "debugger/core/debug_logger.h"
5 #include <sys/timeb.h>
6 #include <sys/types.h>
7 #include <time.h>
8
9 namespace debug {
10 Logger* Logger::logger_ = NULL;
11
12 void Logger::SetGlobalLogger(Logger* logger) {
13 logger_ = logger;
14 }
15
16 Logger* Logger::Get() {
17 return logger_;
18 }
19
20 void Logger::Log(const char* id,
21 const char* fmt,
22 ... ) {
23 va_list marker;
24 va_start(marker, fmt);
25 VLog(id, fmt, marker);
26 }
27
28 void Logger::VLog(const char* id,
29 const char* fmt,
30 va_list args) {
31 char tmp[32 * 1024];
32 signed int res = _vsnprintf_s(tmp, sizeof(tmp) - 1, fmt, args);
33 if (-1 != res) {
34 tmp[sizeof(tmp) - 1] = 0;
35 tmp[res] = 0;
36 StartRecord(id);
37 LogString(tmp);
38 FinishRecord();
39 }
40 }
41
42 void Logger::StartRecord(const char* id) {
43 _timeb tmb;
44 _ftime_s(&tmb);
45 time_t now = tmb.time;
46 int ms = tmb.millitm;
47 tm ts;
48 if (0 != gmtime_s(&ts, &now)) {
49 LogString(id);
50 return;
51 }
52
53 int year = ts.tm_year % 100;
54 char tmp[1000] = {0};
55 _snprintf_s(tmp,
56 sizeof(tmp) - 1,
57 _TRUNCATE,
58 "<<<<[%02d/%02d/%02d %02d:%02d:%02d.%03d] [%s] ",
59 ts.tm_mon + 1,
60 ts.tm_mday,
61 year,
62 ts.tm_hour,
63 ts.tm_min,
64 ts.tm_sec,
65 ms,
66 id);
67 tmp[sizeof(tmp) - 1] = 0;
68 LogString(tmp);
69 }
70
71 void Logger::LogString(const char* msg) {
72 printf("%s", msg);
73 }
74
75 void Logger::FinishRecord() {
76 printf(">>>>\n");
77 fflush(stdout);
78 }
79
80 TextFileLogger::TextFileLogger()
81 : file_(NULL),
82 stdout_enabled_(false) {
83 }
84
85 TextFileLogger::~TextFileLogger() {
86 if (NULL != file_) {
87 fclose(file_);
88 file_ = NULL;
89 }
90 }
91
92 bool TextFileLogger::Open(const char* file_name) {
93 file_ = NULL;
94 fopen_s(&file_, file_name, "a");
95 return (NULL != file_);
96 }
97
98 void TextFileLogger::LogString(const char* msg) {
99 if (NULL != file_)
100 fprintf(file_, "%s", msg);
101 if (stdout_enabled_)
102 Logger::LogString(msg);
103 }
104
105 void TextFileLogger::FinishRecord() {
106 if (NULL != file_) {
107 fprintf(file_, ">>>>\n");
108 fflush(file_);
109 }
110 if (stdout_enabled_)
111 Logger::FinishRecord();
112 }
113 } // namespace debug
114
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698