blob: d6f4ffaa6f343b91bf074d7ca9c3a7be1c964934 [file] [log] [blame]
Prince Pereirac1c21d62021-04-22 08:38:15 +00001/*
2 * Copyright 2020-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
17// Package config Common log initialization
18package config
19
20import (
21 log "github.com/opencord/voltha-lib-go/v4/pkg/log"
22)
23
24// logger represents the log object
25var logger log.CLogger
26
27// Initlog initialise log package
28func Initlog() log.CLogger {
29 if logger != nil {
30 return logger
31 }
32 // Setup this package so that it's log level can be modified at run time
33 var err error
34
35 coreFlags := NewCoreFlags()
36
37 var logLevel log.LogLevel
38
39 switch coreFlags.LogLevel {
40 case LogLevelDebug:
41 logLevel = log.DebugLevel
42 case LogLevelInfo:
43 logLevel = log.InfoLevel
44 case LogLevelWarn:
45 logLevel = log.WarnLevel
46 case LogLevelError:
47 logLevel = log.ErrorLevel
48 default:
49 logLevel = log.ErrorLevel
50 }
51
52 logger, err = log.RegisterPackage(log.JSON, logLevel, log.Fields{})
53 if err != nil {
54 panic(err)
55 }
56 return logger
57}