blob: 29f6f92830a5f5612281215b943af7811b6150a3 [file] [log] [blame]
btolsch9d6900c2018-05-30 18:22:53 -07001// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef PLATFORM_API_LOGGING_H_
6#define PLATFORM_API_LOGGING_H_
7
btolsch2f2e7fa2019-03-29 16:48:49 -07008#include "absl/strings/string_view.h"
Jordan Baylesd08f8d22019-01-17 15:06:02 -08009
btolsch9d6900c2018-05-30 18:22:53 -070010namespace openscreen {
11namespace platform {
12
13enum class LogLevel {
Yuri Wiitalab7979032019-11-08 15:17:20 -080014 // Very detailed information, often used for evaluating performance or
15 // debugging production issues in-the-wild.
btolsch9d6900c2018-05-30 18:22:53 -070016 kVerbose = 0,
Yuri Wiitalab7979032019-11-08 15:17:20 -080017
18 // Used occasionally to note events of interest, but not for indicating any
19 // problems. This is also used for general console messaging in Open Screen's
20 // standalone executables.
21 kInfo = 1,
22
23 // Indicates a problem that may or may not lead to an operational failure.
24 kWarning = 2,
25
26 // Indicates an operational failure that may or may not cause a component to
27 // stop working.
28 kError = 3,
29
30 // Indicates a logic flaw, corruption, impossible/unanticipated situation, or
31 // operational failure so serious that Open Screen will soon call Break() to
32 // abort the current process. Examples: security/privacy risks, memory
33 // management issues, API contract violations.
34 kFatal = 4,
btolsch9d6900c2018-05-30 18:22:53 -070035};
36
Yuri Wiitalab7979032019-11-08 15:17:20 -080037// Returns true if |level| is at or above the level where the embedder will
38// record/emit log entries from the code in |file|.
39bool IsLoggingOn(LogLevel level, absl::string_view file);
btolsch9d6900c2018-05-30 18:22:53 -070040
Yuri Wiitalab7979032019-11-08 15:17:20 -080041// Record a log entry, consisting of its logging level, location and message.
42// The embedder may filter-out entries according to its own policy, but this
43// function will not be called if IsLoggingOn(level, file) returns false.
44// Whenever |level| is kFatal, Open Screen will call Break() immediately after
45// this returns.
btolsch9d6900c2018-05-30 18:22:53 -070046void LogWithLevel(LogLevel level,
Jordan Baylesd08f8d22019-01-17 15:06:02 -080047 absl::string_view file,
btolsch9d6900c2018-05-30 18:22:53 -070048 int line,
Jordan Baylesd08f8d22019-01-17 15:06:02 -080049 absl::string_view msg);
Yuri Wiitalab7979032019-11-08 15:17:20 -080050
51// Breaks into the debugger, if one is present. Otherwise, aborts the current
52// process (i.e., this function should not return). In production builds, an
53// embedder could invoke its infrastructure for performing "dumps," consisting
54// of thread stack traces and other relevant process state information, before
55// aborting the process.
btolsch9d6900c2018-05-30 18:22:53 -070056void Break();
Yuri Wiitala10dea9f2019-02-04 20:19:17 -080057
btolsch9d6900c2018-05-30 18:22:53 -070058} // namespace platform
59} // namespace openscreen
60
Yuri Wiitalab7979032019-11-08 15:17:20 -080061// Convenience macros and inline code that Open Screen code uses to invoke the
62// above embedder-implemented functions.
63//
64// TODO(crbug.com/openscreen/77): Remove this, move logging_macros.h to
65// util/logging.h, and search-and-replace all #includes throughout the code
66// base.
67#include "platform/api/internal/logging_macros.h" // NOLINT
68
btolscha21e8ed2018-08-30 15:13:48 -070069#endif // PLATFORM_API_LOGGING_H_