initial commit
This commit is contained in:
34
format.go
Normal file
34
format.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package logging
|
||||
|
||||
import "fmt"
|
||||
|
||||
type LogFormat int
|
||||
const (
|
||||
FormatText LogFormat = iota
|
||||
FormatJson
|
||||
)
|
||||
|
||||
var logFormat = FormatText
|
||||
|
||||
var formatString = map[LogFormat]string {
|
||||
FormatText: "text",
|
||||
FormatJson: "json",
|
||||
}
|
||||
|
||||
func (f LogFormat) String() string {
|
||||
str, _ := formatString[f]
|
||||
return str
|
||||
}
|
||||
|
||||
func SetLogFormat(format LogFormat) error {
|
||||
_, exist := formatString[format]
|
||||
if ! exist {
|
||||
return fmt.Errorf("Logging : ERROR : No such log format (%d)", format)
|
||||
}
|
||||
|
||||
logFormat = format
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user