mirror of
https://github.com/kairos-io/provider-k3s.git
synced 2025-04-27 11:01:01 +00:00
fix: add log rotation and version in logging (#100)
* fix: add log rotation and version in logging Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com> * ci: use 22.04 ubuntu runner Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com> --------- Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>
This commit is contained in:
parent
36a500d332
commit
153d95162a
4
.github/workflows/pull_request.yaml
vendored
4
.github/workflows/pull_request.yaml
vendored
@ -11,7 +11,7 @@ permissions:
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: docker-practice/actions-setup-docker@master
|
||||
@ -21,7 +21,7 @@ jobs:
|
||||
- run: earthly --ci +lint
|
||||
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: go test ./...
|
4
.github/workflows/release.yaml
vendored
4
.github/workflows/release.yaml
vendored
@ -11,7 +11,7 @@ permissions:
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up QEMU
|
||||
@ -26,7 +26,7 @@ jobs:
|
||||
version: "latest"
|
||||
- run: earthly --ci +lint
|
||||
build-provider-package:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04
|
||||
permissions:
|
||||
packages: write
|
||||
steps:
|
||||
|
@ -37,6 +37,7 @@ BUILD_GOLANG:
|
||||
ARG BIN
|
||||
ARG SRC
|
||||
ENV CGO_ENABLED=0
|
||||
ENV GO_LDFLAGS=" -X github.com/kairos-io/provider-k3s/pkg/version.Version=${VERSION} -w -s"
|
||||
RUN go-build-static.sh -a -o ${BIN} ./${SRC}
|
||||
SAVE ARTIFACT ${BIN} ${BIN} AS LOCAL build/${BIN}
|
||||
|
||||
|
1
go.mod
1
go.mod
@ -7,6 +7,7 @@ require (
|
||||
github.com/mudler/go-pluggable v0.0.0-20230126220627-7710299a0ae5
|
||||
github.com/mudler/yip v1.10.0
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
sigs.k8s.io/yaml v1.4.0
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@ -125,6 +125,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
9
main.go
9
main.go
@ -1,21 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/kairos-io/kairos-sdk/clusterplugin"
|
||||
"github.com/mudler/go-pluggable"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/kairos-io/provider-k3s/pkg/log"
|
||||
"github.com/kairos-io/provider-k3s/pkg/provider"
|
||||
)
|
||||
|
||||
func main() {
|
||||
f, err := os.OpenFile("/var/log/provider-k3s.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
logrus.SetOutput(f)
|
||||
log.InitLogger("/var/log/provider-k3s.log")
|
||||
|
||||
plugin := clusterplugin.ClusterPlugin{
|
||||
Provider: provider.ClusterProvider,
|
||||
|
39
pkg/log/log.go
Normal file
39
pkg/log/log.go
Normal file
@ -0,0 +1,39 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/kairos-io/provider-k3s/pkg/version"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
)
|
||||
|
||||
func InitLogger(path string) {
|
||||
f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
logfile := &lumberjack.Logger{
|
||||
Filename: f.Name(),
|
||||
MaxSize: 10,
|
||||
MaxBackups: 5,
|
||||
Compress: true,
|
||||
}
|
||||
|
||||
logrus.SetOutput(logfile)
|
||||
logrus.SetFormatter(KubeadmLogger{
|
||||
Version: version.Version,
|
||||
Formatter: logrus.StandardLogger().Formatter,
|
||||
})
|
||||
}
|
||||
|
||||
type KubeadmLogger struct {
|
||||
Version string
|
||||
Formatter logrus.Formatter
|
||||
}
|
||||
|
||||
func (l KubeadmLogger) Format(entry *logrus.Entry) ([]byte, error) {
|
||||
entry.Data["version"] = l.Version
|
||||
return l.Formatter.Format(entry)
|
||||
}
|
3
pkg/version/version.go
Normal file
3
pkg/version/version.go
Normal file
@ -0,0 +1,3 @@
|
||||
package version
|
||||
|
||||
var Version string
|
Loading…
Reference in New Issue
Block a user