mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	journal: prepend code location to messages at debug log levels
Debug and trace log messages are often written based on the stderr logging, where code location is always visible. journalctl does not show the code location without extra tricks, which makes user-submitted debug logs from journal more cryptic. Make journal log more similar to stderr logs by prepending the code location and log level in the log message when the log topic level is >= DEBUG.
This commit is contained in:
		
							parent
							
								
									d810057310
								
							
						
					
					
						commit
						d3980f7cef
					
				
					 1 changed files with 20 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -47,6 +47,7 @@ impl_log_logtv(void *object,
 | 
			
		|||
	      const char *fmt,
 | 
			
		||||
	      va_list args)
 | 
			
		||||
{
 | 
			
		||||
	static const char * const levels[] = { "-", "E", "W", "I", "D", "T", "*T*" };
 | 
			
		||||
	struct impl *impl = object;
 | 
			
		||||
	char line_buffer[32];
 | 
			
		||||
	char file_buffer[strlen("CODE_FILE=") + strlen(file) + 1];
 | 
			
		||||
| 
						 | 
				
			
			@ -81,9 +82,26 @@ impl_log_logtv(void *object,
 | 
			
		|||
		break;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (topic)
 | 
			
		||||
	if (spa_log_level_topic_enabled(&impl->log, topic, SPA_LOG_LEVEL_DEBUG)) {
 | 
			
		||||
		const char *lev = levels[SPA_CLAMP(level, 0u, SPA_N_ELEMENTS(levels) - 1u)];
 | 
			
		||||
		const char *tp = topic ? topic->topic : "";
 | 
			
		||||
 | 
			
		||||
		if (file && func) {
 | 
			
		||||
			const char *f = strrchr(file, '/');
 | 
			
		||||
 | 
			
		||||
			f = f ? f+1 : file;
 | 
			
		||||
			sz = spa_scnprintf(message_buffer, sizeof(message_buffer),
 | 
			
		||||
					"%s %s%s[%s:%d:%s]: ",
 | 
			
		||||
					lev, tp, topic ? " " : "",
 | 
			
		||||
					f, line, func);
 | 
			
		||||
		} else {
 | 
			
		||||
			sz = spa_scnprintf(message_buffer, sizeof(message_buffer),
 | 
			
		||||
					"%s %s%s", lev, tp, topic ? ": " : "");
 | 
			
		||||
		}
 | 
			
		||||
	} else if (topic) {
 | 
			
		||||
		sz = spa_scnprintf(message_buffer, sizeof(message_buffer),
 | 
			
		||||
				   "%s: ", topic->topic);
 | 
			
		||||
				"%s: ", topic->topic);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* we'll be using the low-level journal API, which expects us to provide
 | 
			
		||||
	 * the location explicitly. line and file are to be passed as preformatted
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue