mirror of
				https://github.com/simon987/task_tracker.git
				synced 2025-10-31 16:06:53 +00:00 
			
		
		
		
	log to file
This commit is contained in:
		
							parent
							
								
									31359b1770
								
							
						
					
					
						commit
						b007e277d4
					
				| @ -6,6 +6,7 @@ import ( | |||||||
| 	"github.com/Sirupsen/logrus" | 	"github.com/Sirupsen/logrus" | ||||||
| 	"github.com/simon987/task_tracker/config" | 	"github.com/simon987/task_tracker/config" | ||||||
| 	"github.com/valyala/fasthttp" | 	"github.com/valyala/fasthttp" | ||||||
|  | 	"os" | ||||||
| 	"time" | 	"time" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| @ -32,7 +33,14 @@ func LogRequestMiddleware(h RequestHandler) fasthttp.RequestHandler { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (api *WebAPI) SetupLogger() { | func (api *WebAPI) SetupLogger() { | ||||||
|  | 	writer, err := os.OpenFile("log.txt", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	logrus.SetFormatter(&logrus.JSONFormatter{}) | ||||||
| 	logrus.SetLevel(config.Cfg.LogLevel) | 	logrus.SetLevel(config.Cfg.LogLevel) | ||||||
|  | 	logrus.SetOutput(writer) | ||||||
| 
 | 
 | ||||||
| 	api.Database.SetupLoggerHook() | 	api.Database.SetupLoggerHook() | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user