commit
						a40899e6be
					
				
							
								
								
									
										14
									
								
								logs/log.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								logs/log.go
									
									
									
									
									
								
							| @ -116,6 +116,7 @@ type BeeLogger struct { | |||||||
| 	enableFuncCallDepth bool | 	enableFuncCallDepth bool | ||||||
| 	loggerFuncCallDepth int | 	loggerFuncCallDepth int | ||||||
| 	asynchronous        bool | 	asynchronous        bool | ||||||
|  | 	prefix              string | ||||||
| 	msgChanLen          int64 | 	msgChanLen          int64 | ||||||
| 	msgChan             chan *logMsg | 	msgChan             chan *logMsg | ||||||
| 	signalChan          chan string | 	signalChan          chan string | ||||||
| @ -267,6 +268,9 @@ func (bl *BeeLogger) writeMsg(logLevel int, msg string, v ...interface{}) error | |||||||
| 	if len(v) > 0 { | 	if len(v) > 0 { | ||||||
| 		msg = fmt.Sprintf(msg, v...) | 		msg = fmt.Sprintf(msg, v...) | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	msg = bl.prefix + " " + msg | ||||||
|  | 
 | ||||||
| 	when := time.Now() | 	when := time.Now() | ||||||
| 	if bl.enableFuncCallDepth { | 	if bl.enableFuncCallDepth { | ||||||
| 		_, file, line, ok := runtime.Caller(bl.loggerFuncCallDepth) | 		_, file, line, ok := runtime.Caller(bl.loggerFuncCallDepth) | ||||||
| @ -325,6 +329,11 @@ func (bl *BeeLogger) EnableFuncCallDepth(b bool) { | |||||||
| 	bl.enableFuncCallDepth = b | 	bl.enableFuncCallDepth = b | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // set prefix | ||||||
|  | func (bl *BeeLogger) SetPrefix(s string) { | ||||||
|  | 	bl.prefix = s | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // start logger chan reading. | // start logger chan reading. | ||||||
| // when chan is not empty, write logs. | // when chan is not empty, write logs. | ||||||
| func (bl *BeeLogger) startLogger() { | func (bl *BeeLogger) startLogger() { | ||||||
| @ -549,6 +558,11 @@ func SetLevel(l int) { | |||||||
| 	beeLogger.SetLevel(l) | 	beeLogger.SetLevel(l) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // SetPrefix sets the prefix | ||||||
|  | func SetPrefix(s string) { | ||||||
|  | 	beeLogger.SetPrefix(s) | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // EnableFuncCallDepth enable log funcCallDepth | // EnableFuncCallDepth enable log funcCallDepth | ||||||
| func EnableFuncCallDepth(b bool) { | func EnableFuncCallDepth(b bool) { | ||||||
| 	beeLogger.enableFuncCallDepth = b | 	beeLogger.enableFuncCallDepth = b | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user