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::detail { 12 isLogLevelEnabled(LogLevel level)13bool isLogLevelEnabled(LogLevel level) noexcept { 14 // c10 logger does not support debug and trace levels. In order to map higher 15 // levels we adjust our ordinal value. 16 int level_int = static_cast<int>(level) - 2; 17 18 if (level_int >= 0) { 19 return FLAGS_caffe2_log_level <= level_int; 20 } 21 22 // Debug and trace levels are only enabled when c10 log level is set to INFO. 23 if (FLAGS_caffe2_log_level != 0) { 24 return false; 25 } 26 27 if (level_int == -1) { 28 return debug_level() != DebugLevel::Off; 29 } 30 if (level_int == -2) { 31 return debug_level() == DebugLevel::Detail; 32 } 33 34 return false; 35 } 36 37 } // namespace c10d::detail 38