Android-cuttlefish cvd tool
tee_logging.h
Go to the documentation of this file.
1//
2// Copyright (C) 2020 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#pragma once
17
18#include <optional>
19#include <string>
20#include <vector>
21
23
26
27namespace cuttlefish {
28
29std::string FromSeverity(android::base::LogSeverity severity);
30Result<android::base::LogSeverity> ToSeverity(const std::string& value);
31
32std::string StderrOutputGenerator(const struct tm& now, int pid, uint64_t tid,
34 const char* tag, const char* file,
35 unsigned int line, const char* message);
36
39
41
46};
47
48class TeeLogger {
49 private:
50 std::vector<SeverityTarget> destinations_;
51
52 public:
53 TeeLogger(const std::vector<SeverityTarget>& destinations,
54 const std::string& log_prefix = "");
55 ~TeeLogger() = default;
56
58 android::base::LogSeverity severity, const char* tag,
59 const char* file, unsigned int line, const char* message);
60
61 private:
62 std::string prefix_;
63};
64
66 public:
67 ScopedTeeLogger(TeeLogger tee_logger);
69
70 private:
73};
74
76 const std::string& log_prefix = "",
78 std::optional<android::base::LogSeverity> stderr_severity = std::nullopt);
79TeeLogger LogToFiles(const std::vector<std::string>& files,
80 const std::string& log_prefix = "");
82 const std::vector<std::string>& files, const std::string& log_prefix = "",
84 std::optional<android::base::LogSeverity> stderr_severity = std::nullopt);
85
86std::string StripColorCodes(const std::string& str);
87
88} // namespace cuttlefish
Definition: logging.h:452
Definition: tee_logging.h:65
~ScopedTeeLogger()
Definition: tee_logging.cpp:143
ScopedTeeLogger(TeeLogger tee_logger)
Definition: tee_logging.cpp:136
android::base::LogFunction old_logger_
Definition: tee_logging.h:71
android::base::ScopedLogSeverity scoped_severity_
Definition: tee_logging.h:72
Definition: shared_fd.h:129
Definition: tee_logging.h:48
std::vector< SeverityTarget > destinations_
Definition: tee_logging.h:50
std::string prefix_
Definition: tee_logging.h:62
TeeLogger(const std::vector< SeverityTarget > &destinations, const std::string &log_prefix="")
Definition: tee_logging.cpp:132
void operator()(android::base::LogId log_id, android::base::LogSeverity severity, const char *tag, const char *file, unsigned int line, const char *message)
Definition: tee_logging.cpp:239
log_id
Definition: log.h:138
std::function< void(LogId, LogSeverity, const char *, const char *, unsigned int, const char *)> LogFunction
Definition: logging.h:110
LogId
Definition: logging.h:97
LogSeverity
Definition: logging.h:87
Definition: alloc_utils.cpp:23
TeeLogger LogToFiles(const std::vector< std::string > &files, const std::string &log_prefix)
Definition: tee_logging.cpp:297
MetadataLevel
Definition: tee_logging.h:40
std::string StripColorCodes(const std::string &str)
Definition: tee_logging.cpp:222
std::string StderrOutputGenerator(const struct tm &now, int pid, uint64_t tid, LogSeverity severity, const char *tag, const char *file, unsigned int line, const char *message)
Definition: tee_logging.cpp:182
TeeLogger LogToStderr(const std::string &log_prefix, MetadataLevel stderr_level, std::optional< android::base::LogSeverity > stderr_severity)
Definition: tee_logging.cpp:288
Result< LogSeverity > ToSeverity(const std::string &value)
Definition: tee_logging.cpp:83
TeeLogger LogToStderrAndFiles(const std::vector< std::string > &files, const std::string &log_prefix, MetadataLevel stderr_level, std::optional< android::base::LogSeverity > stderr_severity)
Definition: tee_logging.cpp:302
LogSeverity LogFileSeverity()
Definition: tee_logging.cpp:128
LogSeverity ConsoleSeverity()
Definition: tee_logging.cpp:124
std::string FromSeverity(const android::base::LogSeverity severity)
Definition: tee_logging.cpp:63
constexpr const char * str
Definition: utils.h:180
Definition: tee_logging.h:42
android::base::LogSeverity severity
Definition: tee_logging.h:43
MetadataLevel metadata_level
Definition: tee_logging.h:45
SharedFD target
Definition: tee_logging.h:44
double now()
Definition: util.cpp:45