feat: log to console in dev

This commit is contained in:
Simon Ding
2024-07-28 11:08:17 +08:00
parent ef9e4487c6
commit 3a4e303d9d
2 changed files with 12 additions and 7 deletions

View File

@@ -25,7 +25,7 @@ COPY --from=flutter /app/build/web ./ui/build/web/
RUN CGO_ENABLED=1 go build -o polaris -ldflags="-X polaris/db.Version=$(git describe --tags --long)" ./cmd/
FROM debian:12
ENV TZ="Asia/Shanghai"
ENV TZ="Asia/Shanghai" GIN_MODE=release
WORKDIR /app
RUN apt-get update && apt-get -y install ca-certificates

View File

@@ -1,6 +1,7 @@
package log
import (
"os"
"path/filepath"
"strings"
@@ -18,12 +19,16 @@ func init() {
atom = zap.NewAtomicLevel()
atom.SetLevel(zap.DebugLevel)
w := zapcore.AddSync(&lumberjack.Logger{
Filename: filepath.Join(dataPath, "logs", "polaris.log"),
MaxSize: 50, // megabytes
MaxBackups: 3,
MaxAge: 30, // days
})
w := zapcore.Lock(os.Stdout)
if os.Getenv("GIN_MODE") == "release" {
w = zapcore.AddSync(&lumberjack.Logger{
Filename: filepath.Join(dataPath, "logs", "polaris.log"),
MaxSize: 50, // megabytes
MaxBackups: 3,
MaxAge: 30, // days
})
}
consoleEncoder := zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig())