2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef BenchLogger_DEFINED
9 #define BenchLogger_DEFINED
18 * Class that allows logging to a file while simultaneously logging to stdout/stderr.
25 * Not virtual, since this class is not intended to be subclassed.
30 * Specify a file to write progress logs to. Unless this is called with a valid file path,
31 * BenchLogger will only write to stdout/stderr.
33 bool SetLogFile(const char file[]);
36 * Log an error to stderr, taking a C style string as input.
38 void logError(const char msg[]) { this->nativeLogError(msg); }
41 * Log an error to stderr, taking an SkString as input.
43 void logError(const SkString& str) { this->nativeLogError(str.c_str()); }
46 * Log the progress of the bench tool to both stdout and the log file specified by SetLogFile,
47 * if any, taking a C style string as input.
49 void logProgress(const char msg[]) {
50 this->nativeLogProgress(msg);
51 this->fileWrite(msg, strlen(msg));
55 * Log the progress of the bench tool to both stdout and the log file specified by SetLogFile,
56 * if any, taking an SkString as input.
58 void logProgress(const SkString& str) {
59 this->nativeLogProgress(str.c_str());
60 this->fileWrite(str.c_str(), str.size());
64 #ifdef SK_BUILD_FOR_ANDROID
65 void nativeLogError(const char msg[]) { SkDebugf("%s", msg); }
67 void nativeLogError(const char msg[]) { fprintf(stderr, "%s", msg); }
69 void nativeLogProgress(const char msg[]) { SkDebugf("%s", msg); }
71 void fileWrite(const char msg[], size_t size);
73 SkFILEWStream* fFileStream;
76 #endif // BenchLogger_DEFINED