filter.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <string>
  7. #include "common/logging/log.h"
  8. namespace Log {
  9. /**
  10. * Implements a log message filter which allows different log classes to have different minimum
  11. * severity levels. The filter can be changed at runtime and can be parsed from a string to allow
  12. * editing via the interface or loading from a configuration file.
  13. */
  14. class Filter {
  15. public:
  16. /// Initializes the filter with all classes having `default_level` as the minimum level.
  17. Filter(Level default_level);
  18. /// Resets the filter so that all classes have `level` as the minimum displayed level.
  19. void ResetAll(Level level);
  20. /// Sets the minimum level of `log_class` (and not of its subclasses) to `level`.
  21. void SetClassLevel(Class log_class, Level level);
  22. /**
  23. * Parses a filter string and applies it to this filter.
  24. *
  25. * A filter string consists of a space-separated list of filter rules, each of the format
  26. * `<class>:<level>`. `<class>` is a log class name, with subclasses separated using periods.
  27. * `*` is allowed as a class name and will reset all filters to the specified level. `<level>`
  28. * a severity level name which will be set as the minimum logging level of the matched classes.
  29. * Rules are applied left to right, with each rule overriding previous ones in the sequence.
  30. *
  31. * A few examples of filter rules:
  32. * - `*:Info` -- Resets the level of all classes to Info.
  33. * - `Service:Info` -- Sets the level of Service to Info.
  34. * - `Service.FS:Trace` -- Sets the level of the Service.FS class to Trace.
  35. */
  36. void ParseFilterString(const std::string& filter_str);
  37. bool ParseFilterRule(const std::string::const_iterator start, const std::string::const_iterator end);
  38. /// Matches class/level combination against the filter, returning true if it passed.
  39. bool CheckMessage(Class log_class, Level level) const;
  40. private:
  41. std::array<Level, (size_t)Class::Count> class_levels;
  42. };
  43. }