blob: 44ea658bdf28b639f348c52554723564e08a60f9 [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
andrew@webrtc.orgf1a48172013-11-07 23:47:26 +000022namespace webrtc {
23
24#if defined(WEBRTC_RESTRICT_LOGGING)
25// Disable all TRACE macros. The LOG macro is still functional.
26#define WEBRTC_TRACE true ? (void) 0 : Trace::Add
wjia@webrtc.org7bf73262013-02-22 00:54:58 +000027#else
henrike@webrtc.org4158c352011-12-19 17:28:25 +000028#define WEBRTC_TRACE Trace::Add
wjia@webrtc.org7bf73262013-02-22 00:54:58 +000029#endif
niklase@google.com470e71d2011-07-07 08:21:25 +000030
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000031class Trace {
32 public:
andrew@webrtc.orgc1ffd332013-03-22 17:13:23 +000033 // The length of the trace text preceeding the log message.
34 static const int kBoilerplateLength;
35 // The position of the timestamp text within a trace.
36 static const int kTimestampPosition;
37 // The length of the timestamp (without "delta" field).
38 static const int kTimestampLength;
39
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000040 // Increments the reference count to the trace.
41 static void CreateTrace();
42 // Decrements the reference count to the trace.
43 static void ReturnTrace();
44 // Note: any instance that writes to the trace file should increment and
45 // decrement the reference count on construction and destruction,
46 // respectively.
niklase@google.com470e71d2011-07-07 08:21:25 +000047
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000048 // Specifies what type of messages should be written to the trace file. The
49 // filter parameter is a bitmask where each message type is enumerated by the
50 // TraceLevel enumerator. TODO(hellner): why is the TraceLevel enumerator not
51 // defined in this file?
andrew@webrtc.org90805182013-09-05 16:40:43 +000052 static void set_level_filter(uint32_t filter) { level_filter_ = filter; }
niklase@google.com470e71d2011-07-07 08:21:25 +000053
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000054 // Returns what type of messages are written to the trace file.
andrew@webrtc.org90805182013-09-05 16:40:43 +000055 static uint32_t level_filter() { return level_filter_; }
niklase@google.com470e71d2011-07-07 08:21:25 +000056
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000057 // Sets the file name. If add_file_counter is false the same file will be
58 // reused when it fills up. If it's true a new file with incremented name
59 // will be used.
pbos@webrtc.org046deb92013-04-09 09:06:11 +000060 static int32_t SetTraceFile(const char* file_name,
61 const bool add_file_counter = false);
niklase@google.com470e71d2011-07-07 08:21:25 +000062
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000063 // Returns the name of the file that the trace is currently writing to.
pbos@webrtc.org046deb92013-04-09 09:06:11 +000064 static int32_t TraceFile(char file_name[1024]);
niklase@google.com470e71d2011-07-07 08:21:25 +000065
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000066 // Registers callback to receive trace messages.
67 // TODO(hellner): Why not use OutStream instead? Why is TraceCallback not
68 // defined in this file?
pbos@webrtc.org046deb92013-04-09 09:06:11 +000069 static int32_t SetTraceCallback(TraceCallback* callback);
niklase@google.com470e71d2011-07-07 08:21:25 +000070
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000071 // Adds a trace message for writing to file. The message is put in a queue
72 // for writing to file whenever possible for performance reasons. I.e. there
73 // is a crash it is possible that the last, vital logs are not logged yet.
74 // level is the type of message to log. If that type of messages is
75 // filtered it will not be written to file. module is an identifier for what
76 // part of the code the message is coming.
77 // id is an identifier that should be unique for that set of classes that
78 // are associated (e.g. all instances owned by an engine).
79 // msg and the ellipsis are the same as e.g. sprintf.
80 // TODO(hellner) Why is TraceModule not defined in this file?
81 static void Add(const TraceLevel level,
82 const TraceModule module,
pbos@webrtc.org046deb92013-04-09 09:06:11 +000083 const int32_t id,
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000084 const char* msg, ...);
andrew@webrtc.org90805182013-09-05 16:40:43 +000085
86 private:
87 static uint32_t level_filter_;
niklase@google.com470e71d2011-07-07 08:21:25 +000088};
andrew@webrtc.org50419b02012-11-14 19:07:54 +000089
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000090} // namespace webrtc
91
92#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_