blob: a1358fab07ad3c7d6e4a4deff5b1d01f76ed923d [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.orgdaabfd22013-01-03 09:37:03 +00009 *
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.com470e71d2011-07-07 08:21:25 +000014 */
15
niklase@google.com470e71d2011-07-07 08:21:25 +000016#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_
17#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_
18
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000019#include "webrtc/common_types.h"
20#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
henrike@webrtc.org4158c352011-12-19 17:28:25 +000022#define WEBRTC_TRACE Trace::Add
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000025
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000026class Trace {
27 public:
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.
niklase@google.com470e71d2011-07-07 08:21:25 +000035
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000036 // 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 the
38 // TraceLevel enumerator. TODO(hellner): why is the TraceLevel enumerator not
39 // defined in this file?
40 static WebRtc_Word32 SetLevelFilter(const WebRtc_UWord32 filter);
niklase@google.com470e71d2011-07-07 08:21:25 +000041
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000042 // Returns what type of messages are written to the trace file.
43 static WebRtc_Word32 LevelFilter(WebRtc_UWord32& filter);
niklase@google.com470e71d2011-07-07 08:21:25 +000044
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000045 // Sets the file name. If add_file_counter 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.
48 static WebRtc_Word32 SetTraceFile(const char* file_name,
49 const bool add_file_counter = false);
niklase@google.com470e71d2011-07-07 08:21:25 +000050
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000051 // Returns the name of the file that the trace is currently writing to.
52 static WebRtc_Word32 TraceFile(char file_name[1024]);
niklase@google.com470e71d2011-07-07 08:21:25 +000053
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000054 // Registers callback to receive trace messages.
55 // TODO(hellner): Why not use OutStream instead? Why is TraceCallback not
56 // defined in this file?
57 static WebRtc_Word32 SetTraceCallback(TraceCallback* callback);
niklase@google.com470e71d2011-07-07 08:21:25 +000058
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000059 // 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.
62 // level is the type of message to log. If that type of messages is
63 // filtered it will not be written to file. module is an identifier for what
64 // part of the code the message is coming.
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).
67 // msg and the ellipsis are the same as e.g. sprintf.
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.com470e71d2011-07-07 08:21:25 +000073};
andrew@webrtc.org50419b02012-11-14 19:07:54 +000074
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000075} // namespace webrtc
76
77#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_