Skip to content

Commit bd9d1db

Browse files
committed
debug: add log
1 parent 7753380 commit bd9d1db

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

server/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use the official Go image with version 1.24
2-
FROM golang:1.24.0-alpine AS builder
2+
FROM golang:1.24.0 AS builder
33

44
# Set the working directory inside the container
55
WORKDIR /app
@@ -19,7 +19,7 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
1919
go clean -cache -modcache
2020

2121
# Create a non-root user and set permissions
22-
RUN adduser -D -h /home/appuser appuser && \
22+
RUN useradd -m appuser && \
2323
mkdir -p logs && \
2424
chown -R appuser:appuser config/ && \
2525
chown -R appuser:appuser logs/ && \

server/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ require (
5353
github.com/go-openapi/swag/yamlutils v0.24.0 // indirect
5454
github.com/go-playground/locales v0.14.1 // indirect
5555
github.com/go-playground/universal-translator v0.18.1 // indirect
56-
github.com/go-sql-driver/mysql v1.8.1 // indirect
56+
github.com/go-sql-driver/mysql v1.9.3 // indirect
5757
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
5858
github.com/goccy/go-json v0.10.5 // indirect
5959
github.com/goccy/go-yaml v1.18.0 // indirect

server/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHO
7171
github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
7272
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
7373
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
74+
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
75+
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
7476
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
7577
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
7678
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=

server/log/logger.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ func getLogLevel() zapcore.Level {
3636

3737
func getEncoder() zapcore.Encoder {
3838
encoderConfig := zap.NewProductionEncoderConfig()
39+
location, err := time.LoadLocation("Asia/Singapore")
40+
if err != nil {
41+
// 如果加载时区失败,回退到本地时区
42+
location = time.Local
43+
}
3944
encoderConfig.EncodeTime = func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
40-
enc.AppendString(t.Local().Format("2006-01-02 15:04:05"))
45+
enc.AppendString(t.In(location).Format("2006-01-02 15:04:05"))
4146
}
4247
encoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
4348
return zapcore.NewConsoleEncoder(encoderConfig)

server/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ func main() {
4040
go grpc.Init(sigCh)
4141
go http.Init(sigCh)
4242
// listen terminage signal
43-
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
43+
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1, syscall.SIGUSR2)
4444
sig := <-sigCh // Block until signal is received
4545
debug.PrintStack()
4646
log.Logger.Infof("Received signal: %v, shutting down", sig)
47+
<<<<<<< Updated upstream
48+
select {}
49+
=======
50+
>>>>>>> Stashed changes
4751
}

server/repository/init.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
"github.com/NUS-ISS-Agile-Team/ceramicraft-user-mservice/server/config"
8+
"github.com/NUS-ISS-Agile-Team/ceramicraft-user-mservice/server/log"
89
"github.com/NUS-ISS-Agile-Team/ceramicraft-user-mservice/server/repository/model"
910
"gorm.io/driver/mysql"
1011
"gorm.io/gorm"
@@ -29,13 +30,15 @@ func Init() {
2930
config.Config.MySQLConfig.Port,
3031
config.Config.MySQLConfig.DBName,
3132
)
33+
fmt.Printf("Connecting to MySQL at %s", dsn)
3234
DB, err = gorm.Open(mysql.Open(dsn),
3335
&gorm.Config{
3436
PrepareStmt: true,
3537
SkipDefaultTransaction: true,
3638
},
3739
)
3840
if err != nil {
41+
log.Logger.Errorf("failed to connect database: %v", err)
3942
panic(err)
4043
}
4144
err = DB.AutoMigrate(
@@ -44,6 +47,7 @@ func Init() {
4447
&model.UserAddress{},
4548
)
4649
if err != nil {
50+
log.Logger.Errorf("failed to migrate database: %v", err)
4751
panic(err)
4852
}
4953
}

0 commit comments

Comments
 (0)