1
0
mirror of https://github.com/kubeshark/kubeshark.git synced 2025-05-03 14:18:28 +00:00
kubeshark/logger/logger.go
M. Mert Yıldıran 0eb7883a47
Rename the project to Kubeshark ()
* Rename `mizu` to `kubeshark`

* Rename `up9inc` to `kubeshark`

* Change the logo, title, motto and the main color

* Replace the favicon

* Update the docs link

* Change the copyright text in C files

* Remove a comment

* Rewrite the `README.md` and update the logo and screenshots used in it

* Add a `TODO`

* Fix the grammar

* Fix the bottom text in the filtering guide

* Change the Docker Hub username of cross-compilation intermediate images

* Add an install script

* Fix `docker/login-action` in the CI

* Delete `build-custom-branch.yml` GitHub workflow

* Update `README.md`

* Remove `install.sh`

* Change the motto back to "Traffic viewer for Kubernetes"
2022-11-19 11:13:15 +03:00

50 lines
1.4 KiB
Go

package logger
import (
"os"
"github.com/op/go-logging"
)
var Log = logging.MustGetLogger("kubeshark")
var format = logging.MustStringFormatter(
`[%{time:2006-01-02T15:04:05.000-0700}] %{level:-5s} ▶ %{message} ▶ [%{pid} %{shortfile} %{shortfunc}]`,
)
func InitLogger(logPath string) {
f, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
Log.Infof("Failed to open kubeshark log file: %v, err %v", logPath, err)
}
fileLog := logging.NewLogBackend(f, "", 0)
consoleLog := logging.NewLogBackend(os.Stderr, "", 0)
backend2Formatter := logging.NewBackendFormatter(fileLog, format)
backend1Leveled := logging.AddModuleLevel(consoleLog)
backend1Leveled.SetLevel(logging.INFO, "")
logging.SetBackend(backend1Leveled, backend2Formatter)
}
func InitLoggerStd(level logging.Level) {
var backends []logging.Backend
stderrBackend := logging.NewLogBackend(os.Stderr, "", 0)
stderrFormater := logging.NewBackendFormatter(stderrBackend, format)
stderrLeveled := logging.AddModuleLevel(stderrFormater)
stderrLeveled.SetLevel(logging.ERROR, "")
backends = append(backends, stderrLeveled)
if level >= logging.WARNING {
stdoutBackend := logging.NewLogBackend(os.Stdout, "", 0)
stdoutFormater := logging.NewBackendFormatter(stdoutBackend, format)
stdoutLeveled := logging.AddModuleLevel(stdoutFormater)
stdoutLeveled.SetLevel(level, "")
backends = append(backends, stdoutLeveled)
}
logging.SetBackend(backends...)
}