Prometheus Kafka Writer Microservice
[demo.git] / vnfs / DAaaS / microservices / prom-kafka-writer / pkg / config / logger.go
1 /*
2  *
3  * Copyright 2019 Intel Corporation.
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  *     http://www.apache.org/licenses/LICENSE-2.0
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  *
14  */
15
16 package config
17
18 import (
19         "go.uber.org/zap"
20         "log"
21         "sync"
22 )
23
24 var logOnce sync.Once
25 var slogger *zap.SugaredLogger
26
27 //GetLoggerInstance returns a singleton instance of logger
28 func GetLoggerInstance() *zap.SugaredLogger {
29         logOnce.Do(func() {
30                 logger, err := zap.NewProduction()
31                 if err != nil {
32                         log.Fatalf("can't initialize zap logger: %v", err)
33                 }
34                 defer logger.Sync()
35                 slogger = logger.Sugar()
36         })
37         return slogger
38 }