niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 9 | * |
| 10 | * System independent wrapper for logging runtime information to file. |
| 11 | * Note: All log messages will be written to the same trace file. |
| 12 | * Note: If too many messages are written to file there will be a build up of |
| 13 | * messages. Apply filtering to avoid that. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | #ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ |
| 17 | #define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ |
| 18 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 19 | #include "webrtc/common_types.h" |
| 20 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
wjia@webrtc.org | 7bf7326 | 2013-02-22 00:54:58 +0000 | [diff] [blame] | 22 | #if !defined(WEBRTC_LOGGING) |
| 23 | #define WEBRTC_TRACE (true) ? (void)0 : Trace::Add |
| 24 | #else |
henrike@webrtc.org | 4158c35 | 2011-12-19 17:28:25 +0000 | [diff] [blame] | 25 | #define WEBRTC_TRACE Trace::Add |
wjia@webrtc.org | 7bf7326 | 2013-02-22 00:54:58 +0000 | [diff] [blame] | 26 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 30 | class Trace { |
| 31 | public: |
andrew@webrtc.org | c1ffd33 | 2013-03-22 17:13:23 +0000 | [diff] [blame^] | 32 | // The length of the trace text preceeding the log message. |
| 33 | static const int kBoilerplateLength; |
| 34 | // The position of the timestamp text within a trace. |
| 35 | static const int kTimestampPosition; |
| 36 | // The length of the timestamp (without "delta" field). |
| 37 | static const int kTimestampLength; |
| 38 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 39 | // Increments the reference count to the trace. |
| 40 | static void CreateTrace(); |
| 41 | // Decrements the reference count to the trace. |
| 42 | static void ReturnTrace(); |
| 43 | // Note: any instance that writes to the trace file should increment and |
| 44 | // decrement the reference count on construction and destruction, |
| 45 | // respectively. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 47 | // Specifies what type of messages should be written to the trace file. The |
| 48 | // filter parameter is a bitmask where each message type is enumerated by the |
| 49 | // TraceLevel enumerator. TODO(hellner): why is the TraceLevel enumerator not |
| 50 | // defined in this file? |
| 51 | static WebRtc_Word32 SetLevelFilter(const WebRtc_UWord32 filter); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 53 | // Returns what type of messages are written to the trace file. |
| 54 | static WebRtc_Word32 LevelFilter(WebRtc_UWord32& filter); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 56 | // Sets the file name. If add_file_counter is false the same file will be |
| 57 | // reused when it fills up. If it's true a new file with incremented name |
| 58 | // will be used. |
| 59 | static WebRtc_Word32 SetTraceFile(const char* file_name, |
| 60 | const bool add_file_counter = false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 62 | // Returns the name of the file that the trace is currently writing to. |
| 63 | static WebRtc_Word32 TraceFile(char file_name[1024]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 65 | // Registers callback to receive trace messages. |
| 66 | // TODO(hellner): Why not use OutStream instead? Why is TraceCallback not |
| 67 | // defined in this file? |
| 68 | static WebRtc_Word32 SetTraceCallback(TraceCallback* callback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 70 | // Adds a trace message for writing to file. The message is put in a queue |
| 71 | // for writing to file whenever possible for performance reasons. I.e. there |
| 72 | // is a crash it is possible that the last, vital logs are not logged yet. |
| 73 | // level is the type of message to log. If that type of messages is |
| 74 | // filtered it will not be written to file. module is an identifier for what |
| 75 | // part of the code the message is coming. |
| 76 | // id is an identifier that should be unique for that set of classes that |
| 77 | // are associated (e.g. all instances owned by an engine). |
| 78 | // msg and the ellipsis are the same as e.g. sprintf. |
| 79 | // TODO(hellner) Why is TraceModule not defined in this file? |
| 80 | static void Add(const TraceLevel level, |
| 81 | const TraceModule module, |
| 82 | const WebRtc_Word32 id, |
| 83 | const char* msg, ...); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | }; |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame] | 85 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 86 | } // namespace webrtc |
| 87 | |
| 88 | #endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ |