mirror of
				https://github.com/binwiederhier/ntfy.git
				synced 2025-10-31 13:02:24 +01:00 
			
		
		
		
	Add comment
This commit is contained in:
		
							parent
							
								
									9ff3bb0c87
								
							
						
					
					
						commit
						484fd91452
					
				
					 1 changed files with 9 additions and 9 deletions
				
			
		
							
								
								
									
										18
									
								
								log/event.go
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								log/event.go
									
										
									
									
									
								
							|  | @ -129,20 +129,13 @@ func (e *Event) With(contexts ...Contexter) *Event { | ||||||
| 	return e | 	return e | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // maybeLog logs the event to the defined output. The event is only logged, if | // Render returns the rendered log event as a string, or an empty string. The event is only rendered, | ||||||
| // either the global log level is >= l, or if the log level in one of the overrides matches | // if either the global log level is >= l, or if the log level in one of the overrides matches | ||||||
| // the level. | // the level. | ||||||
| // | // | ||||||
| // If no overrides are defined (default), the Contexter array is not applied unless the event | // If no overrides are defined (default), the Contexter array is not applied unless the event | ||||||
| // is actually logged. If overrides are defined, then Contexters have to be applied in any case | // is actually logged. If overrides are defined, then Contexters have to be applied in any case | ||||||
| // to determine if they match. This is super complicated, but required for efficiency. | // to determine if they match. This is super complicated, but required for efficiency. | ||||||
| func (e *Event) maybeLog(l Level, message string, v ...any) { |  | ||||||
| 	m := e.Render(l, message, v...) |  | ||||||
| 	if m != "" { |  | ||||||
| 		log.Println(m) |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func (e *Event) Render(l Level, message string, v ...any) string { | func (e *Event) Render(l Level, message string, v ...any) string { | ||||||
| 	appliedContexters := e.maybeApplyContexters() | 	appliedContexters := e.maybeApplyContexters() | ||||||
| 	if !e.shouldLog(l) { | 	if !e.shouldLog(l) { | ||||||
|  | @ -160,6 +153,13 @@ func (e *Event) Render(l Level, message string, v ...any) string { | ||||||
| 	return e.String() | 	return e.String() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // maybeLog logs the event to the defined output, or does nothing if Render returns an empty string | ||||||
|  | func (e *Event) maybeLog(l Level, message string, v ...any) { | ||||||
|  | 	if m := e.Render(l, message, v...); m != "" { | ||||||
|  | 		log.Println(m) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // Loggable returns true if the given log level is lower or equal to the current log level | // Loggable returns true if the given log level is lower or equal to the current log level | ||||||
| func (e *Event) Loggable(l Level) bool { | func (e *Event) Loggable(l Level) bool { | ||||||
| 	return e.globalLevelWithOverride() <= l | 	return e.globalLevelWithOverride() <= l | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 binwiederhier
						binwiederhier