1b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org/* 2b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org * 4b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org * Use of this source code is governed by a BSD-style license 5b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org * that can be found in the LICENSE file in the root of the source 6b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org * tree. An additional intellectual property rights grant can be found 7b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org * in the file PATENTS. All contributing project authors may 8b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org * be found in the AUTHORS file in the root of the source tree. 97824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org * 107824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org * System independent wrapper for logging runtime information to file. 117824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org * Note: All log messages will be written to the same trace file. 127824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org * Note: If too many messages are written to file there will be a build up of 137824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org * messages. Apply filtering to avoid that. 14b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org */ 15b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org 16b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ 17b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ 18b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org 197824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org#include "webrtc/common_types.h" 207824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org#include "webrtc/typedefs.h" 21b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org 229705beb71497537569f82b7b0e3a0175c4214ed2andrew@webrtc.orgnamespace webrtc { 239705beb71497537569f82b7b0e3a0175c4214ed2andrew@webrtc.org 249705beb71497537569f82b7b0e3a0175c4214ed2andrew@webrtc.org#if defined(WEBRTC_RESTRICT_LOGGING) 259705beb71497537569f82b7b0e3a0175c4214ed2andrew@webrtc.org// Disable all TRACE macros. The LOG macro is still functional. 269705beb71497537569f82b7b0e3a0175c4214ed2andrew@webrtc.org#define WEBRTC_TRACE true ? (void) 0 : Trace::Add 276688ec191868a3c21b3a4f84248ebebf212e2e05wjia@webrtc.org#else 28b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org#define WEBRTC_TRACE Trace::Add 296688ec191868a3c21b3a4f84248ebebf212e2e05wjia@webrtc.org#endif 30b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org 317824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.orgclass Trace { 327824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org public: 334c27c038149965cddfbe4043284af39bacfc2bcdandrew@webrtc.org // The length of the trace text preceeding the log message. 344c27c038149965cddfbe4043284af39bacfc2bcdandrew@webrtc.org static const int kBoilerplateLength; 354c27c038149965cddfbe4043284af39bacfc2bcdandrew@webrtc.org // The position of the timestamp text within a trace. 364c27c038149965cddfbe4043284af39bacfc2bcdandrew@webrtc.org static const int kTimestampPosition; 374c27c038149965cddfbe4043284af39bacfc2bcdandrew@webrtc.org // The length of the timestamp (without "delta" field). 384c27c038149965cddfbe4043284af39bacfc2bcdandrew@webrtc.org static const int kTimestampLength; 394c27c038149965cddfbe4043284af39bacfc2bcdandrew@webrtc.org 407824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // Increments the reference count to the trace. 417824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org static void CreateTrace(); 427824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // Decrements the reference count to the trace. 437824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org static void ReturnTrace(); 447824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // Note: any instance that writes to the trace file should increment and 457824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // decrement the reference count on construction and destruction, 467824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // respectively. 47b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org 487824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // Specifies what type of messages should be written to the trace file. The 497824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // filter parameter is a bitmask where each message type is enumerated by the 507824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // TraceLevel enumerator. TODO(hellner): why is the TraceLevel enumerator not 517824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // defined in this file? 5206eaa5465d57f416c14bb3a587ba4146290d6a58andrew@webrtc.org static void set_level_filter(uint32_t filter) { level_filter_ = filter; } 53b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org 547824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // Returns what type of messages are written to the trace file. 5506eaa5465d57f416c14bb3a587ba4146290d6a58andrew@webrtc.org static uint32_t level_filter() { return level_filter_; } 56b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org 577824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // Sets the file name. If add_file_counter is false the same file will be 587824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // reused when it fills up. If it's true a new file with incremented name 597824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // will be used. 60c0231afbbf1d7bac40b77da5933715dc63c88144pbos@webrtc.org static int32_t SetTraceFile(const char* file_name, 61c0231afbbf1d7bac40b77da5933715dc63c88144pbos@webrtc.org const bool add_file_counter = false); 62b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org 637824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // Returns the name of the file that the trace is currently writing to. 64c0231afbbf1d7bac40b77da5933715dc63c88144pbos@webrtc.org static int32_t TraceFile(char file_name[1024]); 65b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org 667824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // Registers callback to receive trace messages. 677824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // TODO(hellner): Why not use OutStream instead? Why is TraceCallback not 687824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // defined in this file? 69c0231afbbf1d7bac40b77da5933715dc63c88144pbos@webrtc.org static int32_t SetTraceCallback(TraceCallback* callback); 70b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org 717824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // Adds a trace message for writing to file. The message is put in a queue 727824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // for writing to file whenever possible for performance reasons. I.e. there 737824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // is a crash it is possible that the last, vital logs are not logged yet. 747824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // level is the type of message to log. If that type of messages is 757824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // filtered it will not be written to file. module is an identifier for what 767824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // part of the code the message is coming. 777824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // id is an identifier that should be unique for that set of classes that 787824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // are associated (e.g. all instances owned by an engine). 797824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // msg and the ellipsis are the same as e.g. sprintf. 807824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org // TODO(hellner) Why is TraceModule not defined in this file? 817824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org static void Add(const TraceLevel level, 827824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org const TraceModule module, 83c0231afbbf1d7bac40b77da5933715dc63c88144pbos@webrtc.org const int32_t id, 847824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org const char* msg, ...); 8506eaa5465d57f416c14bb3a587ba4146290d6a58andrew@webrtc.org 8606eaa5465d57f416c14bb3a587ba4146290d6a58andrew@webrtc.org private: 8706eaa5465d57f416c14bb3a587ba4146290d6a58andrew@webrtc.org static uint32_t level_filter_; 88b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org}; 89d898c019c4e09c73bc7354da9f1b54004f3e4b7eandrew@webrtc.org 907824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org} // namespace webrtc 917824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org 927824ff1bacbd3be5af8088fc7d81c33fe0647f36phoglund@webrtc.org#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ 93