2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
23 #cgo CFLAGS: -I/usr/local/include
24 #cgo LDFLAGS: -lmdclog
26 #include <mdclog/mdclog.h>
27 void xAppMgr_mdclog_write(mdclog_severity_t severity, const char *msg) {
28 mdclog_write(severity, "%s", msg);
43 LogLvlErr = C.MDCLOG_ERR
44 LogLvlWarn = C.MDCLOG_WARN
45 LogLvlInfo = C.MDCLOG_INFO
46 LogLvlDebug = C.MDCLOG_DEBUG
49 func WriteLog(lvl C.mdclog_severity_t, msg string) {
50 t := time.Now().Format("2019-01-02 15:04:05")
51 text := fmt.Sprintf("%s:: %s ", t, msg)
53 C.xAppMgr_mdclog_write(lvl, C.CString(text))
56 func (Log) SetLevel(level int) {
57 l := C.mdclog_severity_t(level)
61 func (Log) SetMdc(key string, value string) {
62 C.mdclog_mdc_add(C.CString(key), C.CString(value))
65 func (Log) Fatal(pattern string, args ...interface{}) {
66 WriteLog(LogLvlErr, fmt.Sprintf(pattern, args...))
67 log.Panic("Fatal error occured, exiting ...")
70 func (Log) Error(pattern string, args ...interface{}) {
71 WriteLog(LogLvlErr, fmt.Sprintf(pattern, args...))
74 func (Log) Warn(pattern string, args ...interface{}) {
75 WriteLog(LogLvlWarn, fmt.Sprintf(pattern, args...))
78 func (Log) Info(pattern string, args ...interface{}) {
79 WriteLog(LogLvlInfo, fmt.Sprintf(pattern, args...))
82 func (Log) Debug(pattern string, args ...interface{}) {
83 WriteLog(LogLvlDebug, fmt.Sprintf(pattern, args...))