started new logger output
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -3,7 +3,6 @@ package jobm
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gitbase.de/apairon/mark2web/pkg/progress"
|
||||
)
|
||||
@@ -52,7 +51,7 @@ func Enqueue(jobs ...Job) {
|
||||
// Wait will wait for all jobs to finish
|
||||
func Wait() {
|
||||
close(jobChan)
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
progress.Stop()
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
var Log = logging.MustGetLogger("myLogger")
|
||||
var logBackendLeveled logging.LeveledBackend
|
||||
|
||||
var Prefix = ""
|
||||
|
||||
// SetLogLevel sets log level for global logger (debug, info, notice, warning, error)
|
||||
func SetLogLevel(level string) {
|
||||
logBackendLevel := logging.INFO
|
||||
@@ -44,7 +46,7 @@ func SetLogLevel(level string) {
|
||||
func configureLogger() {
|
||||
logBackend := logging.NewLogBackend(os.Stderr, "", 0)
|
||||
logBackendFormatter := logging.NewBackendFormatter(logBackend, logging.MustStringFormatter(
|
||||
`%{color}%{time:15:04:05.000} %{shortfunc} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`,
|
||||
`%{color}%{time:2006-01-02 15:04:05.000} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`,
|
||||
))
|
||||
logBackendLeveled = logging.AddModuleLevel(logBackendFormatter)
|
||||
logBackendLeveled.SetLevel(logging.NOTICE, "")
|
||||
@@ -59,34 +61,38 @@ func init() {
|
||||
configureLogger()
|
||||
}
|
||||
|
||||
func prefix() string {
|
||||
return Prefix
|
||||
}
|
||||
|
||||
// D is shorthand for Debugf
|
||||
func D(format string, args ...interface{}) {
|
||||
Log.Debugf(format, args...)
|
||||
Log.Debugf(prefix()+format, args...)
|
||||
}
|
||||
|
||||
// I is shorthand for Infof
|
||||
func I(format string, args ...interface{}) {
|
||||
Log.Infof(format, args...)
|
||||
Log.Infof(prefix()+format, args...)
|
||||
}
|
||||
|
||||
// N is shorthand for Noticef
|
||||
func N(format string, args ...interface{}) {
|
||||
Log.Noticef(format, args...)
|
||||
Log.Noticef(prefix()+format, args...)
|
||||
}
|
||||
|
||||
// W is shorthand for Warningf
|
||||
func W(format string, args ...interface{}) {
|
||||
Log.Warningf(format, args...)
|
||||
Log.Warningf(prefix()+format, args...)
|
||||
}
|
||||
|
||||
// E is shorthand for Errorf
|
||||
func E(format string, args ...interface{}) {
|
||||
Log.Errorf(format, args...)
|
||||
Log.Errorf(prefix()+format, args...)
|
||||
}
|
||||
|
||||
// P is shorthand for Panicf
|
||||
func P(format string, args ...interface{}) {
|
||||
Log.Panicf(format, args...)
|
||||
Log.Panicf(prefix()+format, args...)
|
||||
}
|
||||
|
||||
// Eerr is shorthand for
|
||||
@@ -96,7 +102,7 @@ func P(format string, args ...interface{}) {
|
||||
func Eerr(err error, format string, args ...interface{}) {
|
||||
if err != nil {
|
||||
args = append(args, err)
|
||||
Log.Errorf(format+"\nError: %s", args...)
|
||||
Log.Errorf(prefix()+format+" (Error: %s)", args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,6 +125,6 @@ func Eexit(err error, format string, args ...interface{}) {
|
||||
func Perr(err error, format string, args ...interface{}) {
|
||||
if err != nil {
|
||||
args = append(args, err)
|
||||
Log.Panicf(format+"\nError: %s", args...)
|
||||
Log.Panicf(prefix()+format+" (Error: %s)", args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package progress
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gitbase.de/apairon/mark2web/pkg/helper"
|
||||
"gitbase.de/apairon/mark2web/pkg/logger"
|
||||
"github.com/gosuri/uiprogress"
|
||||
"github.com/mattn/go-tty"
|
||||
)
|
||||
@@ -23,8 +25,12 @@ var OverallTotal = 0
|
||||
// OverallDone is number of done jobs
|
||||
var OverallDone = 0
|
||||
|
||||
// Init initializes the bar drawing
|
||||
func Init() {
|
||||
func init() {
|
||||
updateLoggerPrefix()
|
||||
}
|
||||
|
||||
// Start initializes the bar drawing
|
||||
func Start() {
|
||||
if t, err := tty.Open(); err == nil && t != nil {
|
||||
terminalWidth, _, _ = t.Size()
|
||||
t.Close()
|
||||
@@ -33,9 +39,15 @@ func Init() {
|
||||
initialized = true
|
||||
}
|
||||
|
||||
func updateLoggerPrefix() {
|
||||
logger.Prefix = fmt.Sprintf("%3d/%3d: ", OverallDone, OverallTotal)
|
||||
}
|
||||
|
||||
// IncrTotal increases the total jobs for the bar
|
||||
func IncrTotal(barname string) {
|
||||
OverallTotal++
|
||||
updateLoggerPrefix()
|
||||
|
||||
if initialized {
|
||||
_bar := bars[barname]
|
||||
if _bar == nil {
|
||||
@@ -60,6 +72,8 @@ func IncrTotal(barname string) {
|
||||
// IncrDone increases to done jobs counter
|
||||
func IncrDone(barname string) {
|
||||
OverallDone++
|
||||
updateLoggerPrefix()
|
||||
|
||||
if initialized {
|
||||
bars[barname].Bar.Incr()
|
||||
bars[barname].Description = ""
|
||||
@@ -72,3 +86,11 @@ func DescribeCurrent(barname, description string) {
|
||||
bars[barname].Description = description
|
||||
}
|
||||
}
|
||||
|
||||
// Stop stops the bar drawing
|
||||
func Stop() {
|
||||
if initialized {
|
||||
time.Sleep(time.Millisecond * 200)
|
||||
uiprogress.Stop()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user