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

Side by Side Diff: third_party/WebKit/Source/wtf/DataLog.cpp

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 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
« no previous file with comments | « third_party/WebKit/Source/wtf/DataLog.h ('k') | third_party/WebKit/Source/wtf/DateMath.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 28 matching lines...) Expand all
39 #define DATA_LOG_FILENAME "/tmp/WTFLog" 39 #define DATA_LOG_FILENAME "/tmp/WTFLog"
40 40
41 namespace WTF { 41 namespace WTF {
42 42
43 #if OS(POSIX) 43 #if OS(POSIX)
44 static pthread_once_t initializeLogFileOnceKey = PTHREAD_ONCE_INIT; 44 static pthread_once_t initializeLogFileOnceKey = PTHREAD_ONCE_INIT;
45 #endif 45 #endif
46 46
47 static FilePrintStream* file; 47 static FilePrintStream* file;
48 48
49 static void initializeLogFileOnce() 49 static void initializeLogFileOnce() {
50 {
51 #if DATA_LOG_TO_FILE 50 #if DATA_LOG_TO_FILE
52 #ifdef DATA_LOG_FILENAME 51 #ifdef DATA_LOG_FILENAME
53 const char* filename = DATA_LOG_FILENAME; 52 const char* filename = DATA_LOG_FILENAME;
54 #else 53 #else
55 const char* filename = getenv("WTF_DATA_LOG_FILENAME"); 54 const char* filename = getenv("WTF_DATA_LOG_FILENAME");
56 #endif 55 #endif
57 char actualFilename[1024]; 56 char actualFilename[1024];
58 57
59 snprintf(actualFilename, sizeof(actualFilename), "%s.%d.txt", filename, getp id()); 58 snprintf(actualFilename, sizeof(actualFilename), "%s.%d.txt", filename,
59 getpid());
60 60
61 if (filename) { 61 if (filename) {
62 file = FilePrintStream::open(actualFilename, "w").leakPtr(); 62 file = FilePrintStream::open(actualFilename, "w").leakPtr();
63 if (!file)
64 fprintf(stderr, "Warning: Could not open log file %s for writing.\n" , actualFilename);
65 }
66 #endif // DATA_LOG_TO_FILE
67 if (!file) 63 if (!file)
68 file = new FilePrintStream(stderr, FilePrintStream::Borrow); 64 fprintf(stderr, "Warning: Could not open log file %s for writing.\n",
65 actualFilename);
66 }
67 #endif // DATA_LOG_TO_FILE
68 if (!file)
69 file = new FilePrintStream(stderr, FilePrintStream::Borrow);
69 70
70 setvbuf(file->file(), 0, _IONBF, 0); // Prefer unbuffered output, so that we get a full log upon crash or deadlock. 71 setvbuf(
72 file->file(), 0, _IONBF,
73 0); // Prefer unbuffered output, so that we get a full log upon crash or deadlock.
71 } 74 }
72 75
73 static void initializeLogFile() 76 static void initializeLogFile() {
74 {
75 #if OS(POSIX) 77 #if OS(POSIX)
76 pthread_once(&initializeLogFileOnceKey, initializeLogFileOnce); 78 pthread_once(&initializeLogFileOnceKey, initializeLogFileOnce);
77 #else 79 #else
78 if (!file) 80 if (!file)
79 initializeLogFileOnce(); 81 initializeLogFileOnce();
80 #endif 82 #endif
81 } 83 }
82 84
83 FilePrintStream& dataFile() 85 FilePrintStream& dataFile() {
84 { 86 initializeLogFile();
85 initializeLogFile(); 87 return *file;
86 return *file;
87 } 88 }
88 89
89 void dataLogFV(const char* format, va_list argList) 90 void dataLogFV(const char* format, va_list argList) {
90 { 91 dataFile().vprintf(format, argList);
91 dataFile().vprintf(format, argList);
92 } 92 }
93 93
94 void dataLogF(const char* format, ...) 94 void dataLogF(const char* format, ...) {
95 { 95 va_list argList;
96 va_list argList; 96 va_start(argList, format);
97 va_start(argList, format); 97 dataLogFV(format, argList);
98 dataLogFV(format, argList); 98 va_end(argList);
99 va_end(argList);
100 } 99 }
101 100
102 void dataLogFString(const char* str) 101 void dataLogFString(const char* str) {
103 { 102 dataFile().printf("%s", str);
104 dataFile().printf("%s", str);
105 } 103 }
106 104
107 } // namespace WTF 105 } // namespace WTF
108
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/DataLog.h ('k') | third_party/WebKit/Source/wtf/DateMath.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698