diff options
author | 2019-10-15 00:48:18 +0000 | |
---|---|---|
committer | 2019-10-15 13:30:04 +0000 | |
commit | 99f7370360201104ddfc99b5e766b4e32e8524cc (patch) | |
tree | 9e7dbc4db186e85afd0654b64bdb4cabdb7b81ab /vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/pkg/utils/logutils.go | |
parent | 3289af42fd3af32fd07c565d072c65743249ebce (diff) |
HDFSWriter microservice working copy
Issue-ID: ONAPARC-453
Signed-off-by: Rajamohan Raj <rajamohan.raj@intel.com>
Change-Id: I11c91b642e466763c1ca6f5734bf81fb260e2b39
Diffstat (limited to 'vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/pkg/utils/logutils.go')
-rw-r--r-- | vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/pkg/utils/logutils.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/pkg/utils/logutils.go b/vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/pkg/utils/logutils.go new file mode 100644 index 00000000..0f72e718 --- /dev/null +++ b/vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/pkg/utils/logutils.go @@ -0,0 +1,32 @@ +package utils + +import ( + "go.uber.org/zap" + "fmt" + "sync" +) + + + +var logOnce sync.Once +var logger *zap.SugaredLogger + +//GetLoggerInstance returns a singleton instance of logger +func GetLoggerInstance() (*zap.SugaredLogger){ + logOnce.Do(func(){ + logger = createLogger() + }) + return logger +} + + +//createLogger returns a SugaredLogger, sugaredLogger can be directly used to generate logs +func createLogger() (*zap.SugaredLogger){ + logger, err := zap.NewDevelopment() + if err != nil { + fmt.Printf("can't initialize zap logger: %v", err) + } + defer logger.Sync() + slogger := logger.Sugar() + return slogger +}
\ No newline at end of file |