All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
logger.hpp
Go to the documentation of this file.
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 <cuml/common/logger_macros.hpp>
20 
21 #include <rapids_logger/logger.hpp>
22 
23 namespace ML {
24 
33 inline rapids_logger::sink_ptr default_sink()
34 {
35  auto* filename = std::getenv("CUML_DEBUG_LOG_FILE");
36  return (filename == nullptr)
37  ? static_cast<rapids_logger::sink_ptr>(std::make_shared<rapids_logger::stderr_sink_mt>())
38  : static_cast<rapids_logger::sink_ptr>(
39  std::make_shared<rapids_logger::basic_file_sink_mt>(filename, true));
40 }
41 
47 inline std::string default_pattern() { return "[%6t][%H:%M:%S:%f][%-6l] %v"; }
48 
54 inline rapids_logger::logger& default_logger()
55 {
56  static rapids_logger::logger logger_ = [] {
57  rapids_logger::logger logger_{"CUML", {default_sink()}};
58  logger_.set_pattern(default_pattern());
59  logger_.set_level(rapids_logger::level_enum::warn);
60  return logger_;
61  }();
62  return logger_;
63 }
64 
65 } // namespace ML
Definition: dbscan.hpp:30
rapids_logger::sink_ptr default_sink()
Returns the default sink for the global logger.
Definition: logger.hpp:33
std::string default_pattern()
Returns the default log pattern for the global logger.
Definition: logger.hpp:47
rapids_logger::logger & default_logger()
Get the default logger.
Definition: logger.hpp:54