Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 56ab441

Browse files
authored
Add a new class for logging. (#36)
1 parent a3c7ece commit 56ab441

File tree

4 files changed

+98
-9
lines changed

4 files changed

+98
-9
lines changed

web_transport/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ source_set("owt_web_transport_impl") {
2323
"//third_party/boringssl",
2424
]
2525
sources = [
26+
"sdk/api/owt/quic/logging.h",
2627
"sdk/api/owt/quic/version.h",
2728
"sdk/api/owt/quic/web_transport_client_interface.h",
2829
"sdk/api/owt/quic/web_transport_definitions.h",
@@ -37,6 +38,7 @@ source_set("owt_web_transport_impl") {
3738
"sdk/impl/utilities.cc",
3839
"sdk/impl/utilities.h",
3940
"sdk/impl/version.cc",
41+
"sdk/impl/logging.cc",
4042
"sdk/impl/web_transport_factory_impl.cc",
4143
"sdk/impl/web_transport_factory_impl.h",
4244
"sdk/impl/web_transport_http3_client.cc",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef OWT_WEB_TRANSPORT_LOGGING_H_
8+
#define OWT_WEB_TRANSPORT_LOGGING_H_
9+
10+
#include "export.h"
11+
12+
namespace owt {
13+
namespace quic {
14+
15+
enum class LoggingSeverity : int {
16+
/// This level is for data which we do not want to appear in the normal debug
17+
/// log, but should appear in diagnostic logs.
18+
kVerbose,
19+
/// Chatty level used in debugging for all sorts of things, the default in
20+
/// debug builds.
21+
kInfo,
22+
/// Something that may warrant investigation.
23+
kWarning,
24+
/// Something that should not have occurred.
25+
kError,
26+
/// Fatal errors.
27+
kFatal
28+
};
29+
30+
class OWT_EXPORT Logging {
31+
public:
32+
/// Set logging severity. All logging messages with higher severity will be
33+
/// logged.
34+
static void Severity(LoggingSeverity severity);
35+
/// Get current logging severity.
36+
static LoggingSeverity Severity();
37+
// Init logging module.
38+
static void InitLogging();
39+
40+
private:
41+
static LoggingSeverity min_severity_;
42+
};
43+
44+
} // namespace quic
45+
} // namespace owt
46+
47+
#endif

web_transport/sdk/impl/logging.cc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "owt/quic/logging.h"
8+
#include <unordered_map>
9+
#include "base/logging.h"
10+
11+
namespace owt {
12+
namespace quic {
13+
14+
#ifdef _DEBUG
15+
LoggingSeverity Logging::min_severity_ = LoggingSeverity::kInfo;
16+
#else
17+
LoggingSeverity Logging::min_severity_ = LoggingSeverity::kError;
18+
#endif
19+
20+
// Due to a defect in C++ 11, static cast to int instead of enum value.
21+
// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2148
22+
static std::unordered_map<int, logging::LogSeverity> logging_severity_map = {
23+
{static_cast<int>(LoggingSeverity::kVerbose), logging::LOG_VERBOSE},
24+
{static_cast<int>(LoggingSeverity::kInfo), logging::LOG_INFO},
25+
{static_cast<int>(LoggingSeverity::kWarning), logging::LOG_WARNING},
26+
{static_cast<int>(LoggingSeverity::kError), logging::LOG_ERROR},
27+
{static_cast<int>(LoggingSeverity::kFatal), logging::LOG_FATAL}};
28+
29+
void Logging::Severity(LoggingSeverity severity) {
30+
min_severity_ = severity;
31+
LOG(ERROR) << "Setting logging level to "
32+
<< logging_severity_map[static_cast<int>(severity)];
33+
logging::SetMinLogLevel(logging_severity_map[static_cast<int>(severity)]);
34+
}
35+
36+
LoggingSeverity Logging::Severity() {
37+
return min_severity_;
38+
}
39+
40+
void Logging::InitLogging() {
41+
logging::LoggingSettings settings;
42+
settings.logging_dest = logging::LOG_TO_STDERR;
43+
logging::InitLogging(settings);
44+
}
45+
46+
} // namespace quic
47+
} // namespace owt

web_transport/sdk/impl/web_transport_factory_impl.cc

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include "owt/quic/logging.h"
78
#include "impl/web_transport_factory_impl.h"
89
#include "base/at_exit.h"
910
#include "base/bind.h"
@@ -135,15 +136,7 @@ void WebTransportFactoryImpl::Init() {
135136
base::CommandLine::Init(0, nullptr);
136137
base::CommandLine* command_line(base::CommandLine::ForCurrentProcess());
137138
command_line->AppendSwitch("--quic_default_to_bbr");
138-
// Logging settings for Chromium.
139-
#ifdef _DEBUG
140-
logging::SetMinLogLevel(logging::LOG_VERBOSE);
141-
#else
142-
logging::SetMinLogLevel(logging::LOG_WARNING);
143-
#endif
144-
logging::LoggingSettings settings;
145-
settings.logging_dest = logging::LOG_TO_STDERR;
146-
InitLogging(settings);
139+
Logging::InitLogging();
147140
}
148141

149142
} // namespace quic

0 commit comments

Comments
 (0)