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. |
| 9 | */ |
| 10 | |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame^] | 11 | // System independent wrapper for logging runtime information to file. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | // Note: All log messages will be written to the same trace file. |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame^] | 13 | // Note: If too many messages are written to file there will be a build up of |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | // messages. Apply filtering to avoid that. |
| 15 | #ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ |
| 16 | #define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ |
| 17 | |
| 18 | #include "common_types.h" |
| 19 | #include "typedefs.h" |
| 20 | |
henrike@webrtc.org | 4158c35 | 2011-12-19 17:28:25 +0000 | [diff] [blame] | 21 | #define WEBRTC_TRACE Trace::Add |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | class Trace |
| 25 | { |
| 26 | public: |
| 27 | |
| 28 | // Increments the reference count to the trace. |
| 29 | static void CreateTrace(); |
| 30 | // Decrements the reference count to the trace. |
| 31 | static void ReturnTrace(); |
| 32 | // Note: any instance that writes to the trace file should increment and |
| 33 | // decrement the reference count on construction and destruction |
| 34 | // respectively |
| 35 | |
| 36 | // Specifies what type of messages should be written to the trace file. The |
| 37 | // filter parameter is a bitmask where each message type is enumerated by |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame^] | 38 | // the TraceLevel enumerator. TODO(hellner): why is the |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | // TraceLevel enumerator not defined in this file? |
| 40 | static WebRtc_Word32 SetLevelFilter(const WebRtc_UWord32 filter); |
| 41 | |
| 42 | // Returns what type of messages are written to the trace file. |
| 43 | static WebRtc_Word32 LevelFilter(WebRtc_UWord32& filter); |
| 44 | |
| 45 | // Sets the file name. If addFileCounter is false the same file will be |
| 46 | // reused when it fills up. If it's true a new file with incremented name |
| 47 | // will be used. |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 48 | static WebRtc_Word32 SetTraceFile(const char* fileName, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | const bool addFileCounter = false); |
| 50 | |
| 51 | // Returns the name of the file that the trace is currently writing to. |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 52 | static WebRtc_Word32 TraceFile(char fileName[1024]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
| 54 | // Registers callback to receive trace messages. TODO (hellner) |
| 55 | // why not use OutStream instead? Why is TraceCallback not defined in this |
| 56 | // file |
| 57 | static WebRtc_Word32 SetTraceCallback(TraceCallback* callback); |
| 58 | |
| 59 | // Adds a trace message for writing to file. The message is put in a queue |
| 60 | // for writing to file whenever possible for performance reasons. I.e. there |
| 61 | // is a crash it is possible that the last, vital logs are not logged yet. |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame^] | 62 | // level is the type of message to log. If that type of messages is |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | // filtered it will not be written to file. module is an identifier for what |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame^] | 64 | // part of the code the message is coming. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | // id is an identifier that should be unique for that set of classes that |
| 66 | // are associated (e.g. all instances owned by an engine). |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame^] | 67 | // msg and the ellipsis are the same as e.g. sprintf. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | // TODO (hellner) Why is TraceModule not defined in this file? |
| 69 | static void Add(const TraceLevel level, |
| 70 | const TraceModule module, |
| 71 | const WebRtc_Word32 id, |
| 72 | const char* msg, ...); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | }; |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame^] | 74 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | } // namespace webrtc |
| 76 | #endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ |