mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Merge pull request #632 from 1ace/refactor/log
Refactor preprocessor logic out of _sway_log()
This commit is contained in:
		
						commit
						93743e0d5f
					
				
					 2 changed files with 9 additions and 12 deletions
				
			
		
							
								
								
									
										15
									
								
								common/log.c
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								common/log.c
									
										
									
									
									
								
							| 
						 | 
					@ -61,11 +61,7 @@ void sway_abort(const char *format, ...) {
 | 
				
			||||||
	sway_terminate(EXIT_FAILURE);
 | 
						sway_terminate(EXIT_FAILURE);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef NDEBUG
 | 
					 | 
				
			||||||
void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) {
 | 
					void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) {
 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
void _sway_log(log_importance_t verbosity, const char* format, ...) {
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	if (verbosity <= v) {
 | 
						if (verbosity <= v) {
 | 
				
			||||||
		unsigned int c = verbosity;
 | 
							unsigned int c = verbosity;
 | 
				
			||||||
		if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) {
 | 
							if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) {
 | 
				
			||||||
| 
						 | 
					@ -76,13 +72,14 @@ void _sway_log(log_importance_t verbosity, const char* format, ...) {
 | 
				
			||||||
			fprintf(stderr, "%s", verbosity_colors[c]);
 | 
								fprintf(stderr, "%s", verbosity_colors[c]);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (filename && line) {
 | 
				
			||||||
 | 
								char *file = strdup(filename);
 | 
				
			||||||
 | 
								fprintf(stderr, "[%s:%d] ", basename(file), line);
 | 
				
			||||||
 | 
								free(file);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		va_list args;
 | 
							va_list args;
 | 
				
			||||||
		va_start(args, format);
 | 
							va_start(args, format);
 | 
				
			||||||
#ifndef NDEBUG
 | 
					 | 
				
			||||||
		char *file = strdup(filename);
 | 
					 | 
				
			||||||
		fprintf(stderr, "[%s:%d] ", basename(file), line);
 | 
					 | 
				
			||||||
		free(file);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
		vfprintf(stderr, format, args);
 | 
							vfprintf(stderr, format, args);
 | 
				
			||||||
		va_end(args);
 | 
							va_end(args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,14 +22,14 @@ bool _sway_assert(bool condition, const char* format, ...) __attribute__((format
 | 
				
			||||||
#define sway_assert(COND, FMT, ...) \
 | 
					#define sway_assert(COND, FMT, ...) \
 | 
				
			||||||
	_sway_assert(COND, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__)
 | 
						_sway_assert(COND, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef NDEBUG
 | 
					 | 
				
			||||||
void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,4,5)));
 | 
					void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,4,5)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef NDEBUG
 | 
				
			||||||
#define sway_log(VERBOSITY, FMT, ...) \
 | 
					#define sway_log(VERBOSITY, FMT, ...) \
 | 
				
			||||||
	_sway_log(__FILE__, __LINE__, VERBOSITY, FMT, ##__VA_ARGS__)
 | 
						_sway_log(__FILE__, __LINE__, VERBOSITY, FMT, ##__VA_ARGS__)
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
void _sway_log(log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,2,3)));
 | 
					 | 
				
			||||||
#define sway_log(VERBOSITY, FMT, ...) \
 | 
					#define sway_log(VERBOSITY, FMT, ...) \
 | 
				
			||||||
	_sway_log(VERBOSITY, FMT, ##__VA_ARGS__)
 | 
						_sway_log(NULL, 0, VERBOSITY, FMT, ##__VA_ARGS__)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void error_handler(int sig);
 | 
					void error_handler(int sig);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue