aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMLoggerRingBufferWriter.h
diff options
context:
space:
mode:
authorGravatar thomasvl@gmail.com <thomasvl@gmail.com@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2008-07-21 14:49:00 +0000
committerGravatar thomasvl@gmail.com <thomasvl@gmail.com@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2008-07-21 14:49:00 +0000
commit4963c8a9d57501b5ffb0fe52fbfe60cd71b3b916 (patch)
treedd70e4aba13b245427788ccdb075e04f1af0951c /Foundation/GTMLoggerRingBufferWriter.h
parentef630a18e87e03f15a2ae2b7b90623d4a0183f89 (diff)
helps if I add the files before doing the commit
Diffstat (limited to 'Foundation/GTMLoggerRingBufferWriter.h')
-rw-r--r--Foundation/GTMLoggerRingBufferWriter.h96
1 files changed, 96 insertions, 0 deletions
diff --git a/Foundation/GTMLoggerRingBufferWriter.h b/Foundation/GTMLoggerRingBufferWriter.h
new file mode 100644
index 0000000..e749a33
--- /dev/null
+++ b/Foundation/GTMLoggerRingBufferWriter.h
@@ -0,0 +1,96 @@
+//
+// GTMLoggerRingBufferWriter.h
+//
+// Copyright 2007-2008 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+//
+
+#import "GTMLogger.h"
+
+typedef struct GTMRingBufferPair GTMRingBufferPair;
+
+// GTMLoggerRingBufferWriter is a GTMLogWriter that accumulates logged Info
+// and Debug messages (when they're not compiled out in a release build)
+// into a ring buffer. If an Error or Assert message is
+// logged, all of the previously logged messages (up to the size of the
+// buffer) are then logged. At that point the buffer resets itself.
+//
+// How to use:
+//
+// * Create a logger writer that you want to use to do the ultimate writing,
+// such as to stdErr, or a log file, or an NSArray that aggregates other
+// writers.
+// id<GTMLoggerWriter> someWriter = ...
+//
+// * Make a new ring buffer with this writer, along with the buffer's
+// capacity (which must be >= 1):
+// rbw =
+// [GTMLoggerRingBufferWriter ringBufferWriterWithCapacity:32
+// writer:someWriter];
+//
+// * Set your logger's writer to be the ring buffer writer:
+// [[GTMLogger sharedLogger] setWriter:rbw];
+//
+// Note that this writer is at the end of the GTMLogger food chain, where the
+// default filter removes Info messages in Release mode (Debug messages are
+// compiled out). You can pass nil to GTMLogger's -setFilter to have it pass
+// along all the messages.
+//
+@interface GTMLoggerRingBufferWriter : NSObject <GTMLogWriter> {
+ @private
+ id<GTMLogWriter> writer_;
+ GTMRingBufferPair *buffer_;
+ int capacity_;
+ int nextIndex_; // Index of the next element of |buffer_| to fill.
+ int totalLogged_; // This > 0 and |nextIndex_| == 0 means we've wrapped.
+}
+
+// Returns an autoreleased ring buffer writer. If |capacity| is
+// non-positive, or |writer| is nil, then nil is returned.
++ (id)ringBufferWriterWithCapacity:(int)capacity
+ writer:(id<GTMLogWriter>)loggerWriter;
+
+// Designated initializer. If |capacity| is non-positive, or |writer|
+// is nil, then nil is returned. If you just use -init, nil will be returned.
+- (id)initWithCapacity:(int)capacity
+ writer:(id<GTMLogWriter>)loggerWriter;
+
+// How many messages will be logged before older messages get dropped
+// on the floor.
+- (int)capacity;
+
+// The log writer that will get the buffered log messages if/when they
+// need to be displayed.
+- (id<GTMLogWriter>)writer;
+
+// How many log messages are currently in the buffer.
+- (int)count;
+
+// How many have been dropped on the floor since creation, or the last
+// reset.
+- (int)droppedLogCount;
+
+// The total number of messages processed since creation, or the last
+// reset.
+- (int)totalLogged;
+
+// Purge the contents and reset the counters.
+- (void)reset;
+
+// Print out the contents without resetting anything.
+// Contents are automatically printed and reset when an error-level
+// message comes through.
+- (void)dumpContents;
+
+@end // GTMLoggerRingBufferWriter