MCPcopy Create free account
hub / github.com/apache/arrow / StartArrowLog

Method StartArrowLog

cpp/src/arrow/util/logging.cc:147–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145#endif
146
147void ArrowLog::StartArrowLog(const std::string& app_name,
148 ArrowLogLevel severity_threshold,
149 const std::string& log_dir) {
150 severity_threshold_ = severity_threshold;
151 // In InitGoogleLogging, it simply keeps the pointer.
152 // We need to make sure the app name passed to InitGoogleLogging exist.
153 // We should avoid using static string is a dynamic lib.
154 static std::unique_ptr<std::string> app_name_;
155 app_name_.reset(new std::string(app_name));
156 log_dir_.reset(new std::string(log_dir));
157#ifdef ARROW_USE_GLOG
158 google::LogSeverity mapped_severity_threshold = GetMappedSeverity(severity_threshold_);
159 google::SetStderrLogging(mapped_severity_threshold);
160 // Enable log file if log_dir is not empty.
161 if (!log_dir.empty()) {
162 auto dir_ends_with_slash = log_dir;
163 if (log_dir[log_dir.length() - 1] != '/') {
164 dir_ends_with_slash += "/";
165 }
166 auto app_name_without_path = app_name;
167 if (app_name.empty()) {
168 app_name_without_path = "DefaultApp";
169 } else {
170 // Find the app name without the path.
171 size_t pos = app_name.rfind('/');
172 if (pos != app_name.npos && pos + 1 < app_name.length()) {
173 app_name_without_path = app_name.substr(pos + 1);
174 }
175 }
176 // If InitGoogleLogging is called but SetLogDestination is not called,
177 // the log will be output to /tmp besides stderr. If log_dir is not
178 // provided, we'd better not call InitGoogleLogging.
179 google::InitGoogleLogging(app_name_->c_str());
180 google::SetLogFilenameExtension(app_name_without_path.c_str());
181 for (int i = static_cast<int>(severity_threshold_);
182 i <= static_cast<int>(ArrowLogLevel::ARROW_FATAL); ++i) {
183 google::LogSeverity level = GetMappedSeverity(static_cast<ArrowLogLevel>(i));
184 google::SetLogDestination(level, dir_ends_with_slash.c_str());
185 }
186 }
187#endif
188}
189
190void ArrowLog::UninstallSignalAction() {
191#ifdef ARROW_USE_GLOG

Callers

nothing calls this directly

Calls 5

GetMappedSeverityFunction · 0.85
substrMethod · 0.80
resetMethod · 0.45
emptyMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected