Bumps the minor-and-patch group with 9 updates: | Package | From | To | | --- | --- | --- | | [github.com/nats-io/nats-server/v2](https://github.com/nats-io/nats-server) | `2.14.4` | `2.14.5` | | [github.com/nats-io/nats.go](https://github.com/nats-io/nats.go) | `1.52.0` | `1.53.1` | | [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) | `2.32.0` | `2.32.1` | | [github.com/sirupsen/logrus](https://github.com/sirupsen/logrus) | `1.9.4` | `1.10.0` | | [golang.org/x/crypto](https://github.com/golang/crypto) | `0.54.0` | `0.55.0` | | [golang.org/x/image](https://github.com/golang/image) | `0.44.0` | `0.45.0` | | [golang.org/x/net](https://github.com/golang/net) | `0.57.0` | `0.58.0` | | [golang.org/x/text](https://github.com/golang/text) | `0.40.0` | `0.41.0` | | google.golang.org/protobuf | `1.36.11` | `1.36.12` | Updates `github.com/nats-io/nats-server/v2` from 2.14.4 to 2.14.5 - [Release notes](https://github.com/nats-io/nats-server/releases) - [Changelog](https://github.com/nats-io/nats-server/blob/main/RELEASES.md) - [Commits](https://github.com/nats-io/nats-server/compare/v2.14.4...v2.14.5) Updates `github.com/nats-io/nats.go` from 1.52.0 to 1.53.1 - [Release notes](https://github.com/nats-io/nats.go/releases) - [Commits](https://github.com/nats-io/nats.go/compare/v1.52.0...v1.53.1) Updates `github.com/onsi/ginkgo/v2` from 2.32.0 to 2.32.1 - [Release notes](https://github.com/onsi/ginkgo/releases) - [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/ginkgo/compare/v2.32.0...v2.32.1) Updates `github.com/sirupsen/logrus` from 1.9.4 to 1.10.0 - [Release notes](https://github.com/sirupsen/logrus/releases) - [Changelog](https://github.com/sirupsen/logrus/blob/master/CHANGELOG.md) - [Commits](https://github.com/sirupsen/logrus/compare/v1.9.4...v1.10.0) Updates `golang.org/x/crypto` from 0.54.0 to 0.55.0 - [Commits](https://github.com/golang/crypto/compare/v0.54.0...v0.55.0) Updates `golang.org/x/image` from 0.44.0 to 0.45.0 - [Commits](https://github.com/golang/image/compare/v0.44.0...v0.45.0) Updates `golang.org/x/net` from 0.57.0 to 0.58.0 - [Commits](https://github.com/golang/net/compare/v0.57.0...v0.58.0) Updates `golang.org/x/text` from 0.40.0 to 0.41.0 - [Release notes](https://github.com/golang/text/releases) - [Commits](https://github.com/golang/text/compare/v0.40.0...v0.41.0) Updates `google.golang.org/protobuf` from 1.36.11 to 1.36.12 --- updated-dependencies: - dependency-name: github.com/nats-io/nats-server/v2 dependency-version: 2.14.5 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: minor-and-patch - dependency-name: github.com/nats-io/nats.go dependency-version: 1.53.1 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: minor-and-patch - dependency-name: github.com/onsi/ginkgo/v2 dependency-version: 2.32.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: minor-and-patch - dependency-name: github.com/sirupsen/logrus dependency-version: 1.10.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: minor-and-patch - dependency-name: golang.org/x/crypto dependency-version: 0.55.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: minor-and-patch - dependency-name: golang.org/x/image dependency-version: 0.45.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: minor-and-patch - dependency-name: golang.org/x/net dependency-version: 0.58.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: minor-and-patch - dependency-name: golang.org/x/text dependency-version: 0.41.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: minor-and-patch - dependency-name: google.golang.org/protobuf dependency-version: 1.36.12 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: minor-and-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
101 lines
3.1 KiB
Go
101 lines
3.1 KiB
Go
package logrus
|
|
|
|
import (
|
|
"bufio"
|
|
"io"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
// Writer at INFO level. See WriterLevel for details.
|
|
func (logger *Logger) Writer() *io.PipeWriter {
|
|
return logger.WriterLevel(InfoLevel)
|
|
}
|
|
|
|
// WriterLevel returns an io.Writer that can be used to write arbitrary text to
|
|
// the logger at the given log level. Each line written to the writer will be
|
|
// printed in the usual way using formatters and hooks. The writer is part of an
|
|
// io.Pipe and it is the callers responsibility to close the writer when done.
|
|
// This can be used to override the standard library logger easily.
|
|
func (logger *Logger) WriterLevel(level Level) *io.PipeWriter {
|
|
return NewEntry(logger).WriterLevel(level)
|
|
}
|
|
|
|
// Writer returns an io.Writer that writes to the logger at the info log level
|
|
func (entry *Entry) Writer() *io.PipeWriter {
|
|
return entry.WriterLevel(InfoLevel)
|
|
}
|
|
|
|
// WriterLevel returns an io.Writer that writes to the logger at the given log level
|
|
func (entry *Entry) WriterLevel(level Level) *io.PipeWriter {
|
|
reader, writer := io.Pipe()
|
|
|
|
printFunc := entry.Print
|
|
|
|
// Determine which log function to use based on the specified log level
|
|
switch level {
|
|
case TraceLevel:
|
|
printFunc = entry.Trace
|
|
case DebugLevel:
|
|
printFunc = entry.Debug
|
|
case InfoLevel:
|
|
printFunc = entry.Info
|
|
case WarnLevel:
|
|
printFunc = entry.Warn
|
|
case ErrorLevel:
|
|
printFunc = entry.Error
|
|
case FatalLevel:
|
|
printFunc = entry.Fatal
|
|
case PanicLevel:
|
|
printFunc = entry.Panic
|
|
}
|
|
|
|
// Start a new goroutine to scan the input and write it to the logger using the specified print function.
|
|
// It splits the input into chunks of up to 64KB to avoid buffer overflows.
|
|
go entry.writerScanner(reader, printFunc)
|
|
|
|
// Set a finalizer function to close the writer when it is garbage collected
|
|
runtime.SetFinalizer(writer, writerFinalizer)
|
|
|
|
return writer
|
|
}
|
|
|
|
// writerScanner scans the input from the reader and writes it to the logger
|
|
func (entry *Entry) writerScanner(reader *io.PipeReader, printFunc func(args ...any)) {
|
|
scanner := bufio.NewScanner(reader)
|
|
|
|
// Set the buffer size to the maximum token size to avoid buffer overflows
|
|
scanner.Buffer(make([]byte, bufio.MaxScanTokenSize), bufio.MaxScanTokenSize)
|
|
|
|
// Define a split function to split the input into chunks of up to 64KB
|
|
chunkSize := bufio.MaxScanTokenSize // 64KB
|
|
splitFunc := func(data []byte, atEOF bool) (int, []byte, error) {
|
|
if len(data) >= chunkSize {
|
|
return chunkSize, data[:chunkSize], nil
|
|
}
|
|
|
|
return bufio.ScanLines(data, atEOF)
|
|
}
|
|
|
|
// Use the custom split function to split the input
|
|
scanner.Split(splitFunc)
|
|
|
|
// Scan the input and write it to the logger using the specified print function
|
|
for scanner.Scan() {
|
|
printFunc(strings.TrimRight(scanner.Text(), "\r\n"))
|
|
}
|
|
|
|
// If there was an error while scanning the input, log an error
|
|
if err := scanner.Err(); err != nil {
|
|
entry.Errorf("Error while reading from Writer: %s", err)
|
|
}
|
|
|
|
// Close the reader when we are done
|
|
reader.Close()
|
|
}
|
|
|
|
// WriterFinalizer is a finalizer function that closes then given writer when it is garbage collected
|
|
func writerFinalizer(writer *io.PipeWriter) {
|
|
writer.Close()
|
|
}
|