| 1 | // Copyright 2013 The Flutter 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 | #include "flutter/fml/log_settings.h" |
| 6 | |
| 7 | #include <fcntl.h> |
| 8 | |
| 9 | #include <algorithm> |
| 10 | #include <cstring> |
| 11 | #include <iostream> |
| 12 | #include <limits> |
| 13 | |
| 14 | #include "flutter/fml/build_config.h" |
| 15 | #include "flutter/fml/logging.h" |
| 16 | |
| 17 | #if defined(OS_FUCHSIA) |
| 18 | #include <lib/syslog/global.h> |
| 19 | #endif |
| 20 | |
| 21 | namespace fml { |
| 22 | namespace state { |
| 23 | |
| 24 | // Defined in log_settings_state.cc. |
| 25 | extern LogSettings g_log_settings; |
| 26 | |
| 27 | } // namespace state |
| 28 | |
| 29 | void SetLogSettings(const LogSettings& settings) { |
| 30 | // Validate the new settings as we set them. |
| 31 | state::g_log_settings.min_log_level = |
| 32 | std::min(a: LOG_FATAL, b: settings.min_log_level); |
| 33 | #if defined(OS_FUCHSIA) |
| 34 | // Syslog should accept all logs, since filtering by severity is done by fml. |
| 35 | fx_logger_t* logger = fx_log_get_logger(); |
| 36 | if (logger) { |
| 37 | fx_logger_set_min_severity(logger, |
| 38 | std::numeric_limits<fx_log_severity_t>::min()); |
| 39 | } |
| 40 | #endif |
| 41 | } |
| 42 | |
| 43 | LogSettings GetLogSettings() { |
| 44 | return state::g_log_settings; |
| 45 | } |
| 46 | |
| 47 | int GetMinLogLevel() { |
| 48 | return std::min(a: state::g_log_settings.min_log_level, b: LOG_FATAL); |
| 49 | } |
| 50 | |
| 51 | ScopedSetLogSettings::ScopedSetLogSettings(const LogSettings& settings) { |
| 52 | old_settings_ = GetLogSettings(); |
| 53 | SetLogSettings(settings); |
| 54 | } |
| 55 | |
| 56 | ScopedSetLogSettings::~ScopedSetLogSettings() { |
| 57 | SetLogSettings(old_settings_); |
| 58 | } |
| 59 | |
| 60 | } // namespace fml |
| 61 |
