Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 3 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
| 4 * Copyright (C) 2011 University of Szeged. All rights reserved. | 4 * Copyright (C) 2011 University of Szeged. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 #endif | 224 #endif |
| 225 } | 225 } |
| 226 | 226 |
| 227 FrameToNameScope::~FrameToNameScope() | 227 FrameToNameScope::~FrameToNameScope() |
| 228 { | 228 { |
| 229 free(m_cxaDemangled); | 229 free(m_cxaDemangled); |
| 230 } | 230 } |
| 231 | 231 |
| 232 } // anonymous namespace | 232 } // anonymous namespace |
| 233 | 233 |
| 234 static const char kScopedLoggerIndent[] = " "; | |
|
esprehn
2016/03/28 23:16:48
can we just add a method called printIndent() that
skobes
2016/03/29 18:23:40
Done.
| |
| 235 | |
| 236 ScopedLogger::ScopedLogger(bool condition, const char* format, ...) | |
|
tkent
2016/03/28 23:16:30
The code should be wrapped with |namespace WTF|.
skobes
2016/03/29 18:23:40
Done.
| |
| 237 : m_parent(condition ? current() : 0) | |
| 238 , m_multiline(false) | |
| 239 { | |
| 240 if (!condition) | |
| 241 return; | |
| 242 | |
| 243 va_list args; | |
| 244 va_start(args, format); | |
| 245 init(format, args); | |
| 246 va_end(args); | |
| 247 } | |
| 248 | |
| 249 ScopedLogger::~ScopedLogger() | |
| 250 { | |
| 251 if (current() == this) { | |
| 252 if (m_multiline) | |
| 253 indent(); | |
| 254 else | |
| 255 print(" "); | |
| 256 print(")\n"); | |
| 257 current() = m_parent; | |
| 258 } | |
| 259 } | |
| 260 | |
| 261 void ScopedLogger::init(const char* format, va_list args) | |
| 262 { | |
| 263 current() = this; | |
| 264 if (m_parent) | |
| 265 m_parent->writeNewlineIfNeeded(); | |
| 266 indent(); | |
| 267 print("( "); | |
| 268 m_printFunc(format, args); | |
| 269 } | |
| 270 | |
| 271 void ScopedLogger::writeNewlineIfNeeded() | |
| 272 { | |
| 273 if (!m_multiline) { | |
| 274 print("\n"); | |
| 275 m_multiline = true; | |
| 276 } | |
| 277 } | |
| 278 | |
| 279 void ScopedLogger::indent() | |
| 280 { | |
| 281 if (m_parent) { | |
| 282 m_parent->indent(); | |
| 283 print(kScopedLoggerIndent); | |
| 284 } | |
| 285 } | |
| 286 | |
| 287 void ScopedLogger::log(const char* format, ...) | |
| 288 { | |
| 289 if (current() != this) | |
| 290 return; | |
| 291 | |
| 292 va_list args; | |
| 293 va_start(args, format); | |
| 294 | |
| 295 writeNewlineIfNeeded(); | |
| 296 indent(); | |
| 297 print(kScopedLoggerIndent); | |
| 298 m_printFunc(format, args); | |
| 299 print("\n"); | |
| 300 | |
| 301 va_end(args); | |
| 302 } | |
| 303 | |
| 304 void ScopedLogger::print(const char* format, ...) | |
| 305 { | |
| 306 va_list args; | |
| 307 va_start(args, format); | |
| 308 m_printFunc(format, args); | |
| 309 va_end(args); | |
| 310 } | |
| 311 | |
| 312 ScopedLogger*& ScopedLogger::current() | |
| 313 { | |
| 314 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<ScopedLogger*>, ref, new Thre adSpecific<ScopedLogger*>); | |
| 315 return *ref; | |
| 316 } | |
| 317 | |
| 318 ScopedLogger::PrintFunctionPtr ScopedLogger::m_printFunc = vprintf_stderr_common ; | |
| 319 | |
| 234 void WTFPrintBacktrace(void** stack, int size) | 320 void WTFPrintBacktrace(void** stack, int size) |
| 235 { | 321 { |
| 236 for (int i = 0; i < size; ++i) { | 322 for (int i = 0; i < size; ++i) { |
| 237 FrameToNameScope frameToName(stack[i]); | 323 FrameToNameScope frameToName(stack[i]); |
| 238 const int frameNumber = i + 1; | 324 const int frameNumber = i + 1; |
| 239 if (frameToName.nullableName()) | 325 if (frameToName.nullableName()) |
| 240 printf_stderr_common("%-3d %p %s\n", frameNumber, stack[i], frameToN ame.nullableName()); | 326 printf_stderr_common("%-3d %p %s\n", frameNumber, stack[i], frameToN ame.nullableName()); |
| 241 else | 327 else |
| 242 printf_stderr_common("%-3d %p\n", frameNumber, stack[i]); | 328 printf_stderr_common("%-3d %p\n", frameNumber, stack[i]); |
| 243 } | 329 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 267 printCallSite(file, line, function); | 353 printCallSite(file, line, function); |
| 268 } | 354 } |
| 269 | 355 |
| 270 void WTFLogAlways(const char* format, ...) | 356 void WTFLogAlways(const char* format, ...) |
| 271 { | 357 { |
| 272 va_list args; | 358 va_list args; |
| 273 va_start(args, format); | 359 va_start(args, format); |
| 274 vprintf_stderr_with_trailing_newline(format, args); | 360 vprintf_stderr_with_trailing_newline(format, args); |
| 275 va_end(args); | 361 va_end(args); |
| 276 } | 362 } |
| OLD | NEW |