Skip to content

Commit

Permalink
Merge pull request #792 from isucon/fix-log
Browse files Browse the repository at this point in the history
ログ出力を改善
  • Loading branch information
wtks authored Dec 7, 2024
2 parents 61289d2 + 4baef93 commit a77b0e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions bench/benchmarker/world/owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@ func (p *Owner) Tick(ctx *Context) error {
return WrapCodeError(ErrorCodeSalesMismatched, err)
}
if increase := desiredChairNum(res.Total) - p.createChairTryCount; increase > 0 {
ctx.ContestantLogger().Info("一定の売上が立ったためオーナーの椅子が増加します", slog.Int("id", int(p.ID)), slog.Int("increase", increase))
ctx.ContestantLogger().Info("一定の売上が立ったためオーナーの椅子が増加します", slog.String("名前", p.RegisteredData.Name), slog.Int("増加数", increase))
for range increase {
p.createChairTryCount++
// TODO どのモデルを増やすか
models := p.ChairModels[modelSpeeds[(p.createChairTryCount-1)%len(modelSpeeds)]]
_, err := p.World.CreateChair(ctx, &CreateChairArgs{
Owner: p,
Expand Down
10 changes: 10 additions & 0 deletions bench/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ var runCmd = &cobra.Command{
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
AddSource: true,
Level: slog.LevelDebug,
ReplaceAttr: func(_ []string, a slog.Attr) slog.Attr {
if a.Key == "time" && a.Value.Kind() == slog.KindTime {
return slog.String(a.Key, a.Value.Time().In(jst).Format("15:04:05.000"))
}
return a
},
})))
contestantLogger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
ReplaceAttr: func(_ []string, a slog.Attr) slog.Attr {
if a.Key == "time" && a.Value.Kind() == slog.KindTime {
Expand Down

0 comments on commit a77b0e2

Please sign in to comment.