mirror of
https://github.com/kevin-DL/revel-cmd.git
synced 2026-01-11 18:54:31 +00:00
Initial rewrite of revel/cmd to provide vendor support and enhanced CLI options
This commit is contained in:
43
utils/log.go
Normal file
43
utils/log.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/revel/cmd/logger"
|
||||
"github.com/revel/config"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var Logger = logger.New()
|
||||
|
||||
func InitLogger(basePath string, logLevel logger.LogLevel) {
|
||||
newContext := config.NewContext()
|
||||
if logLevel<logger.LvlInfo {
|
||||
newContext.SetOption("log.info.output", "none")
|
||||
newContext.SetOption("log.debug.output", "none")
|
||||
} else {
|
||||
newContext.SetOption("log.info.output", "stdout")
|
||||
newContext.SetOption("log.debug.output", "stdout")
|
||||
}
|
||||
newContext.SetOption("log.warn.output","stderr")
|
||||
newContext.SetOption("log.error.output","stderr")
|
||||
newContext.SetOption("log.crit.output","stderr")
|
||||
Logger.SetHandler(logger.InitializeFromConfig(basePath, newContext))
|
||||
}
|
||||
|
||||
// This function is to throw a panic that may be caught by the packger so it can perform the needed
|
||||
// imports
|
||||
func Retry(format string, args ...interface{}) {
|
||||
// Ensure the user's command prompt starts on the next line.
|
||||
if !strings.HasSuffix(format, "\n") {
|
||||
format += "\n"
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, format, args...)
|
||||
panic(format) // Panic instead of os.Exit so that deferred will run.
|
||||
}
|
||||
|
||||
type LoggedError struct{ error }
|
||||
|
||||
func NewLoggedError(err error) *LoggedError {
|
||||
return &LoggedError{err}
|
||||
}
|
||||
Reference in New Issue
Block a user