diff options
author | Unknwon <u@gogs.io> | 2017-03-23 18:34:25 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2017-03-23 18:34:25 -0400 |
commit | 8a3f4fc616086af121ab0c79aa3a24d30703acc9 (patch) | |
tree | c8424182196f8c3ffda81897e6e94d045cb79bde /vendor | |
parent | 66c1e6b0e8308068dbddaec03585f388875f4192 (diff) |
models: add config options for XORM logger (#3183)
Added new config section '[log.xorm]'.
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/gopkg.in/clog.v1/README.md | 4 | ||||
-rw-r--r-- | vendor/gopkg.in/clog.v1/clog.go | 2 | ||||
-rw-r--r-- | vendor/gopkg.in/clog.v1/file.go | 41 | ||||
-rw-r--r-- | vendor/gopkg.in/clog.v1/slack.go | 6 | ||||
-rw-r--r-- | vendor/vendor.json | 6 |
5 files changed, 50 insertions, 9 deletions
diff --git a/vendor/gopkg.in/clog.v1/README.md b/vendor/gopkg.in/clog.v1/README.md index 402eca05..e66c0abc 100644 --- a/vendor/gopkg.in/clog.v1/README.md +++ b/vendor/gopkg.in/clog.v1/README.md @@ -28,7 +28,7 @@ Please apply `-u` flag to update in the future. ## Getting Started -Clog currently has two builtin logger adapters: `console`, `file` and `slack`. +Clog currently has three builtin logger adapters: `console`, `file` and `slack`. It is extremely easy to create one with all default settings. Generally, you would want to create new logger inside `init` or `main` function. @@ -138,6 +138,8 @@ Slack logger is also supported in a simple way: ... ``` +This logger also works for [Discord Slack](https://discordapp.com/developers/docs/resources/webhook#execute-slackcompatible-webhook) endpoint. + ## Credits - Avatar is a modified version based on [egonelbre/gophers' scientist](https://github.com/egonelbre/gophers/blob/master/vector/science/scientist.svg). diff --git a/vendor/gopkg.in/clog.v1/clog.go b/vendor/gopkg.in/clog.v1/clog.go index 8dbdf228..c1797fa9 100644 --- a/vendor/gopkg.in/clog.v1/clog.go +++ b/vendor/gopkg.in/clog.v1/clog.go @@ -24,7 +24,7 @@ import ( ) const ( - _VERSION = "1.0.2" + _VERSION = "1.1.0" ) // Version returns current version of the package. diff --git a/vendor/gopkg.in/clog.v1/file.go b/vendor/gopkg.in/clog.v1/file.go index 27a36efa..a0157d40 100644 --- a/vendor/gopkg.in/clog.v1/file.go +++ b/vendor/gopkg.in/clog.v1/file.go @@ -17,6 +17,7 @@ package clog import ( "bytes" "fmt" + "io" "io/ioutil" "log" "os" @@ -58,6 +59,9 @@ type FileConfig struct { } type file struct { + // Indicates whether object is been used in standalone mode. + standalone bool + *log.Logger Adapter @@ -77,6 +81,21 @@ func newFile() Logger { } } +// NewFileWriter returns an io.Writer for synchronized file logger in standalone mode. +func NewFileWriter(filename string, cfg FileRotationConfig) (io.Writer, error) { + f := &file{ + standalone: true, + } + if err := f.Init(FileConfig{ + Filename: filename, + FileRotationConfig: cfg, + }); err != nil { + return nil, err + } + + return f, nil +} + func (f *file) Level() LEVEL { return f.level } var newLineBytes = []byte("\n") @@ -196,7 +215,9 @@ func (f *file) Init(v interface{}) (err error) { f.initRotate() } - f.msgChan = make(chan *Message, cfg.BufferSize) + if !f.standalone { + f.msgChan = make(chan *Message, cfg.BufferSize) + } return nil } @@ -205,11 +226,15 @@ func (f *file) ExchangeChans(errorChan chan<- error) chan *Message { return f.msgChan } -func (f *file) write(msg *Message) { +func (f *file) write(msg *Message) int { f.Logger.Print(msg.Body) + bytesWrote := len(msg.Body) + if !f.standalone { + bytesWrote += LOG_PREFIX_LENGTH + } if f.rotate.Rotate { - f.currentSize += int64(LOG_PREFIX_LENGTH + len(msg.Body)) + f.currentSize += int64(bytesWrote) f.currentLines++ // TODO: should I care if log message itself contains new lines? var ( @@ -243,6 +268,16 @@ func (f *file) write(msg *Message) { f.currentLines = 0 } } + return bytesWrote +} + +var _ io.Writer = new(file) + +// Write implements method of io.Writer interface. +func (f *file) Write(p []byte) (int, error) { + return f.write(&Message{ + Body: string(p), + }), nil } func (f *file) Start() { diff --git a/vendor/gopkg.in/clog.v1/slack.go b/vendor/gopkg.in/clog.v1/slack.go index 33264e93..93c5e651 100644 --- a/vendor/gopkg.in/clog.v1/slack.go +++ b/vendor/gopkg.in/clog.v1/slack.go @@ -92,8 +92,12 @@ func (s *slack) ExchangeChans(errorChan chan<- error) chan *Message { return s.msgChan } +func buildSlackAttachment(msg *Message) string { + return fmt.Sprintf(_SLACK_ATTACHMENT, msg.Body, slackColors[msg.Level]) +} + func (s *slack) write(msg *Message) { - attachment := fmt.Sprintf(_SLACK_ATTACHMENT, msg.Body, slackColors[msg.Level]) + attachment := buildSlackAttachment(msg) resp, err := http.Post(s.url, "application/json", bytes.NewReader([]byte(attachment))) if err != nil { s.errorChan <- fmt.Errorf("slack: %v", err) diff --git a/vendor/vendor.json b/vendor/vendor.json index 8b7893eb..426748ea 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -525,10 +525,10 @@ "revisionTime": "2015-09-24T05:17:56Z" }, { - "checksumSHA1": "TlOZMrb/wY8vsDIGkXlmxsbDLP0=", + "checksumSHA1": "ZJBrUSDBKgkXID1MVRkXSTlmOh4=", "path": "gopkg.in/clog.v1", - "revision": "bf4bf4a49c663cd0963f8775a4b60d30a75098d1", - "revisionTime": "2017-02-17T23:04:09Z" + "revision": "ff5a366d133e02b3d411dbe3854ebd912a434c7f", + "revisionTime": "2017-03-23T22:33:02Z" }, { "checksumSHA1": "LIu3jihd3edOyIsJJK3V6vx2UZg=", |