Skip to content

Commit 4165b31

Browse files
committed
[update] replace logger
1 parent a46c345 commit 4165b31

File tree

17 files changed

+66
-86
lines changed

17 files changed

+66
-86
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ workflows:
8181
- lint:
8282
matrix:
8383
parameters:
84-
version: ["1.21", "1.20"]
84+
version: ["1.21"]
8585
- test:
8686
matrix:
8787
parameters:
88-
version: ["1.21", "1.20"]
88+
version: ["1.21"]

.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ TIME_ZONE=Asia/Tokyo
66
ALLOW_ORIGIN=*
77
JWT_ACCESS_TOKEN_SECRET=gobel-api-jwt-access-token-secret
88
JWT_REFRESH_TOKEN_SECRET=gobel-api-jwt-refresh-token-secret
9-
LOG_THRESHOLD=0 # 0:info 1:warn 2:error 3:fatal
10-
LOG_TIME_ZONE_OFFSET=32400 # 9*60*60
9+
LOG_LEVEL=0 # -4: Debug 0: Info 4: Warn 8: Error
1110

1211
# mysql
1312
DB_DRIVER=mysql

README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The Gobel is a headless cms built with golang.
1717
[bmfsan/gobel-api](https://hub.docker.com/r/bmfsan/gobel-api)
1818

1919
# Features
20-
- Support Go 1.20 >= 1.18
20+
- Support Go 1.21
2121

2222
# Documentation
2323
- [Coding Rule](https://github.com/bmf-san/gobel-api/blob/master/doc/CodingRule.md)
@@ -65,21 +65,32 @@ gobel-api is based on Clean Architecture.
6565
| -------------------- | -------------- |
6666
| Frameworks & Drivers | infrastructure |
6767
| Interface | interfaces |
68-
| usecase | usecase |
68+
| Usecase | usecase |
6969
| Entities | domain |
7070

71-
cf. [blog.cleancoder.com - The Clean Code Blog by Robert C. Martin (Uncle Bob)](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html)
71+
cf. [bmf-tech.com - Golangでクリーンアーキテクチャに入門する](https://bmf-tech.com/posts/Golang%E3%81%A7%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%A2%E3%83%BC%E3%82%AD%E3%83%86%E3%82%AF%E3%83%81%E3%83%A3%E3%81%AB%E5%85%A5%E9%96%80%E3%81%99%E3%82%8B)
7272

73-
# Contributing
74-
We welcome your issue or pull request from everyone.
75-
Please make sure to read the [CONTRIBUTING.md](https://github.com/bmf-san/gobel-api/.github/CONTRIBUTING.md).
73+
# Contribution
74+
Issues and Pull Requests are always welcome.
75+
76+
We would be happy to receive your contributions.
77+
78+
Please review the following documents before making a contribution.
79+
80+
[CODE_OF_CONDUCT](https://github.com/bmf-san/gobel-api/blob/master/.github/CODE_OF_CONDUCT.md)
81+
[CONTRIBUTING](https://github.com/bmf-san/gobel-api/blob/master/.github/CONTRIBUTING.md)
7682

7783
# License
78-
This project is licensed under the terms of the MIT license.
84+
Based on the MIT License.
85+
86+
[LICENSE](https://github.com/bmf-san/gobel-api/blob/master/LICENSE)
7987

80-
# Author
81-
bmf - Software engineer.
88+
## Author
89+
[bmf-san](https://github.com/bmf-san)
8290

83-
- [github - bmf-san/bmf-san](https://github.com/bmf-san/bmf-san)
84-
- [twitter - @bmf-san](https://twitter.com/bmf_san)
85-
- [blog - bmf-tech](http://bmf-tech.com/)
91+
- Email
92+
93+
- Blog
94+
- [bmf-tech.com](http://bmf-tech.com)
95+
- Twitter
96+
- [bmf-san](https://twitter.com/bmf-san)

app/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.20.0-alpine as builder
1+
FROM golang:1.21.0-alpine as builder
22

33
WORKDIR /go/gobel-api/app
44

app/Dockerfile.local

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.20.0-alpine
1+
FROM golang:1.21.0-alpine
22

33
WORKDIR /go/gobel-api/app
44

app/domain/logger.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.21
44

55
require (
66
github.com/bmf-san/goblin v0.0.0-20230202025516-4793d4844d3f
7-
github.com/bmf-san/golem v0.0.0-20210221133857-7ecb33f0ca76
87
golang.org/x/crypto v0.7.0
98
)
109

app/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
github.com/bmf-san/goblin v0.0.0-20230202025516-4793d4844d3f h1:9zv+ydZDJuioOV9taKWq/LgdGziBYilo4asfjbjW5oE=
22
github.com/bmf-san/goblin v0.0.0-20230202025516-4793d4844d3f/go.mod h1:RovWvwcoNNx7Idk/FanQtQjRSWIjZobNusVK8P3Semo=
3-
github.com/bmf-san/golem v0.0.0-20210221133857-7ecb33f0ca76 h1:eZRVFcQ82z1uPDYQzI71M5zXwpjvrD3tLy+uc0txC6E=
4-
github.com/bmf-san/golem v0.0.0-20210221133857-7ecb33f0ca76/go.mod h1:v2YJqaEietOXsYUQVOJeBNIxAGrn4GCeWbfpVzAndRE=
53
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
64
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
75
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

app/infrastructure/logger.go

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,16 @@
11
package infrastructure
22

33
import (
4-
"time"
4+
"os"
55

6-
"github.com/bmf-san/golem"
6+
"log/slog"
77
)
88

9-
// A Logger represents a logger.
10-
type Logger struct {
11-
logger *golem.Logger
12-
}
13-
14-
// NewLogger creates a Logger.
15-
func NewLogger(threshold int, location *time.Location) *Logger {
16-
return &Logger{
17-
logger: golem.NewLogger(threshold, location),
18-
}
19-
}
20-
21-
// Fatal outputs a fatal level log.
22-
func (l *Logger) Fatal(msg string) {
23-
l.logger.Fatal(msg)
24-
}
25-
26-
// Error outputs a fatal level log.
27-
func (l *Logger) Error(msg string) {
28-
l.logger.Error(msg)
29-
}
30-
31-
// Warn outputs a fatal level log.
32-
func (l *Logger) Warn(msg string) {
33-
l.logger.Warn(msg)
34-
}
35-
36-
// Info outputs a fatal level log.
37-
func (l *Logger) Info(msg string) {
38-
l.logger.Info(msg)
9+
// NewLogger creates a logger.
10+
func NewLogger(level int) *slog.Logger {
11+
handler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
12+
Level: slog.Level(level),
13+
})
14+
logger := slog.New(handler)
15+
return logger
3916
}

app/infrastructure/middleware.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package infrastructure
22

33
import (
4+
"log/slog"
45
"net/http"
56
"os"
67
"runtime"
@@ -12,13 +13,13 @@ import (
1213

1314
// Middleware represents the plural of middelware.
1415
type Middleware struct {
15-
logger domain.Logger
16+
logger *slog.Logger
1617
adminRepository repository.AdminRepository
1718
JWT repository.JWT
1819
}
1920

2021
// NewLogger creates a Middleware.
21-
func NewMiddleware(l domain.Logger, ar repository.AdminRepository, jr repository.JWT) *Middleware {
22+
func NewMiddleware(l *slog.Logger, ar repository.AdminRepository, jr repository.JWT) *Middleware {
2223
return &Middleware{
2324
logger: l,
2425
adminRepository: ar,

0 commit comments

Comments
 (0)