k8snetworkplumbingwg / cni-log Goto Github PK
View Code? Open in Web Editor NEWCni-log provides general logging functionality for Container Network Interfaces (CNI).
Cni-log provides general logging functionality for Container Network Interfaces (CNI).
An application using it would most likely set its own path via SetLogFile
before logging any messages.
currently we end up with the default log file always being created even if logs are not written to it.
proposal:
remove default log file, force user to set it
alternative:
if log file path was not set, use default (initialize on first write)
Can be triggered by the following unit test:
+ Context("Logging from different go routines", Ordered, func() {
+ var logFile2 string
+
+ BeforeEach(func() {
+ tempDir := os.TempDir()
+ logFile2 = path.Join(tempDir, "test2.log")
+
+ SetLogFile(logFile)
+ SetLogStderr(false)
+ })
+ AfterEach(func() {
+ Expect(os.RemoveAll(logFile2)).To(Succeed())
+ })
+
+ When("another go routine manipulates the logger", func() {
+ It("does not cause a race condition", func() {
+ go func() {
+ SetLogFile(logFile2)
+ }()
+ // expected := fmt.Sprintf(`time=".*" level=%q msg=%q`, infoStr, infoMsg)
+ errStr := captureStdErrEvent(InfoStructured, infoMsg)
+ Expect(errStr).To(BeEmpty())
+ // Expect(logFileContainsRegex(logFile, expected)).To(BeTrue())
+ })
+ })
And by running:
go test -v -race ./... .
Result:
$ go test -count=1 -race ./... --ginkgo.focus='Logging from different go routines'
Running Suite: CNI-LOG Test Suite - /home/akaris/development/cni-log
====================================================================
Random Seed: 1695739922
Will run 1 of 41 specs
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS==================
WARNING: DATA RACE
Read at 0x000000d65450 by goroutine 34:
github.com/k8snetworkplumbingwg/cni-log.isFileLoggingEnabled()
/home/akaris/development/cni-log/logging.go:262 +0x84
github.com/k8snetworkplumbingwg/cni-log.printWithPrefixf()
/home/akaris/development/cni-log/logging.go:428 +0x8d
github.com/k8snetworkplumbingwg/cni-log.InfoStructured()
/home/akaris/development/cni-log/logging.go:367 +0x73
github.com/k8snetworkplumbingwg/cni-log.captureStdErrEvent()
/home/akaris/development/cni-log/logging_test.go:722 +0x86
github.com/k8snetworkplumbingwg/cni-log.glob..func1.11.3.1()
/home/akaris/development/cni-log/logging_test.go:584 +0xb5
github.com/onsi/ginkgo/v2/internal.(*Suite).runNode.func2()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/suite.go:596 +0xea
Previous write at 0x000000d65450 by goroutine 35:
github.com/k8snetworkplumbingwg/cni-log.SetLogFile()
/home/akaris/development/cni-log/logging.go:251 +0x25c
github.com/k8snetworkplumbingwg/cni-log.glob..func1.11.3.1.1()
/home/akaris/development/cni-log/logging_test.go:581 +0x44
Goroutine 34 (running) created at:
github.com/onsi/ginkgo/v2/internal.(*Suite).runNode()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/suite.go:584 +0x935
github.com/onsi/ginkgo/v2/internal.(*group).attemptSpec()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/group.go:181 +0xfd8
github.com/onsi/ginkgo/v2/internal.(*group).run()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/group.go:303 +0xe64
github.com/onsi/ginkgo/v2/internal.(*Suite).runSpecs()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/suite.go:304 +0xe86
github.com/onsi/ginkgo/v2/internal.(*Suite).Run()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/suite.go:83 +0x444
github.com/onsi/ginkgo/v2.RunSpecs()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/core_dsl.go:280 +0x16a4
github.com/k8snetworkplumbingwg/cni-log.TestLogging()
/home/akaris/development/cni-log/logging_test.go:45 +0x55
testing.tRunner()
/usr/lib/golang/src/testing/testing.go:1576 +0x216
testing.(*T).Run.func1()
/usr/lib/golang/src/testing/testing.go:1629 +0x47
Goroutine 35 (finished) created at:
github.com/k8snetworkplumbingwg/cni-log.glob..func1.11.3.1()
/home/akaris/development/cni-log/logging_test.go:580 +0x96
github.com/onsi/ginkgo/v2/internal.(*Suite).runNode.func2()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/suite.go:596 +0xea
==================
==================
WARNING: DATA RACE
Read at 0x00c000196120 by goroutine 34:
gopkg.in/natefinch/lumberjack%2ev2.(*Logger).filename()
/home/akaris/development/go/pkg/mod/gopkg.in/natefinch/[email protected]/lumberjack.go:293 +0x49
gopkg.in/natefinch/lumberjack%2ev2.(*Logger).openExistingOrNew()
/home/akaris/development/go/pkg/mod/gopkg.in/natefinch/[email protected]/lumberjack.go:267 +0x5e
gopkg.in/natefinch/lumberjack%2ev2.(*Logger).Write()
/home/akaris/development/go/pkg/mod/gopkg.in/natefinch/[email protected]/lumberjack.go:147 +0x2d2
fmt.Fprintf()
/usr/lib/golang/src/fmt/print.go:225 +0xb1
github.com/k8snetworkplumbingwg/cni-log.doWritef()
/home/akaris/development/cni-log/logging.go:412 +0x6c
github.com/k8snetworkplumbingwg/cni-log.printWithPrefixf()
/home/akaris/development/cni-log/logging.go:441 +0x1c5
github.com/k8snetworkplumbingwg/cni-log.InfoStructured()
/home/akaris/development/cni-log/logging.go:367 +0x73
github.com/k8snetworkplumbingwg/cni-log.captureStdErrEvent()
/home/akaris/development/cni-log/logging_test.go:722 +0x86
github.com/k8snetworkplumbingwg/cni-log.glob..func1.11.3.1()
/home/akaris/development/cni-log/logging_test.go:584 +0xb5
github.com/onsi/ginkgo/v2/internal.(*Suite).runNode.func2()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/suite.go:596 +0xea
Previous write at 0x00c000196120 by goroutine 35:
github.com/k8snetworkplumbingwg/cni-log.SetLogFile()
/home/akaris/development/cni-log/logging.go:250 +0x206
github.com/k8snetworkplumbingwg/cni-log.glob..func1.11.3.1.1()
/home/akaris/development/cni-log/logging_test.go:581 +0x44
Goroutine 34 (running) created at:
github.com/onsi/ginkgo/v2/internal.(*Suite).runNode()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/suite.go:584 +0x935
github.com/onsi/ginkgo/v2/internal.(*group).attemptSpec()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/group.go:181 +0xfd8
github.com/onsi/ginkgo/v2/internal.(*group).run()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/group.go:303 +0xe64
github.com/onsi/ginkgo/v2/internal.(*Suite).runSpecs()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/suite.go:304 +0xe86
github.com/onsi/ginkgo/v2/internal.(*Suite).Run()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/suite.go:83 +0x444
github.com/onsi/ginkgo/v2.RunSpecs()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/core_dsl.go:280 +0x16a4
github.com/k8snetworkplumbingwg/cni-log.TestLogging()
/home/akaris/development/cni-log/logging_test.go:45 +0x55
testing.tRunner()
/usr/lib/golang/src/testing/testing.go:1576 +0x216
testing.(*T).Run.func1()
/usr/lib/golang/src/testing/testing.go:1629 +0x47
Goroutine 35 (finished) created at:
github.com/k8snetworkplumbingwg/cni-log.glob..func1.11.3.1()
/home/akaris/development/cni-log/logging_test.go:580 +0x96
github.com/onsi/ginkgo/v2/internal.(*Suite).runNode.func2()
/home/akaris/development/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/suite.go:596 +0xea
==================
•
Ran 1 of 41 Specs in 0.004 seconds
SUCCESS! -- 1 Passed | 0 Failed | 0 Pending | 40 Skipped
--- FAIL: TestLogging (0.01s)
testing.go:1446: race detected during execution of test
FAIL
FAIL github.com/k8snetworkplumbingwg/cni-log 0.017s
FAIL
Shall we create an initial release of this project?
It's currently :
5 | debug | DebugLevel |
---|---|---|
6 | verbose | VerboseLevel |
Shouldn't it be :
5 | verbose | VerboseLevel |
---|---|---|
6 | debug | DebugLevel |
Or, should "verbose" better be called "trace"?
5 | debug | DebugLevel |
---|---|---|
6 | trace | TraceLevel |
That's very subjective but I have never seen any place where "verbose" logged more info than "debug"
The logger should support only logging to stderr. In that case, crio will forward the error logs to the journal. Instead, the logger requires that users provide a log file, even when stderr logging is on, resulting in 2 different locations always receiving logs. This seems redundant.
Current combinations:
Better:
Most of crio's logs are structured, like:
11 23:02:45 sno.workload.bos2.lab crio[4322]: time="2023-07-11 23:02:45.552961184Z" level=info msg="Stopped pod sandbox: 35c3b3752c664d6ac80baa037503f08d359bab27627d40502b5b80f6f1b85264" id=823e2120-adbd-44d1-963a-ea68b957dea4 name=/runtime.v1.RuntimeService/StopPodSandbo
Extend the logger so that it can provide similarly structured logs
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.