aboutsummaryrefslogtreecommitdiff
path: root/internal/dbutil/writer.go
blob: 6b83d53754f7218b1a51cd0d721a5f963619bb18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2020 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package dbutil

import (
	"fmt"
	"io"
)

// Writer is a wrapper of io.Writer for the gorm.logger.
type Writer struct {
	io.Writer
}

func (w *Writer) Print(v ...interface{}) {
	if len(v) == 0 {
		return
	}

	if len(v) == 1 {
		fmt.Fprint(w.Writer, v[0])
		return
	}

	switch v[0] {
	case "sql":
		fmt.Fprintf(w.Writer, "[sql] [%s] [%s] %s %v (%d rows affected)", v[1:]...)
	case "log":
		fmt.Fprintf(w.Writer, "[log] [%s] %s", v[1:]...)
	default:
		fmt.Fprint(w.Writer, v...)
	}
}