mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	log: make timestamps configurable
This commit is contained in:
		
							parent
							
								
									53f93c2bde
								
							
						
					
					
						commit
						f92775719a
					
				
					 3 changed files with 10 additions and 2 deletions
				
			
		| 
						 | 
					@ -167,6 +167,8 @@ static inline void spa_log_trace_fp (struct spa_log *l, const char *format, ...)
 | 
				
			||||||
#define SPA_KEY_LOG_COLORS		"log.colors"		/**< enable colors in the logger */
 | 
					#define SPA_KEY_LOG_COLORS		"log.colors"		/**< enable colors in the logger */
 | 
				
			||||||
#define SPA_KEY_LOG_FILE		"log.file"		/**< log to the specified file instead of
 | 
					#define SPA_KEY_LOG_FILE		"log.file"		/**< log to the specified file instead of
 | 
				
			||||||
								  *  stderr. */
 | 
													  *  stderr. */
 | 
				
			||||||
 | 
					#define SPA_KEY_LOG_TIMESTAMP		"log.timestamp"		/**< log timestamps */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}  /* extern "C" */
 | 
					}  /* extern "C" */
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,6 +56,7 @@ struct impl {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	unsigned int have_source:1;
 | 
						unsigned int have_source:1;
 | 
				
			||||||
	unsigned int colors:1;
 | 
						unsigned int colors:1;
 | 
				
			||||||
 | 
						unsigned int timestamp:1;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					@ -90,18 +91,20 @@ impl_log_logv(void *object,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	vsnprintf(text, sizeof(text), fmt, args);
 | 
						vsnprintf(text, sizeof(text), fmt, args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (level >= SPA_LOG_LEVEL_DEBUG) {
 | 
						if (impl->timestamp) {
 | 
				
			||||||
		struct timespec now;
 | 
							struct timespec now;
 | 
				
			||||||
		clock_gettime(CLOCK_MONOTONIC_RAW, &now);
 | 
							clock_gettime(CLOCK_MONOTONIC_RAW, &now);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		size = snprintf(location, sizeof(location), "%s[%s][%09lu.%06lu][%s:%i %s()] %s%s\n",
 | 
							size = snprintf(location, sizeof(location), "%s[%s][%09lu.%06lu][%s:%i %s()] %s%s\n",
 | 
				
			||||||
			prefix, levels[level], now.tv_sec & 0x1FFFFFFF, now.tv_nsec / 1000,
 | 
								prefix, levels[level], now.tv_sec & 0x1FFFFFFF, now.tv_nsec / 1000,
 | 
				
			||||||
			strrchr(file, '/') + 1, line, func, text, suffix);
 | 
								strrchr(file, '/') + 1, line, func, text, suffix);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		size = snprintf(location, sizeof(location), "%s[%s][%s:%i %s()] %s%s\n",
 | 
							size = snprintf(location, sizeof(location), "%s[%s][%s:%i %s()] %s%s\n",
 | 
				
			||||||
			prefix, levels[level], strrchr(file, '/') + 1, line, func, text, suffix);
 | 
								prefix, levels[level], strrchr(file, '/') + 1, line, func, text, suffix);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (SPA_UNLIKELY(do_trace)) {
 | 
						if (SPA_UNLIKELY(do_trace)) {
 | 
				
			||||||
		uint32_t index;
 | 
							uint32_t index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -259,6 +262,8 @@ impl_init(const struct spa_handle_factory *factory,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (info) {
 | 
						if (info) {
 | 
				
			||||||
 | 
							if ((str = spa_dict_lookup(info, SPA_KEY_LOG_TIMESTAMP)) != NULL)
 | 
				
			||||||
 | 
								this->timestamp = (strcmp(str, "true") == 0 || atoi(str) == 1);
 | 
				
			||||||
		if ((str = spa_dict_lookup(info, SPA_KEY_LOG_COLORS)) != NULL)
 | 
							if ((str = spa_dict_lookup(info, SPA_KEY_LOG_COLORS)) != NULL)
 | 
				
			||||||
			this->colors = (strcmp(str, "true") == 0 || atoi(str) == 1);
 | 
								this->colors = (strcmp(str, "true") == 0 || atoi(str) == 1);
 | 
				
			||||||
		if ((str = spa_dict_lookup(info, SPA_KEY_LOG_LEVEL)) != NULL)
 | 
							if ((str = spa_dict_lookup(info, SPA_KEY_LOG_LEVEL)) != NULL)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -351,7 +351,7 @@ SPA_EXPORT
 | 
				
			||||||
void pw_init(int *argc, char **argv[])
 | 
					void pw_init(int *argc, char **argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const char *str;
 | 
						const char *str;
 | 
				
			||||||
	struct spa_dict_item items[3];
 | 
						struct spa_dict_item items[4];
 | 
				
			||||||
	uint32_t n_items;
 | 
						uint32_t n_items;
 | 
				
			||||||
	struct spa_dict info;
 | 
						struct spa_dict info;
 | 
				
			||||||
	struct support *support = &global_support;
 | 
						struct support *support = &global_support;
 | 
				
			||||||
| 
						 | 
					@ -379,6 +379,7 @@ void pw_init(int *argc, char **argv[])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	n_items = 0;
 | 
						n_items = 0;
 | 
				
			||||||
	items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_COLORS, "1");
 | 
						items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_COLORS, "1");
 | 
				
			||||||
 | 
						items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_TIMESTAMP, "1");
 | 
				
			||||||
	snprintf(level, sizeof(level), "%d", pw_log_level);
 | 
						snprintf(level, sizeof(level), "%d", pw_log_level);
 | 
				
			||||||
	items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_LEVEL, level);
 | 
						items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_LEVEL, level);
 | 
				
			||||||
	if ((str = getenv("PIPEWIRE_LOG")) != NULL)
 | 
						if ((str = getenv("PIPEWIRE_LOG")) != NULL)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue