Update logging
[ric-plt/xapp-frame.git] / pkg / xapp / logger.go
index a73cb36..484df2c 100755 (executable)
 
 package xapp
 
-/*
-#cgo CFLAGS: -I/usr/local/include
-#cgo LDFLAGS: -lmdclog
-#
-#include <mdclog/mdclog.h>
-void xAppMgr_mdclog_write(mdclog_severity_t severity, const char *msg) {
-     mdclog_write(severity, "%s", msg);
-}
-*/
-import "C"
-
 import (
-       "fmt"
-       "log"
-       "time"
+       mdclog "gerrit.o-ran-sc.org/r/com/golog"
 )
 
 type Log struct {
+       logger *mdclog.MdcLogger
 }
 
-const (
-       LogLvlErr   = C.MDCLOG_ERR
-       LogLvlWarn  = C.MDCLOG_WARN
-       LogLvlInfo  = C.MDCLOG_INFO
-       LogLvlDebug = C.MDCLOG_DEBUG
-)
-
-func WriteLog(lvl C.mdclog_severity_t, msg string) {
-       t := time.Now().Format("2019-01-02 15:04:05")
-       text := fmt.Sprintf("%s:: %s ", t, msg)
-
-       C.xAppMgr_mdclog_write(lvl, C.CString(text))
-}
-
-func (Log) SetLevel(level int) {
-       l := C.mdclog_severity_t(level)
-       C.mdclog_level_set(l)
+func NewLogger(name string) *Log {
+       l, _ := mdclog.InitLogger(name)
+       return &Log{
+               logger: l,
+       }
 }
 
-func (Log) SetMdc(key string, value string) {
-       C.mdclog_mdc_add(C.CString(key), C.CString(value))
+func (l *Log) SetLevel(level int) {
+       l.logger.LevelSet(mdclog.Level(level))
 }
 
-func (Log) Fatal(pattern string, args ...interface{}) {
-       WriteLog(LogLvlErr, fmt.Sprintf(pattern, args...))
-       log.Panic("Fatal error occured, exiting ...")
+func (l *Log) SetMdc(key string, value string) {
+       l.logger.MdcAdd(key, value)
 }
 
-func (Log) Error(pattern string, args ...interface{}) {
-       WriteLog(LogLvlErr, fmt.Sprintf(pattern, args...))
+func (l *Log) Error(pattern string, args ...interface{}) {
+       l.logger.Error(pattern, args...)
 }
 
-func (Log) Warn(pattern string, args ...interface{}) {
-       WriteLog(LogLvlWarn, fmt.Sprintf(pattern, args...))
+func (l *Log) Warn(pattern string, args ...interface{}) {
+       l.logger.Warning(pattern, args...)
 }
 
-func (Log) Info(pattern string, args ...interface{}) {
-       WriteLog(LogLvlInfo, fmt.Sprintf(pattern, args...))
+func (l *Log) Info(pattern string, args ...interface{}) {
+       l.logger.Info(pattern, args...)
 }
 
-func (Log) Debug(pattern string, args ...interface{}) {
-       WriteLog(LogLvlDebug, fmt.Sprintf(pattern, args...))
+func (l *Log) Debug(pattern string, args ...interface{}) {
+       l.logger.Debug(pattern, args...)
 }