summaryrefslogtreecommitdiff
path: root/vendor/github.com/sirupsen/logrus/writer.go
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2025-02-03 10:12:35 +0000
committerLibravatar GitHub <noreply@github.com>2025-02-03 10:12:35 +0000
commitc086d4048c2a26a0bf70c1ced24c78680a786710 (patch)
treecf7606e8452e9047d7f0e0d9b6de10edf7ebdc89 /vendor/github.com/sirupsen/logrus/writer.go
parent[chore]: Bump golang.org/x/oauth2 from 0.24.0 to 0.25.0 (#3725) (diff)
downloadgotosocial-c086d4048c2a26a0bf70c1ced24c78680a786710.tar.xz
[chore]: Bump github.com/KimMachineGun/automemlimit from 0.6.1 to 0.7.0 (#3726)
Bumps [github.com/KimMachineGun/automemlimit](https://github.com/KimMachineGun/automemlimit) from 0.6.1 to 0.7.0. - [Release notes](https://github.com/KimMachineGun/automemlimit/releases) - [Commits](https://github.com/KimMachineGun/automemlimit/compare/v0.6.1...v0.7.0) --- updated-dependencies: - dependency-name: github.com/KimMachineGun/automemlimit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/sirupsen/logrus/writer.go')
-rw-r--r--vendor/github.com/sirupsen/logrus/writer.go102
1 files changed, 0 insertions, 102 deletions
diff --git a/vendor/github.com/sirupsen/logrus/writer.go b/vendor/github.com/sirupsen/logrus/writer.go
deleted file mode 100644
index 074fd4b8b..000000000
--- a/vendor/github.com/sirupsen/logrus/writer.go
+++ /dev/null
@@ -1,102 +0,0 @@
-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()
-
- var printFunc func(args ...interface{})
-
- // 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
- default:
- printFunc = entry.Print
- }
-
- // 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 ...interface{})) {
- 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()
-}