mirror of
https://gitea.com/gitea/log
synced 2025-10-05 16:32:46 +02:00
stylistic-fixes (#17)
This commit is contained in:
committed by
techknowlogick
parent
d6e06556cd
commit
f316138381
12
colors.go
12
colors.go
@@ -208,7 +208,7 @@ normalLoop:
|
||||
|
||||
if i > lasti {
|
||||
written, err := c.w.Write(bytes[lasti:i])
|
||||
totalWritten = totalWritten + written
|
||||
totalWritten += written
|
||||
if err != nil {
|
||||
return totalWritten, err
|
||||
}
|
||||
@@ -243,7 +243,7 @@ normalLoop:
|
||||
if bytes[j] == 'm' {
|
||||
if c.mode == allowColor {
|
||||
written, err := c.w.Write(bytes[i : j+1])
|
||||
totalWritten = totalWritten + written
|
||||
totalWritten += written
|
||||
if err != nil {
|
||||
return totalWritten, err
|
||||
}
|
||||
@@ -278,7 +278,7 @@ func ColorSprintf(format string, args ...interface{}) string {
|
||||
}
|
||||
return fmt.Sprintf(format, v...)
|
||||
}
|
||||
return fmt.Sprintf(format)
|
||||
return format
|
||||
}
|
||||
|
||||
// ColorFprintf will write to the provided writer similar to ColorSprintf
|
||||
@@ -290,7 +290,7 @@ func ColorFprintf(w io.Writer, format string, args ...interface{}) (int, error)
|
||||
}
|
||||
return fmt.Fprintf(w, format, v...)
|
||||
}
|
||||
return fmt.Fprintf(w, format)
|
||||
return fmt.Fprint(w, format)
|
||||
}
|
||||
|
||||
// ColorFormatted structs provide their own colored string when formatted with ColorSprintf
|
||||
@@ -378,9 +378,9 @@ func (cv *ColoredValue) Format(s fmt.State, c rune) {
|
||||
return
|
||||
}
|
||||
}
|
||||
s.Write([]byte(*cv.colorBytes))
|
||||
s.Write(*cv.colorBytes)
|
||||
fmt.Fprintf(&protectedANSIWriter{w: s}, fmtString(s, c), *(cv.Value))
|
||||
s.Write([]byte(*cv.resetBytes))
|
||||
s.Write(*cv.resetBytes)
|
||||
}
|
||||
|
||||
// SetColorBytes will allow a user to set the colorBytes of a colored value
|
||||
|
4
conn.go
4
conn.go
@@ -67,7 +67,9 @@ func (i *connWriter) connect() error {
|
||||
}
|
||||
|
||||
if tcpConn, ok := conn.(*net.TCPConn); ok {
|
||||
tcpConn.SetKeepAlive(true)
|
||||
if err := tcpConn.SetKeepAlive(true); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
i.innerWriter = conn
|
||||
|
@@ -24,7 +24,6 @@ func listenReadAndClose(t *testing.T, l net.Listener, expected string) {
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expected, string(written))
|
||||
return
|
||||
}
|
||||
|
||||
func TestConnLogger(t *testing.T) {
|
||||
|
4
event.go
4
event.go
@@ -79,7 +79,7 @@ func (l *ChannelledLog) Start() {
|
||||
return
|
||||
}
|
||||
l.loggerProvider.Flush()
|
||||
case _, _ = <-l.close:
|
||||
case <-l.close:
|
||||
l.closeLogger()
|
||||
return
|
||||
}
|
||||
@@ -104,7 +104,6 @@ func (l *ChannelledLog) closeLogger() {
|
||||
l.loggerProvider.Flush()
|
||||
l.loggerProvider.Close()
|
||||
l.closed <- true
|
||||
return
|
||||
}
|
||||
|
||||
// Close this ChannelledLog
|
||||
@@ -228,7 +227,6 @@ func (m *MultiChannelledLog) closeLoggers() {
|
||||
}
|
||||
m.mutex.Unlock()
|
||||
m.closed <- true
|
||||
return
|
||||
}
|
||||
|
||||
// Start processing the MultiChannelledLog
|
||||
|
4
file.go
4
file.go
@@ -223,7 +223,7 @@ func compressOldLogFile(fname string, compressionLevel int) error {
|
||||
|
||||
func (log *FileLogger) deleteOldLog() {
|
||||
dir := filepath.Dir(log.Filename)
|
||||
filepath.Walk(dir, func(path string, info os.FileInfo, err error) (returnErr error) {
|
||||
_ = filepath.Walk(dir, func(path string, info os.FileInfo, err error) (returnErr error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
returnErr = fmt.Errorf("Unable to delete old log '%s', error: %+v", path, r)
|
||||
@@ -246,7 +246,7 @@ func (log *FileLogger) deleteOldLog() {
|
||||
// there are no buffering messages in file logger in memory.
|
||||
// flush file means sync file from disk.
|
||||
func (log *FileLogger) Flush() {
|
||||
log.mw.fd.Sync()
|
||||
_ = log.mw.fd.Sync()
|
||||
}
|
||||
|
||||
// GetName returns the default name for this implementation
|
||||
|
@@ -103,7 +103,7 @@ func TestFileLogger(t *testing.T) {
|
||||
assert.Equal(t, expected, string(logData))
|
||||
|
||||
event.level = WARN
|
||||
expected = expected + fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg)
|
||||
expected += fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg)
|
||||
fileLogger.LogEvent(&event)
|
||||
fileLogger.Flush()
|
||||
logData, err = ioutil.ReadFile(filename)
|
||||
@@ -130,7 +130,7 @@ func TestFileLogger(t *testing.T) {
|
||||
err = realFileLogger.DoRotate()
|
||||
assert.Error(t, err)
|
||||
|
||||
expected = expected + fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg)
|
||||
expected += fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg)
|
||||
fileLogger.LogEvent(&event)
|
||||
fileLogger.Flush()
|
||||
logData, err = ioutil.ReadFile(filename)
|
||||
@@ -138,7 +138,7 @@ func TestFileLogger(t *testing.T) {
|
||||
assert.Equal(t, expected, string(logData))
|
||||
|
||||
// Should fail to rotate
|
||||
expected = expected + fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg)
|
||||
expected += fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg)
|
||||
fileLogger.LogEvent(&event)
|
||||
fileLogger.Flush()
|
||||
logData, err = ioutil.ReadFile(filename)
|
||||
@@ -188,7 +188,7 @@ func TestCompressFileLogger(t *testing.T) {
|
||||
assert.Equal(t, expected, string(logData))
|
||||
|
||||
event.level = WARN
|
||||
expected = expected + fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg)
|
||||
expected += fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg)
|
||||
fileLogger.LogEvent(&event)
|
||||
fileLogger.Flush()
|
||||
logData, err = ioutil.ReadFile(filename)
|
||||
|
1
go.sum
1
go.sum
@@ -4,6 +4,7 @@ github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc
|
||||
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
|
2
level.go
2
level.go
@@ -101,7 +101,7 @@ func (l *Level) UnmarshalJSON(b []byte) error {
|
||||
|
||||
switch v := tmp.(type) {
|
||||
case string:
|
||||
*l = FromString(string(v))
|
||||
*l = FromString(v)
|
||||
case int:
|
||||
*l = FromString(Level(v).String())
|
||||
default:
|
||||
|
1
log.go
1
log.go
@@ -1,4 +1,5 @@
|
||||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
|
4
smtp.go
4
smtp.go
@@ -11,10 +11,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
subjectPhrase = "Diagnostic message from server"
|
||||
)
|
||||
|
||||
type smtpWriter struct {
|
||||
owner *SMTPLogger
|
||||
}
|
||||
|
@@ -203,7 +203,7 @@ func (logger *WriterLogger) createMsg(buf *[]byte, event *Event) {
|
||||
(&protectedANSIWriter{
|
||||
w: &baw,
|
||||
mode: pawMode,
|
||||
}).Write([]byte(msg))
|
||||
}).Write(msg)
|
||||
*buf = baw
|
||||
|
||||
if event.stacktrace != "" && logger.StacktraceLevel <= event.level {
|
||||
@@ -252,10 +252,7 @@ func (logger *WriterLogger) Match(event *Event) bool {
|
||||
mode: removeColor,
|
||||
}).Write([]byte(event.msg))
|
||||
msg = baw
|
||||
if logger.regexp.Match(msg) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return logger.regexp.Match(msg)
|
||||
}
|
||||
|
||||
// Close the base logger
|
||||
|
Reference in New Issue
Block a user