mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-04 15:08:21 +01:00
40 lines
837 B
Go
40 lines
837 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/vmware/harbor/dao"
|
|
"github.com/vmware/harbor/utils/log"
|
|
)
|
|
|
|
const (
|
|
INFO = "info"
|
|
WARN = "warning"
|
|
ERR = "error"
|
|
)
|
|
|
|
type Logger struct {
|
|
ID int64
|
|
}
|
|
|
|
func (l *Logger) Infof(format string, v ...interface{}) {
|
|
err := dao.AddJobLog(l.ID, INFO, fmt.Sprintf(format, v...))
|
|
if err != nil {
|
|
log.Warningf("Failed to add job log, id: %d, error: %v", l.ID, err)
|
|
}
|
|
}
|
|
|
|
func (l *Logger) Warningf(format string, v ...interface{}) {
|
|
err := dao.AddJobLog(l.ID, WARN, fmt.Sprintf(format, v...))
|
|
if err != nil {
|
|
log.Warningf("Failed to add job log, id: %d, error: %v", l.ID, err)
|
|
}
|
|
}
|
|
|
|
func (l *Logger) Errorf(format string, v ...interface{}) {
|
|
err := dao.AddJobLog(l.ID, ERR, fmt.Sprintf(format, v...))
|
|
if err != nil {
|
|
log.Warningf("Failed to add job log, id: %d, error: %v", l.ID, err)
|
|
}
|
|
}
|