mirror of
				https://github.com/Icinga/icinga2.git
				synced 2025-10-31 03:03:52 +01:00 
			
		
		
		
	As proposed in #8857, this adds a Logger subclass that writes structured log messages via journald's native protocol by calling sd_journal_sendv. The feature therefore depends on the systemd library. sd_journal_sendv is available since the early days (systemd v38), so a version check is probably superflous. We add the following fields to each record: - MESSAGE: The log message - PRIORITY (aka severity): Numeric severity as in RFC5424 section 6.2.1 - SYSLOG_FACILITY: Numeric facility as in RFC5424 section 6.2.1 - SYSLOG_IDENTIFIER: If provided, use value from configuration. Else use systemd's default behaior, which is to determine the field by using libc's program_invocation_short_name, resulting in "icinga2". - ICINGA2_FACILITY: Facility as in Log::Log(..., String facility, ...), e.g. "ApiListener" - some more fields are added automatically by systemd Fields are stored indexed, so we can do fast queries for certain field values. Example: $ journalctl -t icinga2 ICINGA2_FACILITY=ApiListener -n 5 Syslog compatiblity is ratained because good old tag, severity and facility is stored along, and systemd can forward to syslog daemons. See also https://systemd.io/JOURNAL_NATIVE_PROTOCOL/.
		
			
				
	
	
		
			22 lines
		
	
	
		
			276 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			276 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| /* Icinga 2 | (c) 2021 Icinga GmbH | GPLv2+ */
 | |
| 
 | |
| #include "base/logger.hpp"
 | |
| 
 | |
| library base;
 | |
| 
 | |
| namespace icinga
 | |
| {
 | |
| 
 | |
| class JournaldLogger : Logger
 | |
| {
 | |
| 	activation_priority -100;
 | |
| 
 | |
| 	[config] String facility {
 | |
| 		default {{{ return "LOG_USER"; }}}
 | |
| 	};
 | |
| 
 | |
| 	[config] String identifier;
 | |
| };
 | |
| 
 | |
| }
 |