MCPcopy Create free account
hub / github.com/Icinga/icinga2 / ~Log

Method ~Log

lib/base/logger.cpp:267–323  ·  view source on GitHub ↗

* Writes the message to the application's log. */

Source from the content-addressed store, hash-verified

265 * Writes the message to the application's log.
266 */
267Log::~Log()
268{
269 if (!m_Buffer) {
270 return;
271 }
272
273 LogEntry entry;
274 entry.Timestamp = Utility::GetTime();
275 entry.Severity = m_Severity;
276 entry.Facility = m_Facility;
277
278 {
279 auto msg (m_Buffer->str());
280 msg.erase(msg.find_last_not_of("\n") + 1u);
281
282 entry.Message = std::move(msg);
283 }
284
285 if (m_Severity >= LogWarning) {
286 ContextTrace context;
287
288 if (context.GetLength() > 0) {
289 std::ostringstream trace;
290 trace << context;
291 entry.Message += "\nContext:" + trace.str();
292 }
293 }
294
295 for (const Logger::Ptr& logger : Logger::GetLoggers()) {
296 ObjectLock llock(logger);
297
298 if (!logger->IsActive())
299 continue;
300
301 if (entry.Severity >= logger->GetMinSeverity())
302 logger->ProcessLogEntry(entry);
303
304#ifdef I2_DEBUG /* I2_DEBUG */
305 /* Always flush, don't depend on the timer. Enable this for development sprints on Linux/macOS only. Windows crashes. */
306 //logger->Flush();
307#endif /* I2_DEBUG */
308 }
309
310 if (Logger::IsConsoleLogEnabled() && entry.Severity >= Logger::GetConsoleLogSeverity()) {
311 StreamLogger::ProcessLogEntry(std::cout, entry);
312
313 /* "Console" might be a pipe/socket (systemd, daemontools, docker, ...),
314 * then cout will not flush lines automatically. */
315 std::cout << std::flush;
316 }
317
318#ifdef _WIN32
319 if (Logger::IsEarlyLoggingEnabled() && entry.Severity >= LogCritical) {
320 WindowsEventLogLogger::WriteToWindowsEventLog(entry);
321 }
322#endif /* _WIN32 */
323}

Callers

nothing calls this directly

Calls 5

IsActiveMethod · 0.80
GetMinSeverityMethod · 0.80
eraseMethod · 0.45
GetLengthMethod · 0.45
ProcessLogEntryMethod · 0.45

Tested by

no test coverage detected