harbor/utils/log/level.go

76 lines
1.4 KiB
Go
Raw Normal View History

2016-03-14 07:00:37 +01:00
/*
Copyright (c) 2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package log
import (
"fmt"
)
2016-03-14 07:53:28 +01:00
// Level ...
2016-03-14 07:00:37 +01:00
type Level int
const (
2016-03-14 07:53:28 +01:00
// DebugLevel debug
2016-03-14 07:00:37 +01:00
DebugLevel Level = iota
2016-03-14 07:53:28 +01:00
// InfoLevel info
2016-03-14 07:00:37 +01:00
InfoLevel
2016-03-14 07:53:28 +01:00
// WarningLevel warning
2016-03-14 07:00:37 +01:00
WarningLevel
2016-03-14 07:53:28 +01:00
// ErrorLevel error
2016-03-14 07:00:37 +01:00
ErrorLevel
2016-03-14 07:53:28 +01:00
// FatalLevel fatal
2016-03-14 07:00:37 +01:00
FatalLevel
)
func (l Level) string() (lvl string) {
2016-03-14 07:00:37 +01:00
switch l {
case DebugLevel:
lvl = "DEBUG"
2016-03-14 07:00:37 +01:00
case InfoLevel:
lvl = "INFO"
2016-03-14 07:00:37 +01:00
case WarningLevel:
lvl = "WARNING"
2016-03-14 07:00:37 +01:00
case ErrorLevel:
lvl = "ERROR"
2016-03-14 07:00:37 +01:00
case FatalLevel:
lvl = "FATAL"
default:
lvl = "UNKNOWN"
}
return
}
func parseLevel(lvl string) (level Level, err error) {
switch lvl {
case "debug":
level = DebugLevel
case "info":
level = InfoLevel
case "warning":
level = WarningLevel
case "error":
level = ErrorLevel
case "fatal":
level = FatalLevel
default:
err = fmt.Errorf("invalid log level: %s", lvl)
2016-03-14 07:00:37 +01:00
}
return
2016-03-14 07:00:37 +01:00
}