-
Notifications
You must be signed in to change notification settings - Fork 11
/
service_base.go
55 lines (44 loc) · 1.16 KB
/
service_base.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package appbase
import (
"fmt"
"github.com/jitsucom/bulker/jitsubase/logging"
)
// Service base struct for typical service objects
type Service struct {
// ID is used as [ID] prefix in log and error messages
ID string
}
func NewServiceBase(id string) Service {
return Service{
ID: id,
}
}
func (sb *Service) NewError(format string, a ...any) error {
return fmt.Errorf("[%s] "+format, sb.args(a)...)
}
func (sb *Service) Infof(format string, a ...any) {
logging.Infof("[%s] "+format, sb.args(a)...)
}
func (sb *Service) Errorf(format string, a ...any) {
logging.Errorf("[%s] "+format, sb.args(a)...)
}
func (sb *Service) Warnf(format string, a ...any) {
logging.Warnf("[%s] "+format, sb.args(a)...)
}
func (sb *Service) Debugf(format string, a ...any) {
if logging.IsDebugEnabled() {
logging.Debugf("[%s] "+format, sb.args(a)...)
}
}
func (sb *Service) Fatalf(format string, a ...any) {
logging.Fatalf("[%s] "+format, sb.args(a)...)
}
func (sb *Service) SystemErrorf(format string, a ...any) {
logging.SystemErrorf("[%s] "+format, sb.args(a)...)
}
func (sb *Service) args(a []any) []any {
b := make([]any, len(a)+1)
copy(b[1:], a)
b[0] = sb.ID
return b
}