2016-05-11 10:05:19 +02:00
|
|
|
package utils
|
2016-04-20 08:24:17 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-05-11 10:05:19 +02:00
|
|
|
|
2016-04-20 08:24:17 +02:00
|
|
|
"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)
|
|
|
|
}
|
|
|
|
}
|