1 /* 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 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 11 // System independant wrapper for logging runtime information to file. 12 // Note: All log messages will be written to the same trace file. 13 // Note: If to many messages are written to file there will be a build up of 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 21 #ifdef WEBRTC_NO_TRACE 22 #define WEBRTC_TRACE 23 #else 24 // Ideally we would use __VA_ARGS__ but it's not supported by all compilers 25 // such as VS2003 (it's supported in VS2005). TODO (hellner) why 26 // would this be better than current implementation (not convinced)? 27 #define WEBRTC_TRACE Trace::Add 28 #endif 29 30 namespace webrtc { 31 class Trace 32 { 33 public: 34 35 // Increments the reference count to the trace. 36 static void CreateTrace(); 37 // Decrements the reference count to the trace. 38 static void ReturnTrace(); 39 // Note: any instance that writes to the trace file should increment and 40 // decrement the reference count on construction and destruction 41 // respectively 42 43 // Specifies what type of messages should be written to the trace file. The 44 // filter parameter is a bitmask where each message type is enumerated by 45 // the TraceLevel enumerator. TODO (hellner) why is the 46 // TraceLevel enumerator not defined in this file? 47 static WebRtc_Word32 SetLevelFilter(const WebRtc_UWord32 filter); 48 49 // Returns what type of messages are written to the trace file. 50 static WebRtc_Word32 LevelFilter(WebRtc_UWord32& filter); 51 52 // Sets the file name. If addFileCounter is false the same file will be 53 // reused when it fills up. If it's true a new file with incremented name 54 // will be used. 55 static WebRtc_Word32 SetTraceFile(const WebRtc_Word8* fileName, 56 const bool addFileCounter = false); 57 58 // Returns the name of the file that the trace is currently writing to. 59 static WebRtc_Word32 TraceFile(WebRtc_Word8 fileName[1024]); 60 61 // Registers callback to receive trace messages. TODO (hellner) 62 // why not use OutStream instead? Why is TraceCallback not defined in this 63 // file 64 static WebRtc_Word32 SetTraceCallback(TraceCallback* callback); 65 66 // Adds a trace message for writing to file. The message is put in a queue 67 // for writing to file whenever possible for performance reasons. I.e. there 68 // is a crash it is possible that the last, vital logs are not logged yet. 69 // level is the the type of message to log. If that type of messages is 70 // filtered it will not be written to file. module is an identifier for what 71 // part of the code the message is comming. 72 // id is an identifier that should be unique for that set of classes that 73 // are associated (e.g. all instances owned by an engine). 74 // msg and the elipsis are the same as e.g. sprintf. 75 // TODO (hellner) Why is TraceModule not defined in this file? 76 static void Add(const TraceLevel level, 77 const TraceModule module, 78 const WebRtc_Word32 id, 79 const char* msg, ...); 80 81 }; 82 } // namespace webrtc 83 #endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ 84