restructure hardlink layout
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// setupLogging ensures log directory, opens log file, and configures logrus.
|
||||
// Returns the *os.File so caller can defer its Close().
|
||||
func SetupLogging(logDir, serviceName, buildVersion string) (*os.File, error) {
|
||||
fileName := logDir + serviceName + ".log"
|
||||
f, err := os.OpenFile(fileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("open log file: %w", err)
|
||||
}
|
||||
|
||||
log.SetOutput(f)
|
||||
log.SetFormatter(&log.JSONFormatter{
|
||||
TimestampFormat: time.RFC3339,
|
||||
})
|
||||
log.SetLevel(log.InfoLevel)
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"buildVersion": buildVersion,
|
||||
}).Info("Logging initialized")
|
||||
|
||||
return f, nil
|
||||
}
|
||||
Reference in New Issue
Block a user