Skip to content

Commit

Permalink
make lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Feb 11, 2021
1 parent c3e458d commit 54f3df7
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 20 deletions.
14 changes: 8 additions & 6 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ func (w *FileWriter) Rotate() (err error) {

func (w *FileWriter) rotate() (err error) {
var file *os.File
file, err = os.OpenFile(w.fileargs(timeNow()))
name, flag, perm := w.fileargs(timeNow())
file, err = os.OpenFile(name, flag, perm)
if err != nil {
return err
}
Expand All @@ -165,14 +166,14 @@ func (w *FileWriter) rotate() (err error) {
go func(newname string) {
os.Remove(w.Filename)
if !w.ProcessID {
os.Symlink(filepath.Base(newname), w.Filename)
_ = os.Symlink(filepath.Base(newname), w.Filename)
}

uid, _ := strconv.Atoi(os.Getenv("SUDO_UID"))
gid, _ := strconv.Atoi(os.Getenv("SUDO_GID"))
if uid != 0 && gid != 0 && os.Geteuid() == 0 {
os.Lchown(w.Filename, uid, gid)
os.Chown(newname, uid, gid)
_ = os.Lchown(w.Filename, uid, gid)
_ = os.Chown(newname, uid, gid)
}

dir := filepath.Dir(w.Filename)
Expand Down Expand Up @@ -216,15 +217,16 @@ func (w *FileWriter) rotate() (err error) {
}

func (w *FileWriter) create() (err error) {
w.file, err = os.OpenFile(w.fileargs(timeNow()))
name, flag, perm := w.fileargs(timeNow())
w.file, err = os.OpenFile(name, flag, perm)
if err != nil {
return err
}
w.size = 0

os.Remove(w.Filename)
if !w.ProcessID {
os.Symlink(filepath.Base(w.file.Name()), w.Filename)
_ = os.Symlink(filepath.Base(w.file.Name()), w.Filename)
}

return
Expand Down
14 changes: 7 additions & 7 deletions file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestFileWriter(t *testing.T) {
t.Fatalf("file writer error: %+v", err)
}

// w.Rotate()
// _ = w.Rotate()
w.Close()

matches, err := filepath.Glob("file-output.*.log")
Expand Down Expand Up @@ -94,12 +94,12 @@ func TestFileWriterEnsureFolder(t *testing.T) {

remove(filepath.Dir(filename))

_, err := fmt.Fprintf(w, text1)
_, err := fmt.Fprint(w, text1)
if err != nil {
t.Logf("file writer return error: %+v", err)
}

_, err = fmt.Fprintf(w, text2)
_, err = fmt.Fprint(w, text2)
if err != nil {
t.Logf("file writer return error: %+v", err)
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestFileWriterHostname(t *testing.T) {

time.Sleep(time.Second)
os.Setenv("USER", "root")
w.Rotate()
_ = w.Rotate()
w.Close()

_, err = wlprintf(w, InfoLevel, text2)
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestFileWriterRotate(t *testing.T) {
}

time.Sleep(time.Second)
w.Rotate()
_ = w.Rotate()

// text 2
_, err = wlprintf(w, InfoLevel, text2)
Expand Down Expand Up @@ -300,10 +300,10 @@ func TestFileWriterBackups(t *testing.T) {
}

time.Sleep(time.Second)
w.Rotate()
_ = w.Rotate()

time.Sleep(time.Second)
w.Rotate()
_ = w.Rotate()
w.Close()

matches, err := filepath.Glob("file-backup.*.log")
Expand Down
1 change: 1 addition & 0 deletions formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func formatterArgsPos(key string) (pos int) {
func parseFormatterArgs(json []byte, args *FormatterArgs) {
// treat formatter args as []string
const size = int(unsafe.Sizeof(FormatterArgs{}) / unsafe.Sizeof(""))
// nolint
slice := *(*[]string)(unsafe.Pointer(&reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(args)), Len: size, Cap: size,
}))
Expand Down
2 changes: 1 addition & 1 deletion journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (w *JournalWriter) WriteEntry(e *Entry) (n int, err error) {
print := func(w io.Writer, name, value string) {
if strings.ContainsRune(value, '\n') {
fmt.Fprintln(w, name)
binary.Write(w, binary.LittleEndian, uint64(len(value)))
_ = binary.Write(w, binary.LittleEndian, uint64(len(value)))
fmt.Fprintln(w, value)
} else {
fmt.Fprintf(w, "%s=%s\n", name, value)
Expand Down
6 changes: 2 additions & 4 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ func (l *Logger) WithLevel(level Level) (e *Entry) {
// SetLevel changes logger default level.
func (l *Logger) SetLevel(level Level) {
atomic.StoreUint32((*uint32)(&l.Level), uint32(level))
return
}

// Printf sends a log entry without extra field. Arguments are handled in the manner of fmt.Printf.
Expand Down Expand Up @@ -1222,7 +1221,7 @@ func (e *Entry) Msg(msg string) {
} else {
e.buf = append(e.buf, '}', '\n')
}
e.w.WriteEntry(e)
_, _ = e.w.WriteEntry(e)
if (e.Level == FatalLevel) && notTest {
os.Exit(255)
}
Expand Down Expand Up @@ -1377,6 +1376,7 @@ func (e *Entry) string(s string) {
for _, c := range []byte(s) {
if escapes[c] {
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
// nolint
b := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
Data: sh.Data, Len: sh.Len, Cap: sh.Len,
}))
Expand All @@ -1385,7 +1385,6 @@ func (e *Entry) string(s string) {
}
}
e.buf = append(e.buf, s...)
return
}

func (e *Entry) bytes(b []byte) {
Expand All @@ -1396,7 +1395,6 @@ func (e *Entry) bytes(b []byte) {
}
}
e.buf = append(e.buf, b...)
return
}

// Interface adds the field key with i marshaled using reflection.
Expand Down
2 changes: 1 addition & 1 deletion multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (w *MultiWriter) WriteEntry(e *Entry) (n int, err error) {
}

if w.ConsoleWriter != nil && e.Level >= w.ConsoleLevel {
w.ConsoleWriter.WriteEntry(e)
_, _ = w.ConsoleWriter.WriteEntry(e)
}

return
Expand Down
2 changes: 1 addition & 1 deletion tsv.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (e *TSVEntry) Msg() {
if len(e.buf) != 0 {
e.buf[len(e.buf)-1] = '\n'
}
e.w.Write(e.buf)
_, _ = e.w.Write(e.buf)
if cap(e.buf) <= bbcap {
tepool.Put(e)
}
Expand Down

0 comments on commit 54f3df7

Please sign in to comment.