toolkit/crashreporter/google-breakpad/src/common/mac/GTMLogger.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 //
michael@0 2 // GTMLogger.h
michael@0 3 //
michael@0 4 // Copyright 2007-2008 Google Inc.
michael@0 5 //
michael@0 6 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
michael@0 7 // use this file except in compliance with the License. You may obtain a copy
michael@0 8 // of the License at
michael@0 9 //
michael@0 10 // http://www.apache.org/licenses/LICENSE-2.0
michael@0 11 //
michael@0 12 // Unless required by applicable law or agreed to in writing, software
michael@0 13 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
michael@0 14 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
michael@0 15 // License for the specific language governing permissions and limitations under
michael@0 16 // the License.
michael@0 17 //
michael@0 18
michael@0 19 // Key Abstractions
michael@0 20 // ----------------
michael@0 21 //
michael@0 22 // This file declares multiple classes and protocols that are used by the
michael@0 23 // GTMLogger logging system. The 4 main abstractions used in this file are the
michael@0 24 // following:
michael@0 25 //
michael@0 26 // * logger (GTMLogger) - The main logging class that users interact with. It
michael@0 27 // has methods for logging at different levels and uses a log writer, a log
michael@0 28 // formatter, and a log filter to get the job done.
michael@0 29 //
michael@0 30 // * log writer (GTMLogWriter) - Writes a given string to some log file, where
michael@0 31 // a "log file" can be a physical file on disk, a POST over HTTP to some URL,
michael@0 32 // or even some in-memory structure (e.g., a ring buffer).
michael@0 33 //
michael@0 34 // * log formatter (GTMLogFormatter) - Given a format string and arguments as
michael@0 35 // a va_list, returns a single formatted NSString. A "formatted string" could
michael@0 36 // be a string with the date prepended, a string with values in a CSV format,
michael@0 37 // or even a string of XML.
michael@0 38 //
michael@0 39 // * log filter (GTMLogFilter) - Given a formatted log message as an NSString
michael@0 40 // and the level at which the message is to be logged, this class will decide
michael@0 41 // whether the given message should be logged or not. This is a flexible way
michael@0 42 // to filter out messages logged at a certain level, messages that contain
michael@0 43 // certain text, or filter nothing out at all. This gives the caller the
michael@0 44 // flexibility to dynamically enable debug logging in Release builds.
michael@0 45 //
michael@0 46 // This file also declares some classes to handle the common log writer, log
michael@0 47 // formatter, and log filter cases. Callers can also create their own writers,
michael@0 48 // formatters, and filters and they can even build them on top of the ones
michael@0 49 // declared here. Keep in mind that your custom writer/formatter/filter may be
michael@0 50 // called from multiple threads, so it must be thread-safe.
michael@0 51
michael@0 52 #import <Foundation/Foundation.h>
michael@0 53 #import "GTMDefines.h"
michael@0 54
michael@0 55 // Predeclaration of used protocols that are declared later in this file.
michael@0 56 @protocol GTMLogWriter, GTMLogFormatter, GTMLogFilter;
michael@0 57
michael@0 58 // GTMLogger
michael@0 59 //
michael@0 60 // GTMLogger is the primary user-facing class for an object-oriented logging
michael@0 61 // system. It is built on the concept of log formatters (GTMLogFormatter), log
michael@0 62 // writers (GTMLogWriter), and log filters (GTMLogFilter). When a message is
michael@0 63 // sent to a GTMLogger to log a message, the message is formatted using the log
michael@0 64 // formatter, then the log filter is consulted to see if the message should be
michael@0 65 // logged, and if so, the message is sent to the log writer to be written out.
michael@0 66 //
michael@0 67 // GTMLogger is intended to be a flexible and thread-safe logging solution. Its
michael@0 68 // flexibility comes from the fact that GTMLogger instances can be customized
michael@0 69 // with user defined formatters, filters, and writers. And these writers,
michael@0 70 // filters, and formatters can be combined, stacked, and customized in arbitrary
michael@0 71 // ways to suit the needs at hand. For example, multiple writers can be used at
michael@0 72 // the same time, and a GTMLogger instance can even be used as another
michael@0 73 // GTMLogger's writer. This allows for arbitrarily deep logging trees.
michael@0 74 //
michael@0 75 // A standard GTMLogger uses a writer that sends messages to standard out, a
michael@0 76 // formatter that smacks a timestamp and a few other bits of interesting
michael@0 77 // information on the message, and a filter that filters out debug messages from
michael@0 78 // release builds. Using the standard log settings, a log message will look like
michael@0 79 // the following:
michael@0 80 //
michael@0 81 // 2007-12-30 10:29:24.177 myapp[4588/0xa07d0f60] [lvl=1] foo=<Foo: 0x123>
michael@0 82 //
michael@0 83 // The output contains the date and time of the log message, the name of the
michael@0 84 // process followed by its process ID/thread ID, the log level at which the
michael@0 85 // message was logged (in the previous example the level was 1:
michael@0 86 // kGTMLoggerLevelDebug), and finally, the user-specified log message itself (in
michael@0 87 // this case, the log message was @"foo=%@", foo).
michael@0 88 //
michael@0 89 // Multiple instances of GTMLogger can be created, each configured their own
michael@0 90 // way. Though GTMLogger is not a singleton (in the GoF sense), it does provide
michael@0 91 // access to a shared (i.e., globally accessible) GTMLogger instance. This makes
michael@0 92 // it convenient for all code in a process to use the same GTMLogger instance.
michael@0 93 // The shared GTMLogger instance can also be configured in an arbitrary, and
michael@0 94 // these configuration changes will affect all code that logs through the shared
michael@0 95 // instance.
michael@0 96
michael@0 97 //
michael@0 98 // Log Levels
michael@0 99 // ----------
michael@0 100 // GTMLogger has 3 different log levels: Debug, Info, and Error. GTMLogger
michael@0 101 // doesn't take any special action based on the log level; it simply forwards
michael@0 102 // this information on to formatters, filters, and writers, each of which may
michael@0 103 // optionally take action based on the level. Since log level filtering is
michael@0 104 // performed at runtime, log messages are typically not filtered out at compile
michael@0 105 // time. The exception to this rule is that calls to the GTMLoggerDebug() macro
michael@0 106 // *ARE* filtered out of non-DEBUG builds. This is to be backwards compatible
michael@0 107 // with behavior that many developers are currently used to. Note that this
michael@0 108 // means that GTMLoggerDebug(@"hi") will be compiled out of Release builds, but
michael@0 109 // [[GTMLogger sharedLogger] logDebug:@"hi"] will NOT be compiled out.
michael@0 110 //
michael@0 111 // Standard loggers are created with the GTMLogLevelFilter log filter, which
michael@0 112 // filters out certain log messages based on log level, and some other settings.
michael@0 113 //
michael@0 114 // In addition to the -logDebug:, -logInfo:, and -logError: methods defined on
michael@0 115 // GTMLogger itself, there are also C macros that make usage of the shared
michael@0 116 // GTMLogger instance very convenient. These macros are:
michael@0 117 //
michael@0 118 // GTMLoggerDebug(...)
michael@0 119 // GTMLoggerInfo(...)
michael@0 120 // GTMLoggerError(...)
michael@0 121 //
michael@0 122 // Again, a notable feature of these macros is that GTMLogDebug() calls *will be
michael@0 123 // compiled out of non-DEBUG builds*.
michael@0 124 //
michael@0 125 // Standard Loggers
michael@0 126 // ----------------
michael@0 127 // GTMLogger has the concept of "standard loggers". A standard logger is simply
michael@0 128 // a logger that is pre-configured with some standard/common writer, formatter,
michael@0 129 // and filter combination. Standard loggers are created using the creation
michael@0 130 // methods beginning with "standard". The alternative to a standard logger is a
michael@0 131 // regular logger, which will send messages to stdout, with no special
michael@0 132 // formatting, and no filtering.
michael@0 133 //
michael@0 134 // How do I use GTMLogger?
michael@0 135 // ----------------------
michael@0 136 // The typical way you will want to use GTMLogger is to simply use the
michael@0 137 // GTMLogger*() macros for logging from code. That way we can easily make
michael@0 138 // changes to the GTMLogger class and simply update the macros accordingly. Only
michael@0 139 // your application startup code (perhaps, somewhere in main()) should use the
michael@0 140 // GTMLogger class directly in order to configure the shared logger, which all
michael@0 141 // of the code using the macros will be using. Again, this is just the typical
michael@0 142 // situation.
michael@0 143 //
michael@0 144 // To be complete, there are cases where you may want to use GTMLogger directly,
michael@0 145 // or even create separate GTMLogger instances for some reason. That's fine,
michael@0 146 // too.
michael@0 147 //
michael@0 148 // Examples
michael@0 149 // --------
michael@0 150 // The following show some common GTMLogger use cases.
michael@0 151 //
michael@0 152 // 1. You want to log something as simply as possible. Also, this call will only
michael@0 153 // appear in debug builds. In non-DEBUG builds it will be completely removed.
michael@0 154 //
michael@0 155 // GTMLoggerDebug(@"foo = %@", foo);
michael@0 156 //
michael@0 157 // 2. The previous example is similar to the following. The major difference is
michael@0 158 // that the previous call (example 1) will be compiled out of Release builds
michael@0 159 // but this statement will not be compiled out.
michael@0 160 //
michael@0 161 // [[GTMLogger sharedLogger] logDebug:@"foo = %@", foo];
michael@0 162 //
michael@0 163 // 3. Send all logging output from the shared logger to a file. We do this by
michael@0 164 // creating an NSFileHandle for writing associated with a file, and setting
michael@0 165 // that file handle as the logger's writer.
michael@0 166 //
michael@0 167 // NSFileHandle *f = [NSFileHandle fileHandleForWritingAtPath:@"/tmp/f.log"
michael@0 168 // create:YES];
michael@0 169 // [[GTMLogger sharedLogger] setWriter:f];
michael@0 170 // GTMLoggerError(@"hi"); // This will be sent to /tmp/f.log
michael@0 171 //
michael@0 172 // 4. Create a new GTMLogger that will log to a file. This example differs from
michael@0 173 // the previous one because here we create a new GTMLogger that is different
michael@0 174 // from the shared logger.
michael@0 175 //
michael@0 176 // GTMLogger *logger = [GTMLogger standardLoggerWithPath:@"/tmp/temp.log"];
michael@0 177 // [logger logInfo:@"hi temp log file"];
michael@0 178 //
michael@0 179 // 5. Create a logger that writes to stdout and does NOT do any formatting to
michael@0 180 // the log message. This might be useful, for example, when writing a help
michael@0 181 // screen for a command-line tool to standard output.
michael@0 182 //
michael@0 183 // GTMLogger *logger = [GTMLogger logger];
michael@0 184 // [logger logInfo:@"%@ version 0.1 usage", progName];
michael@0 185 //
michael@0 186 // 6. Send log output to stdout AND to a log file. The trick here is that
michael@0 187 // NSArrays function as composite log writers, which means when an array is
michael@0 188 // set as the log writer, it forwards all logging messages to all of its
michael@0 189 // contained GTMLogWriters.
michael@0 190 //
michael@0 191 // // Create array of GTMLogWriters
michael@0 192 // NSArray *writers = [NSArray arrayWithObjects:
michael@0 193 // [NSFileHandle fileHandleForWritingAtPath:@"/tmp/f.log" create:YES],
michael@0 194 // [NSFileHandle fileHandleWithStandardOutput], nil];
michael@0 195 //
michael@0 196 // GTMLogger *logger = [GTMLogger standardLogger];
michael@0 197 // [logger setWriter:writers];
michael@0 198 // [logger logInfo:@"hi"]; // Output goes to stdout and /tmp/f.log
michael@0 199 //
michael@0 200 // For futher details on log writers, formatters, and filters, see the
michael@0 201 // documentation below.
michael@0 202 //
michael@0 203 // NOTE: GTMLogger is application level logging. By default it does nothing
michael@0 204 // with _GTMDevLog/_GTMDevAssert (see GTMDefines.h). An application can choose
michael@0 205 // to bridge _GTMDevLog/_GTMDevAssert to GTMLogger by providing macro
michael@0 206 // definitions in its prefix header (see GTMDefines.h for how one would do
michael@0 207 // that).
michael@0 208 //
michael@0 209 @interface GTMLogger : NSObject {
michael@0 210 @private
michael@0 211 id<GTMLogWriter> writer_;
michael@0 212 id<GTMLogFormatter> formatter_;
michael@0 213 id<GTMLogFilter> filter_;
michael@0 214 }
michael@0 215
michael@0 216 //
michael@0 217 // Accessors for the shared logger instance
michael@0 218 //
michael@0 219
michael@0 220 // Returns a shared/global standard GTMLogger instance. Callers should typically
michael@0 221 // use this method to get a GTMLogger instance, unless they explicitly want
michael@0 222 // their own instance to configure for their own needs. This is the only method
michael@0 223 // that returns a shared instance; all the rest return new GTMLogger instances.
michael@0 224 + (id)sharedLogger;
michael@0 225
michael@0 226 // Sets the shared logger instance to |logger|. Future calls to +sharedLogger
michael@0 227 // will return |logger| instead.
michael@0 228 + (void)setSharedLogger:(GTMLogger *)logger;
michael@0 229
michael@0 230 //
michael@0 231 // Creation methods
michael@0 232 //
michael@0 233
michael@0 234 // Returns a new autoreleased GTMLogger instance that will log to stdout, using
michael@0 235 // the GTMLogStandardFormatter, and the GTMLogLevelFilter filter.
michael@0 236 + (id)standardLogger;
michael@0 237
michael@0 238 // Same as +standardLogger, but logs to stderr.
michael@0 239 + (id)standardLoggerWithStderr;
michael@0 240
michael@0 241 // Same as +standardLogger but levels >= kGTMLoggerLevelError are routed to
michael@0 242 // stderr, everything else goes to stdout.
michael@0 243 + (id)standardLoggerWithStdoutAndStderr;
michael@0 244
michael@0 245 // Returns a new standard GTMLogger instance with a log writer that will
michael@0 246 // write to the file at |path|, and will use the GTMLogStandardFormatter and
michael@0 247 // GTMLogLevelFilter classes. If |path| does not exist, it will be created.
michael@0 248 + (id)standardLoggerWithPath:(NSString *)path;
michael@0 249
michael@0 250 // Returns an autoreleased GTMLogger instance that will use the specified
michael@0 251 // |writer|, |formatter|, and |filter|.
michael@0 252 + (id)loggerWithWriter:(id<GTMLogWriter>)writer
michael@0 253 formatter:(id<GTMLogFormatter>)formatter
michael@0 254 filter:(id<GTMLogFilter>)filter;
michael@0 255
michael@0 256 // Returns an autoreleased GTMLogger instance that logs to stdout, with the
michael@0 257 // basic formatter, and no filter. The returned logger differs from the logger
michael@0 258 // returned by +standardLogger because this one does not do any filtering and
michael@0 259 // does not do any special log formatting; this is the difference between a
michael@0 260 // "regular" logger and a "standard" logger.
michael@0 261 + (id)logger;
michael@0 262
michael@0 263 // Designated initializer. This method returns a GTMLogger initialized with the
michael@0 264 // specified |writer|, |formatter|, and |filter|. See the setter methods below
michael@0 265 // for what values will be used if nil is passed for a parameter.
michael@0 266 - (id)initWithWriter:(id<GTMLogWriter>)writer
michael@0 267 formatter:(id<GTMLogFormatter>)formatter
michael@0 268 filter:(id<GTMLogFilter>)filter;
michael@0 269
michael@0 270 //
michael@0 271 // Logging methods
michael@0 272 //
michael@0 273
michael@0 274 // Logs a message at the debug level (kGTMLoggerLevelDebug).
michael@0 275 - (void)logDebug:(NSString *)fmt, ... NS_FORMAT_FUNCTION(1, 2);
michael@0 276 // Logs a message at the info level (kGTMLoggerLevelInfo).
michael@0 277 - (void)logInfo:(NSString *)fmt, ... NS_FORMAT_FUNCTION(1, 2);
michael@0 278 // Logs a message at the error level (kGTMLoggerLevelError).
michael@0 279 - (void)logError:(NSString *)fmt, ... NS_FORMAT_FUNCTION(1, 2);
michael@0 280 // Logs a message at the assert level (kGTMLoggerLevelAssert).
michael@0 281 - (void)logAssert:(NSString *)fmt, ... NS_FORMAT_FUNCTION(1, 2);
michael@0 282
michael@0 283
michael@0 284 //
michael@0 285 // Accessors
michael@0 286 //
michael@0 287
michael@0 288 // Accessor methods for the log writer. If the log writer is set to nil,
michael@0 289 // [NSFileHandle fileHandleWithStandardOutput] is used.
michael@0 290 - (id<GTMLogWriter>)writer;
michael@0 291 - (void)setWriter:(id<GTMLogWriter>)writer;
michael@0 292
michael@0 293 // Accessor methods for the log formatter. If the log formatter is set to nil,
michael@0 294 // GTMLogBasicFormatter is used. This formatter will format log messages in a
michael@0 295 // plain printf style.
michael@0 296 - (id<GTMLogFormatter>)formatter;
michael@0 297 - (void)setFormatter:(id<GTMLogFormatter>)formatter;
michael@0 298
michael@0 299 // Accessor methods for the log filter. If the log filter is set to nil,
michael@0 300 // GTMLogNoFilter is used, which allows all log messages through.
michael@0 301 - (id<GTMLogFilter>)filter;
michael@0 302 - (void)setFilter:(id<GTMLogFilter>)filter;
michael@0 303
michael@0 304 @end // GTMLogger
michael@0 305
michael@0 306
michael@0 307 // Helper functions that are used by the convenience GTMLogger*() macros that
michael@0 308 // enable the logging of function names.
michael@0 309 @interface GTMLogger (GTMLoggerMacroHelpers)
michael@0 310 - (void)logFuncDebug:(const char *)func msg:(NSString *)fmt, ...
michael@0 311 NS_FORMAT_FUNCTION(2, 3);
michael@0 312 - (void)logFuncInfo:(const char *)func msg:(NSString *)fmt, ...
michael@0 313 NS_FORMAT_FUNCTION(2, 3);
michael@0 314 - (void)logFuncError:(const char *)func msg:(NSString *)fmt, ...
michael@0 315 NS_FORMAT_FUNCTION(2, 3);
michael@0 316 - (void)logFuncAssert:(const char *)func msg:(NSString *)fmt, ...
michael@0 317 NS_FORMAT_FUNCTION(2, 3);
michael@0 318 @end // GTMLoggerMacroHelpers
michael@0 319
michael@0 320
michael@0 321 // The convenience macros are only defined if they haven't already been defined.
michael@0 322 #ifndef GTMLoggerInfo
michael@0 323
michael@0 324 // Convenience macros that log to the shared GTMLogger instance. These macros
michael@0 325 // are how users should typically log to GTMLogger. Notice that GTMLoggerDebug()
michael@0 326 // calls will be compiled out of non-Debug builds.
michael@0 327 #define GTMLoggerDebug(...) \
michael@0 328 [[GTMLogger sharedLogger] logFuncDebug:__func__ msg:__VA_ARGS__]
michael@0 329 #define GTMLoggerInfo(...) \
michael@0 330 [[GTMLogger sharedLogger] logFuncInfo:__func__ msg:__VA_ARGS__]
michael@0 331 #define GTMLoggerError(...) \
michael@0 332 [[GTMLogger sharedLogger] logFuncError:__func__ msg:__VA_ARGS__]
michael@0 333 #define GTMLoggerAssert(...) \
michael@0 334 [[GTMLogger sharedLogger] logFuncAssert:__func__ msg:__VA_ARGS__]
michael@0 335
michael@0 336 // If we're not in a debug build, remove the GTMLoggerDebug statements. This
michael@0 337 // makes calls to GTMLoggerDebug "compile out" of Release builds
michael@0 338 #ifndef DEBUG
michael@0 339 #undef GTMLoggerDebug
michael@0 340 #define GTMLoggerDebug(...) do {} while(0)
michael@0 341 #endif
michael@0 342
michael@0 343 #endif // !defined(GTMLoggerInfo)
michael@0 344
michael@0 345 // Log levels.
michael@0 346 typedef enum {
michael@0 347 kGTMLoggerLevelUnknown,
michael@0 348 kGTMLoggerLevelDebug,
michael@0 349 kGTMLoggerLevelInfo,
michael@0 350 kGTMLoggerLevelError,
michael@0 351 kGTMLoggerLevelAssert,
michael@0 352 } GTMLoggerLevel;
michael@0 353
michael@0 354
michael@0 355 //
michael@0 356 // Log Writers
michael@0 357 //
michael@0 358
michael@0 359 // Protocol to be implemented by a GTMLogWriter instance.
michael@0 360 @protocol GTMLogWriter <NSObject>
michael@0 361 // Writes the given log message to where the log writer is configured to write.
michael@0 362 - (void)logMessage:(NSString *)msg level:(GTMLoggerLevel)level;
michael@0 363 @end // GTMLogWriter
michael@0 364
michael@0 365
michael@0 366 // Simple category on NSFileHandle that makes NSFileHandles valid log writers.
michael@0 367 // This is convenient because something like, say, +fileHandleWithStandardError
michael@0 368 // now becomes a valid log writer. Log messages are written to the file handle
michael@0 369 // with a newline appended.
michael@0 370 @interface NSFileHandle (GTMFileHandleLogWriter) <GTMLogWriter>
michael@0 371 // Opens the file at |path| in append mode, and creates the file with |mode|
michael@0 372 // if it didn't previously exist.
michael@0 373 + (id)fileHandleForLoggingAtPath:(NSString *)path mode:(mode_t)mode;
michael@0 374 @end // NSFileHandle
michael@0 375
michael@0 376
michael@0 377 // This category makes NSArray a GTMLogWriter that can be composed of other
michael@0 378 // GTMLogWriters. This is the classic Composite GoF design pattern. When the
michael@0 379 // GTMLogWriter -logMessage:level: message is sent to the array, the array
michael@0 380 // forwards the message to all of its elements that implement the GTMLogWriter
michael@0 381 // protocol.
michael@0 382 //
michael@0 383 // This is useful in situations where you would like to send log output to
michael@0 384 // multiple log writers at the same time. Simply create an NSArray of the log
michael@0 385 // writers you wish to use, then set the array as the "writer" for your
michael@0 386 // GTMLogger instance.
michael@0 387 @interface NSArray (GTMArrayCompositeLogWriter) <GTMLogWriter>
michael@0 388 @end // GTMArrayCompositeLogWriter
michael@0 389
michael@0 390
michael@0 391 // This category adapts the GTMLogger interface so that it can be used as a log
michael@0 392 // writer; it's an "adapter" in the GoF Adapter pattern sense.
michael@0 393 //
michael@0 394 // This is useful when you want to configure a logger to log to a specific
michael@0 395 // writer with a specific formatter and/or filter. But you want to also compose
michael@0 396 // that with a different log writer that may have its own formatter and/or
michael@0 397 // filter.
michael@0 398 @interface GTMLogger (GTMLoggerLogWriter) <GTMLogWriter>
michael@0 399 @end // GTMLoggerLogWriter
michael@0 400
michael@0 401
michael@0 402 //
michael@0 403 // Log Formatters
michael@0 404 //
michael@0 405
michael@0 406 // Protocol to be implemented by a GTMLogFormatter instance.
michael@0 407 @protocol GTMLogFormatter <NSObject>
michael@0 408 // Returns a formatted string using the format specified in |fmt| and the va
michael@0 409 // args specified in |args|.
michael@0 410 - (NSString *)stringForFunc:(NSString *)func
michael@0 411 withFormat:(NSString *)fmt
michael@0 412 valist:(va_list)args
michael@0 413 level:(GTMLoggerLevel)level NS_FORMAT_FUNCTION(2, 0);
michael@0 414 @end // GTMLogFormatter
michael@0 415
michael@0 416
michael@0 417 // A basic log formatter that formats a string the same way that NSLog (or
michael@0 418 // printf) would. It does not do anything fancy, nor does it add any data of its
michael@0 419 // own.
michael@0 420 @interface GTMLogBasicFormatter : NSObject <GTMLogFormatter>
michael@0 421
michael@0 422 // Helper method for prettying C99 __func__ and GCC __PRETTY_FUNCTION__
michael@0 423 - (NSString *)prettyNameForFunc:(NSString *)func;
michael@0 424
michael@0 425 @end // GTMLogBasicFormatter
michael@0 426
michael@0 427
michael@0 428 // A log formatter that formats the log string like the basic formatter, but
michael@0 429 // also prepends a timestamp and some basic process info to the message, as
michael@0 430 // shown in the following sample output.
michael@0 431 // 2007-12-30 10:29:24.177 myapp[4588/0xa07d0f60] [lvl=1] log mesage here
michael@0 432 @interface GTMLogStandardFormatter : GTMLogBasicFormatter {
michael@0 433 @private
michael@0 434 NSDateFormatter *dateFormatter_; // yyyy-MM-dd HH:mm:ss.SSS
michael@0 435 NSString *pname_;
michael@0 436 pid_t pid_;
michael@0 437 }
michael@0 438 @end // GTMLogStandardFormatter
michael@0 439
michael@0 440
michael@0 441 //
michael@0 442 // Log Filters
michael@0 443 //
michael@0 444
michael@0 445 // Protocol to be imlemented by a GTMLogFilter instance.
michael@0 446 @protocol GTMLogFilter <NSObject>
michael@0 447 // Returns YES if |msg| at |level| should be filtered out; NO otherwise.
michael@0 448 - (BOOL)filterAllowsMessage:(NSString *)msg level:(GTMLoggerLevel)level;
michael@0 449 @end // GTMLogFilter
michael@0 450
michael@0 451
michael@0 452 // A log filter that filters messages at the kGTMLoggerLevelDebug level out of
michael@0 453 // non-debug builds. Messages at the kGTMLoggerLevelInfo level are also filtered
michael@0 454 // out of non-debug builds unless GTMVerboseLogging is set in the environment or
michael@0 455 // the processes's defaults. Messages at the kGTMLoggerLevelError level are
michael@0 456 // never filtered.
michael@0 457 @interface GTMLogLevelFilter : NSObject <GTMLogFilter>
michael@0 458 @end // GTMLogLevelFilter
michael@0 459
michael@0 460 // A simple log filter that does NOT filter anything out;
michael@0 461 // -filterAllowsMessage:level will always return YES. This can be a convenient
michael@0 462 // way to enable debug-level logging in release builds (if you so desire).
michael@0 463 @interface GTMLogNoFilter : NSObject <GTMLogFilter>
michael@0 464 @end // GTMLogNoFilter
michael@0 465
michael@0 466
michael@0 467 // Base class for custom level filters. Not for direct use, use the minimum
michael@0 468 // or maximum level subclasses below.
michael@0 469 @interface GTMLogAllowedLevelFilter : NSObject <GTMLogFilter> {
michael@0 470 @private
michael@0 471 NSIndexSet *allowedLevels_;
michael@0 472 }
michael@0 473 @end
michael@0 474
michael@0 475 // A log filter that allows you to set a minimum log level. Messages below this
michael@0 476 // level will be filtered.
michael@0 477 @interface GTMLogMininumLevelFilter : GTMLogAllowedLevelFilter
michael@0 478
michael@0 479 // Designated initializer, logs at levels < |level| will be filtered.
michael@0 480 - (id)initWithMinimumLevel:(GTMLoggerLevel)level;
michael@0 481
michael@0 482 @end
michael@0 483
michael@0 484 // A log filter that allows you to set a maximum log level. Messages whose level
michael@0 485 // exceeds this level will be filtered. This is really only useful if you have
michael@0 486 // a composite GTMLogger that is sending the other messages elsewhere.
michael@0 487 @interface GTMLogMaximumLevelFilter : GTMLogAllowedLevelFilter
michael@0 488
michael@0 489 // Designated initializer, logs at levels > |level| will be filtered.
michael@0 490 - (id)initWithMaximumLevel:(GTMLoggerLevel)level;
michael@0 491
michael@0 492 @end
michael@0 493
michael@0 494
michael@0 495 // For subclasses only
michael@0 496 @interface GTMLogger (PrivateMethods)
michael@0 497
michael@0 498 - (void)logInternalFunc:(const char *)func
michael@0 499 format:(NSString *)fmt
michael@0 500 valist:(va_list)args
michael@0 501 level:(GTMLoggerLevel)level NS_FORMAT_FUNCTION(2, 0);
michael@0 502
michael@0 503 @end
michael@0 504

mercurial