Seregon/ShadPKG

A tool for deriving PKG packet encryption keys for ps4 written in c++

C++/47.3 KB/No license
common/logging/filter.h
ShadPKG / common / logging / filter.h
1// SPDX-FileCopyrightText: Copyright 2014 Citra Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3 
4#pragma once
5 
6#include <array>
7#include <cstddef>
8#include <string_view>
9#include "common/logging/types.h"
10 
11namespace Common::Log {
12 
13/**
14 * Returns the name of the passed log class as a C-string. Subclasses are separated by periods
15 * instead of underscores as in the enumeration.
16 */
17const char* GetLogClassName(Class log_class);
18 
19/**
20 * Returns the name of the passed log level as a C-string.
21 */
22const char* GetLevelName(Level log_level);
23 
24/**
25 * Implements a log message filter which allows different log classes to have different minimum
26 * severity levels. The filter can be changed at runtime and can be parsed from a string to allow
27 * editing via the interface or loading from a configuration file.
28 */
29class Filter {
30public:
31 /// Initializes the filter with all classes having `default_level` as the minimum level.
32 explicit Filter(Level default_level = Level::Info);
33 
34 /// Resets the filter so that all classes have `level` as the minimum displayed level.
35 void ResetAll(Level level);
36 
37 /// Sets the minimum level of `log_class` (and not of its subclasses) to `level`.
38 void SetClassLevel(Class log_class, Level level);
39 
40 /**
41 * Parses a filter string and applies it to this filter.
42 *
43 * A filter string consists of a space-separated list of filter rules, each of the format
44 * `<class>:<level>`. `<class>` is a log class name, with subclasses separated using periods.
45 * `*` is allowed as a class name and will reset all filters to the specified level. `<level>`
46 * a severity level name which will be set as the minimum logging level of the matched classes.
47 * Rules are applied left to right, with each rule overriding previous ones in the sequence.
48 *
49 * A few examples of filter rules:
50 * - `*:Info` -- Resets the level of all classes to Info.
51 * - `Service:Info` -- Sets the level of Service to Info.
52 * - `Service.FS:Trace` -- Sets the level of the Service.FS class to Trace.
53 */
54 void ParseFilterString(std::string_view filter_view);
55 
56 /// Matches class/level combination against the filter, returning true if it passed.
57 bool CheckMessage(Class log_class, Level level) const;
58 
59 /// Returns true if any logging classes are set to debug
60 bool IsDebug() const;
61 
62private:
63 std::array<Level, static_cast<std::size_t>(Class::Count)> class_levels;
64};
65 
66} // namespace Common::Log
67