All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
logger.hpp
1 /*
2  * Copyright (c) 2025, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <rmm/detail/export.hpp>
20 #include <rmm/logger_macros.hpp>
21 
22 #include <rapids_logger/logger.hpp>
23 
24 namespace RMM_NAMESPACE {
25 
34 inline rapids_logger::sink_ptr default_sink()
35 {
36  auto* filename = std::getenv("RMM_DEBUG_LOG_FILE");
37  if (filename != nullptr) {
38  return std::make_shared<rapids_logger::basic_file_sink_mt>(filename, true);
39  }
40  return std::make_shared<rapids_logger::stderr_sink_mt>();
41 }
42 
48 inline std::string default_pattern() { return "[%6t][%H:%M:%S:%f][%-6l] %v"; }
49 
55 inline rapids_logger::logger& default_logger()
56 {
57  static rapids_logger::logger logger_ = [] {
58  rapids_logger::logger logger_{"RMM", {default_sink()}};
59  logger_.set_pattern(default_pattern());
60 #if RMM_LOG_ACTIVE_LEVEL <= RMM_LOG_LEVEL_DEBUG
61 #ifdef CUDA_API_PER_THREAD_DEFAULT_STREAM
62  logger_.debug("----- RMM LOG [PTDS ENABLED] -----");
63 #else
64  logger_.debug("----- RMM LOG [PTDS DISABLED] -----");
65 #endif
66 #endif
67  return logger_;
68  }();
69  return logger_;
70 }
71 
72 } // namespace RMM_NAMESPACE