Merge pull request #46926 from thaJeztah/carry_logentries_removal
logger: remove logentries driver (carry 44442)
This commit is contained in:
commit
f3cc93630e
14 changed files with 38 additions and 449 deletions
|
@ -209,6 +209,10 @@ func (sr *swarmRouter) createService(ctx context.Context, w http.ResponseWriter,
|
|||
if err := httputils.ReadJSON(r, &service); err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO(thaJeztah): remove logentries check and migration code in release v26.0.0.
|
||||
if service.TaskTemplate.LogDriver != nil && service.TaskTemplate.LogDriver.Name == "logentries" {
|
||||
return errdefs.InvalidParameter(errors.New("the logentries logging driver has been deprecated and removed"))
|
||||
}
|
||||
|
||||
// Get returns "" if the header does not exist
|
||||
encodedAuth := r.Header.Get(registry.AuthHeader)
|
||||
|
@ -245,6 +249,10 @@ func (sr *swarmRouter) updateService(ctx context.Context, w http.ResponseWriter,
|
|||
if err := httputils.ReadJSON(r, &service); err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO(thaJeztah): remove logentries check and migration code in release v26.0.0.
|
||||
if service.TaskTemplate.LogDriver != nil && service.TaskTemplate.LogDriver.Name == "logentries" {
|
||||
return errdefs.InvalidParameter(errors.New("the logentries logging driver has been deprecated and removed"))
|
||||
}
|
||||
|
||||
rawVersion := r.URL.Query().Get("version")
|
||||
version, err := strconv.ParseUint(rawVersion, 10, 64)
|
||||
|
|
|
@ -62,6 +62,10 @@ func (daemon *Daemon) containerCreate(ctx context.Context, daemonCfg *configStor
|
|||
if opts.params.Config == nil {
|
||||
return containertypes.CreateResponse{}, errdefs.InvalidParameter(runconfig.ErrEmptyConfig)
|
||||
}
|
||||
// TODO(thaJeztah): remove logentries check and migration code in release v26.0.0.
|
||||
if opts.params.HostConfig != nil && opts.params.HostConfig.LogConfig.Type == "logentries" {
|
||||
return containertypes.CreateResponse{}, errdefs.InvalidParameter(fmt.Errorf("the logentries logging driver has been deprecated and removed"))
|
||||
}
|
||||
|
||||
// Normalize some defaults. Doing this "ad-hoc" here for now, as there's
|
||||
// only one field to migrate, but we should consider having a better
|
||||
|
|
|
@ -41,6 +41,7 @@ import (
|
|||
_ "github.com/docker/docker/daemon/graphdriver/register" // register graph drivers
|
||||
"github.com/docker/docker/daemon/images"
|
||||
dlogger "github.com/docker/docker/daemon/logger"
|
||||
"github.com/docker/docker/daemon/logger/local"
|
||||
"github.com/docker/docker/daemon/network"
|
||||
"github.com/docker/docker/daemon/snapshotter"
|
||||
"github.com/docker/docker/daemon/stats"
|
||||
|
@ -339,17 +340,31 @@ func (daemon *Daemon) restore(cfg *configStore) error {
|
|||
|
||||
baseLogger := log.G(context.TODO()).WithField("container", c.ID)
|
||||
|
||||
// Migrate containers that don't have the default ("no") restart-policy set.
|
||||
// The RestartPolicy.Name field may be empty for containers that were
|
||||
// created with versions before v25.0.0.
|
||||
//
|
||||
// We also need to set the MaximumRetryCount to 0, to prevent
|
||||
// validation from failing (MaximumRetryCount is not allowed if
|
||||
// no restart-policy ("none") is set).
|
||||
if c.HostConfig != nil && c.HostConfig.RestartPolicy.Name == "" {
|
||||
baseLogger.WithError(err).Debug("migrated restart-policy")
|
||||
c.HostConfig.RestartPolicy.Name = containertypes.RestartPolicyDisabled
|
||||
c.HostConfig.RestartPolicy.MaximumRetryCount = 0
|
||||
if c.HostConfig != nil {
|
||||
// Migrate containers that don't have the default ("no") restart-policy set.
|
||||
// The RestartPolicy.Name field may be empty for containers that were
|
||||
// created with versions before v25.0.0.
|
||||
//
|
||||
// We also need to set the MaximumRetryCount to 0, to prevent
|
||||
// validation from failing (MaximumRetryCount is not allowed if
|
||||
// no restart-policy ("none") is set).
|
||||
if c.HostConfig.RestartPolicy.Name == "" {
|
||||
baseLogger.Debug("migrated restart-policy")
|
||||
c.HostConfig.RestartPolicy.Name = containertypes.RestartPolicyDisabled
|
||||
c.HostConfig.RestartPolicy.MaximumRetryCount = 0
|
||||
}
|
||||
|
||||
// Migrate containers that use the deprecated (and now non-functional)
|
||||
// logentries driver. Update them to use the "local" logging driver
|
||||
// instead.
|
||||
//
|
||||
// TODO(thaJeztah): remove logentries check and migration code in release v26.0.0.
|
||||
if c.HostConfig.LogConfig.Type == "logentries" {
|
||||
baseLogger.Warn("migrated deprecated logentries logging driver")
|
||||
c.HostConfig.LogConfig = containertypes.LogConfig{
|
||||
Type: local.Name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := daemon.checkpointAndSave(c); err != nil {
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
_ "github.com/docker/docker/daemon/logger/journald"
|
||||
_ "github.com/docker/docker/daemon/logger/jsonfilelog"
|
||||
_ "github.com/docker/docker/daemon/logger/local"
|
||||
_ "github.com/docker/docker/daemon/logger/logentries"
|
||||
_ "github.com/docker/docker/daemon/logger/loggerutils/cache"
|
||||
_ "github.com/docker/docker/daemon/logger/splunk"
|
||||
_ "github.com/docker/docker/daemon/logger/syslog"
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
_ "github.com/docker/docker/daemon/logger/gcplogs"
|
||||
_ "github.com/docker/docker/daemon/logger/gelf"
|
||||
_ "github.com/docker/docker/daemon/logger/jsonfilelog"
|
||||
_ "github.com/docker/docker/daemon/logger/logentries"
|
||||
_ "github.com/docker/docker/daemon/logger/loggerutils/cache"
|
||||
_ "github.com/docker/docker/daemon/logger/splunk"
|
||||
_ "github.com/docker/docker/daemon/logger/syslog"
|
||||
|
|
|
@ -1,117 +0,0 @@
|
|||
// Package logentries provides the log driver for forwarding server logs
|
||||
// to logentries endpoints.
|
||||
package logentries // import "github.com/docker/docker/daemon/logger/logentries"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/bsphere/le_go"
|
||||
"github.com/containerd/log"
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type logentries struct {
|
||||
tag string
|
||||
containerID string
|
||||
containerName string
|
||||
writer *le_go.Logger
|
||||
extra map[string]string
|
||||
lineOnly bool
|
||||
}
|
||||
|
||||
const (
|
||||
name = "logentries"
|
||||
token = "logentries-token"
|
||||
lineonly = "line-only"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := logger.RegisterLogDriver(name, New); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := logger.RegisterLogOptValidator(name, ValidateLogOpt); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// New creates a logentries logger using the configuration passed in on
|
||||
// the context. The supported context configuration variable is
|
||||
// logentries-token.
|
||||
func New(info logger.Info) (logger.Logger, error) {
|
||||
log.G(context.TODO()).WithField("container", info.ContainerID).
|
||||
WithField("token", info.Config[token]).
|
||||
WithField("line-only", info.Config[lineonly]).
|
||||
Debug("logging driver logentries configured")
|
||||
|
||||
log, err := le_go.Connect(info.Config[token])
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error connecting to logentries")
|
||||
}
|
||||
var lineOnly bool
|
||||
if info.Config[lineonly] != "" {
|
||||
if lineOnly, err = strconv.ParseBool(info.Config[lineonly]); err != nil {
|
||||
return nil, errors.Wrap(err, "error parsing lineonly option")
|
||||
}
|
||||
}
|
||||
return &logentries{
|
||||
containerID: info.ContainerID,
|
||||
containerName: info.ContainerName,
|
||||
writer: log,
|
||||
lineOnly: lineOnly,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f *logentries) Log(msg *logger.Message) error {
|
||||
if !f.lineOnly {
|
||||
data := map[string]string{
|
||||
"container_id": f.containerID,
|
||||
"container_name": f.containerName,
|
||||
"source": msg.Source,
|
||||
"log": string(msg.Line),
|
||||
}
|
||||
for k, v := range f.extra {
|
||||
data[k] = v
|
||||
}
|
||||
ts := msg.Timestamp
|
||||
logger.PutMessage(msg)
|
||||
f.writer.Println(f.tag, ts, data)
|
||||
} else {
|
||||
line := string(msg.Line)
|
||||
logger.PutMessage(msg)
|
||||
f.writer.Println(line)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *logentries) Close() error {
|
||||
return f.writer.Close()
|
||||
}
|
||||
|
||||
func (f *logentries) Name() string {
|
||||
return name
|
||||
}
|
||||
|
||||
// ValidateLogOpt looks for logentries specific log option logentries-address.
|
||||
func ValidateLogOpt(cfg map[string]string) error {
|
||||
for key := range cfg {
|
||||
switch key {
|
||||
case "env":
|
||||
case "env-regex":
|
||||
case "labels":
|
||||
case "labels-regex":
|
||||
case "tag":
|
||||
case key:
|
||||
default:
|
||||
return fmt.Errorf("unknown log opt '%s' for logentries log driver", key)
|
||||
}
|
||||
}
|
||||
|
||||
if cfg[token] == "" {
|
||||
return fmt.Errorf("Missing logentries token")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -22,7 +22,6 @@ require (
|
|||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.24
|
||||
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.15.17
|
||||
github.com/aws/smithy-go v1.13.5
|
||||
github.com/bsphere/le_go v0.0.0-20200109081728-fc06dab2caa8
|
||||
github.com/cloudflare/cfssl v1.6.4
|
||||
github.com/containerd/cgroups/v3 v3.0.2
|
||||
github.com/containerd/containerd v1.7.11
|
||||
|
|
|
@ -236,8 +236,6 @@ github.com/bombsimon/wsl/v3 v3.0.0/go.mod h1:st10JtZYLE4D5sC7b8xV4zTKZwAQjCH/Hy2
|
|||
github.com/bombsimon/wsl/v3 v3.1.0/go.mod h1:st10JtZYLE4D5sC7b8xV4zTKZwAQjCH/Hy2Pm1FNZIc=
|
||||
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
|
||||
github.com/bshuster-repo/logrus-logstash-hook v0.4.1/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk=
|
||||
github.com/bsphere/le_go v0.0.0-20200109081728-fc06dab2caa8 h1:fcONpniVVbh9+duVZYYbJuc+yGGdLRxTqpk7pTTz/qI=
|
||||
github.com/bsphere/le_go v0.0.0-20200109081728-fc06dab2caa8/go.mod h1:GrjfimWtH8h8EqJSfbO+sTQYV/fAjL/VN7dMeU8XP2Y=
|
||||
github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
|
||||
github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50=
|
||||
github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
|
||||
|
|
23
vendor/github.com/bsphere/le_go/.gitignore
generated
vendored
23
vendor/github.com/bsphere/le_go/.gitignore
generated
vendored
|
@ -1,23 +0,0 @@
|
|||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
4
vendor/github.com/bsphere/le_go/.travis.yml
generated
vendored
4
vendor/github.com/bsphere/le_go/.travis.yml
generated
vendored
|
@ -1,4 +0,0 @@
|
|||
language: go
|
||||
|
||||
go:
|
||||
- 1.12.x
|
21
vendor/github.com/bsphere/le_go/LICENSE
generated
vendored
21
vendor/github.com/bsphere/le_go/LICENSE
generated
vendored
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2017 Gal Ben-Haim
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
37
vendor/github.com/bsphere/le_go/README.md
generated
vendored
37
vendor/github.com/bsphere/le_go/README.md
generated
vendored
|
@ -1,37 +0,0 @@
|
|||
le_go
|
||||
=====
|
||||
|
||||
Golang client library for logentries.com
|
||||
|
||||
It is compatible with http://golang.org/pkg/log/#Logger
|
||||
and also implements http://golang.org/pkg/io/#Writer
|
||||
|
||||
[](https://godoc.org/github.com/bsphere/le_go)
|
||||
|
||||
[](https://travis-ci.org/bsphere/le_go)
|
||||
|
||||
Usage
|
||||
-----
|
||||
Add a new manual TCP token log at [logentries.com](https://logentries.com/quick-start/) and copy the [token](https://logentries.com/doc/input-token/).
|
||||
|
||||
Installation: `go get github.com/bsphere/le_go`
|
||||
|
||||
**Note:** The Logger is blocking, it can be easily run in a goroutine by calling `go le.Println(...)`
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import "github.com/bsphere/le_go"
|
||||
|
||||
func main() {
|
||||
le, err := le_go.Connect("XXXX-XXXX-XXXX-XXXX") // replace with token
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer le.Close()
|
||||
|
||||
le.Println("another test message")
|
||||
}
|
||||
```
|
||||
|
228
vendor/github.com/bsphere/le_go/le.go
generated
vendored
228
vendor/github.com/bsphere/le_go/le.go
generated
vendored
|
@ -1,228 +0,0 @@
|
|||
// Package le_go provides a Golang client library for logging to
|
||||
// logentries.com over a TCP connection.
|
||||
//
|
||||
// it uses an access token for sending log events.
|
||||
package le_go
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Logger represents a Logentries logger,
|
||||
// it holds the open TCP connection, access token, prefix and flags.
|
||||
//
|
||||
// all Logger operations are thread safe and blocking,
|
||||
// log operations can be invoked in a non-blocking way by calling them from
|
||||
// a goroutine.
|
||||
type Logger struct {
|
||||
conn net.Conn
|
||||
flag int
|
||||
mu sync.Mutex
|
||||
prefix string
|
||||
token string
|
||||
buf []byte
|
||||
}
|
||||
|
||||
const lineSep = "\n"
|
||||
|
||||
// Connect creates a new Logger instance and opens a TCP connection to
|
||||
// logentries.com,
|
||||
// The token can be generated at logentries.com by adding a new log,
|
||||
// choosing manual configuration and token based TCP connection.
|
||||
func Connect(token string) (*Logger, error) {
|
||||
logger := Logger{
|
||||
token: token,
|
||||
}
|
||||
|
||||
if err := logger.openConnection(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &logger, nil
|
||||
}
|
||||
|
||||
// Close closes the TCP connection to logentries.com
|
||||
func (logger *Logger) Close() error {
|
||||
if logger.conn != nil {
|
||||
return logger.conn.Close()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Opens a TCP connection to logentries.com
|
||||
func (logger *Logger) openConnection() error {
|
||||
conn, err := tls.Dial("tcp", "data.logentries.com:443", &tls.Config{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.conn = conn
|
||||
return nil
|
||||
}
|
||||
|
||||
// It returns if the TCP connection to logentries.com is open
|
||||
func (logger *Logger) isOpenConnection() bool {
|
||||
if logger.conn == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
buf := make([]byte, 1)
|
||||
|
||||
logger.conn.SetReadDeadline(time.Now())
|
||||
|
||||
_, err := logger.conn.Read(buf)
|
||||
|
||||
switch err.(type) {
|
||||
case net.Error:
|
||||
if err.(net.Error).Timeout() == true {
|
||||
logger.conn.SetReadDeadline(time.Time{})
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// It ensures that the TCP connection to logentries.com is open.
|
||||
// If the connection is closed, a new one is opened.
|
||||
func (logger *Logger) ensureOpenConnection() error {
|
||||
if !logger.isOpenConnection() {
|
||||
if err := logger.openConnection(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Fatal is same as Print() but calls to os.Exit(1)
|
||||
func (logger *Logger) Fatal(v ...interface{}) {
|
||||
logger.Output(2, fmt.Sprint(v...))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Fatalf is same as Printf() but calls to os.Exit(1)
|
||||
func (logger *Logger) Fatalf(format string, v ...interface{}) {
|
||||
logger.Output(2, fmt.Sprintf(format, v...))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Fatalln is same as Println() but calls to os.Exit(1)
|
||||
func (logger *Logger) Fatalln(v ...interface{}) {
|
||||
logger.Output(2, fmt.Sprintln(v...))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Flags returns the logger flags
|
||||
func (logger *Logger) Flags() int {
|
||||
return logger.flag
|
||||
}
|
||||
|
||||
// Output does the actual writing to the TCP connection
|
||||
func (logger *Logger) Output(calldepth int, s string) error {
|
||||
var (
|
||||
err error
|
||||
waitPeriod = time.Millisecond
|
||||
)
|
||||
for {
|
||||
_, err = logger.Write([]byte(s))
|
||||
if err != nil {
|
||||
if connectionErr := logger.openConnection(); connectionErr != nil {
|
||||
return connectionErr
|
||||
}
|
||||
waitPeriod *= 2
|
||||
time.Sleep(waitPeriod)
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Panic is same as Print() but calls to panic
|
||||
func (logger *Logger) Panic(v ...interface{}) {
|
||||
s := fmt.Sprint(v...)
|
||||
logger.Output(2, s)
|
||||
panic(s)
|
||||
}
|
||||
|
||||
// Panicf is same as Printf() but calls to panic
|
||||
func (logger *Logger) Panicf(format string, v ...interface{}) {
|
||||
s := fmt.Sprintf(format, v...)
|
||||
logger.Output(2, s)
|
||||
panic(s)
|
||||
}
|
||||
|
||||
// Panicln is same as Println() but calls to panic
|
||||
func (logger *Logger) Panicln(v ...interface{}) {
|
||||
s := fmt.Sprintln(v...)
|
||||
logger.Output(2, s)
|
||||
panic(s)
|
||||
}
|
||||
|
||||
// Prefix returns the logger prefix
|
||||
func (logger *Logger) Prefix() string {
|
||||
return logger.prefix
|
||||
}
|
||||
|
||||
// Print logs a message
|
||||
func (logger *Logger) Print(v ...interface{}) error {
|
||||
return logger.Output(2, fmt.Sprint(v...))
|
||||
}
|
||||
|
||||
// Printf logs a formatted message
|
||||
func (logger *Logger) Printf(format string, v ...interface{}) error {
|
||||
return logger.Output(2, fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
// Println logs a message with a linebreak
|
||||
func (logger *Logger) Println(v ...interface{}) error {
|
||||
return logger.Output(2, fmt.Sprintln(v...))
|
||||
}
|
||||
|
||||
// SetFlags sets the logger flags
|
||||
func (logger *Logger) SetFlags(flag int) {
|
||||
logger.flag = flag
|
||||
}
|
||||
|
||||
// SetPrefix sets the logger prefix
|
||||
func (logger *Logger) SetPrefix(prefix string) {
|
||||
logger.prefix = prefix
|
||||
}
|
||||
|
||||
// Write writes a bytes array to the Logentries TCP connection,
|
||||
// it adds the access token and prefix and also replaces
|
||||
// line breaks with the unicode \u2028 character
|
||||
func (logger *Logger) Write(p []byte) (n int, err error) {
|
||||
logger.mu.Lock()
|
||||
if err := logger.ensureOpenConnection(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer logger.mu.Unlock()
|
||||
|
||||
logger.makeBuf(p)
|
||||
|
||||
return logger.conn.Write(logger.buf)
|
||||
}
|
||||
|
||||
// makeBuf constructs the logger buffer
|
||||
// it is not safe to be used from within multiple concurrent goroutines
|
||||
func (logger *Logger) makeBuf(p []byte) {
|
||||
count := strings.Count(string(p), lineSep)
|
||||
p = []byte(strings.Replace(string(p), lineSep, "\u2028", count-1))
|
||||
|
||||
logger.buf = logger.buf[:0]
|
||||
logger.buf = append(logger.buf, (logger.token + " ")...)
|
||||
logger.buf = append(logger.buf, (logger.prefix + " ")...)
|
||||
logger.buf = append(logger.buf, p...)
|
||||
|
||||
if !strings.HasSuffix(string(logger.buf), lineSep) {
|
||||
logger.buf = append(logger.buf, (lineSep)...)
|
||||
}
|
||||
}
|
3
vendor/modules.txt
vendored
3
vendor/modules.txt
vendored
|
@ -186,9 +186,6 @@ github.com/aws/smithy-go/transport/http/internal/io
|
|||
# github.com/beorn7/perks v1.0.1
|
||||
## explicit; go 1.11
|
||||
github.com/beorn7/perks/quantile
|
||||
# github.com/bsphere/le_go v0.0.0-20200109081728-fc06dab2caa8
|
||||
## explicit; go 1.12
|
||||
github.com/bsphere/le_go
|
||||
# github.com/cenkalti/backoff/v4 v4.2.1
|
||||
## explicit; go 1.18
|
||||
github.com/cenkalti/backoff/v4
|
||||
|
|
Loading…
Add table
Reference in a new issue