added logger 95/10895/1
authorhoejoo.lee <hoejoo.lee@samsung.com>
Thu, 13 Apr 2023 09:45:31 +0000 (05:45 -0400)
committerhoejoo.lee <hoejoo.lee@samsung.com>
Thu, 13 Apr 2023 09:45:31 +0000 (05:45 -0400)
Change-Id: I0318634935e813b3196e6b668effab176ac93c0f
Signed-off-by: hoejoo.lee <hoejoo.lee@samsung.com>
go.mod [new file with mode: 0755]
main.go [new file with mode: 0755]
pkg/commons/logger/logger.go [new file with mode: 0755]

diff --git a/go.mod b/go.mod
new file mode 100755 (executable)
index 0000000..59f1cb7
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,3 @@
+module gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter\r
+\r
+go 1.18\r
diff --git a/main.go b/main.go
new file mode 100755 (executable)
index 0000000..c8e2956
--- /dev/null
+++ b/main.go
@@ -0,0 +1,26 @@
+/*\r
+==================================================================================\r
+  Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved.\r
+\r
+  Licensed under the Apache License, Version 2.0 (the "License");\r
+  you may not use this file except in compliance with the License.\r
+  You may obtain a copy of the License at\r
+\r
+         http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+  Unless required by applicable law or agreed to in writing, software\r
+  distributed under the License is distributed on an "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  See the License for the specific language governing permissions and\r
+  limitations under the License.\r
+==================================================================================\r
+*/\r
+\r
+package main\r
+\r
+import "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter"\r
+\r
+func main() {\r
+       logger.Logging(logger.DEBUG, "IN")\r
+       defer logger.Logging(logger.DEBUG, "OUT")\r
+}\r
diff --git a/pkg/commons/logger/logger.go b/pkg/commons/logger/logger.go
new file mode 100755 (executable)
index 0000000..6fa6800
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+==================================================================================
+Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+       http://www.apache.org/licenses/LICENSE-2.0
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==================================================================================
+*/
+
+// Package commons/logger implements log stream.
+package logger
+
+import (
+       "log"
+       "os"
+       "path"
+       "runtime"
+       "strconv"
+       "strings"
+)
+
+var loggers [3]*log.Logger
+var logFlag int
+
+// init initializes package global value.
+func init() {
+       logFlag = log.Ldate | log.Ltime
+       loggers[0] = log.New(os.Stdout, "[INFO][kserve-adapter]", logFlag)
+       loggers[1] = log.New(os.Stdout, "[DEBUG][kserve-adapter]", logFlag)
+       loggers[2] = log.New(os.Stdout, "[ERROR][kserve-adapter]", logFlag)
+}
+
+const (
+       INFO = iota
+       DEBUG
+       ERROR
+)
+
+// Logging prints log stream on standard output with file name and function name, line.
+func Logging(level int, msgs ...string) {
+       pc, file, line, _ := runtime.Caller(1)
+       _, fileName := path.Split(file)
+       parts := strings.Split(runtime.FuncForPC(pc).Name(), ".")
+       pl := len(parts)
+       funcName := parts[pl-1]
+
+       packageName := ""
+       if parts[pl-2][0] == '(' {
+               funcName = parts[pl-2] + "." + funcName
+               packageName = strings.Join(parts[0:pl-2], ".")
+       } else {
+               packageName = strings.Join(parts[0:pl-1], ".")
+       }
+
+       loggers[level].Println(packageName, fileName, funcName, ":", strconv.Itoa(line), msgs)
+}