1 | // Copyright (c) Meta Platforms, Inc. and its affiliates. |
---|---|
2 | // All rights reserved. |
3 | // |
4 | // This source code is licensed under the BSD-style license found in the |
5 | // LICENSE file in the root directory of this source tree. |
6 | |
7 | #include <torch/csrc/distributed/c10d/logging.h> |
8 | |
9 | #include <torch/csrc/distributed/c10d/debug.h> |
10 | |
11 | namespace c10d { |
12 | namespace detail { |
13 | |
14 | bool isLogLevelEnabled(LogLevel level) noexcept { |
15 | // c10 logger does not support debug and trace levels. In order to map higher |
16 | // levels we adjust our ordinal value. |
17 | int level_int = static_cast<int>(level) - 2; |
18 | |
19 | if (level_int >= 0) { |
20 | return FLAGS_caffe2_log_level <= level_int; |
21 | } |
22 | |
23 | // Debug and trace levels are only enabled when c10 log level is set to INFO. |
24 | if (FLAGS_caffe2_log_level != 0) { |
25 | return false; |
26 | } |
27 | |
28 | if (level_int == -1) { |
29 | return debug_level() != DebugLevel::Off; |
30 | } |
31 | if (level_int == -2) { |
32 | return debug_level() == DebugLevel::Detail; |
33 | } |
34 | |
35 | return false; |
36 | } |
37 | |
38 | } // namespace detail |
39 | } // namespace c10d |
40 |