blob: cc6e48def7d625559816060c3e192281295400be [file] [log] [blame]
Matteo Scandolo2bf742a2019-10-01 11:33:34 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Matteo Scandolo40e067f2019-10-16 16:59:41 -070017package common
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070018
19import log "github.com/sirupsen/logrus"
20
21func SetLogLevel(logger *log.Logger, level string, caller bool) {
22
23 logger.SetReportCaller(caller)
24
25 switch level {
26 case "trace":
27 logger.SetLevel(log.TraceLevel)
28 case "debug":
29 logger.SetLevel(log.DebugLevel)
30 case "info":
31 logger.SetLevel(log.InfoLevel)
32 case "warn":
33 logger.SetLevel(log.WarnLevel)
34 case "error":
35 logger.SetLevel(log.ErrorLevel)
36 default:
37 logger.SetLevel(log.DebugLevel)
38 logger.WithFields(log.Fields{
39 "level": level,
40 }).Warn("The provided level is unknown. Defaulting to 'debug'")
41 }
42
43}