Logging errors not going to file #2589
              
                
                  
                  
                    Answered
                  
                  by
                    aldas
                  
              
          
                  
                    
                      SKFrozenCloud
                    
                  
                
                  asked this question in
                Q&A
              
            -
| Hi, I'm logging to a file and the requests are going to the file but not any errors I log through the echo logger. echoLogFile, err := os.OpenFile("logs/server-"+time.Now().Format("2006-01-02")+".log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0660)
if err != nil {
    panic(fmt.Sprintf("Can not open log file: %v", err))
}
defer echoLogFile.Close()
e := echo.New()
defaultEchoLoggerConfig := middleware.DefaultLoggerConfig
defaultEchoLoggerConfig.Output = echoLogFile
e.Use(middleware.LoggerWithConfig(defaultEchoLoggerConfig))
c.Logger().Error(errors.New("error log showing in console but not in file")) | 
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            aldas
          
      
      
        Feb 7, 2024 
      
    
    Replies: 1 comment 1 reply
-
| This is because  | 
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            
      Answer selected by
        SKFrozenCloud
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
This is because
c.Logger()and logger middleware are two different things and are not related. If you wantc.Logger()to output to file you need to sete.Logger =with proper "file"logging logger instance.