mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-18 07:36:24 -07:00
Prevent gclog.Println from adding an extra newline
Also add more thorough gclog testing
This commit is contained in:
parent
e6838817fd
commit
9ab597be64
3 changed files with 43 additions and 12 deletions
1
Makefile
1
Makefile
|
@ -41,6 +41,7 @@ clean:
|
|||
rm -f ${BIN}.exe
|
||||
rm -rf releases/
|
||||
rm -rf ${GOPATH}/src/${GOCHAN_PKG}
|
||||
rm -f pkg/gclog/logtest/*
|
||||
|
||||
dependencies:
|
||||
go get -v \
|
||||
|
|
|
@ -99,9 +99,9 @@ func (gcl *GcLogger) Println(flags int, v ...interface{}) string {
|
|||
logs := gcl.selectLogs(flags)
|
||||
for _, l := range logs {
|
||||
if l == os.Stdout {
|
||||
io.WriteString(l, str+"\n")
|
||||
io.WriteString(l, str)
|
||||
} else {
|
||||
io.WriteString(l, gcl.getPrefix()+str+"\n")
|
||||
io.WriteString(l, gcl.getPrefix()+str)
|
||||
}
|
||||
}
|
||||
if flags&LFatal > 0 {
|
||||
|
|
|
@ -1,18 +1,48 @@
|
|||
package gclog
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGochanLog(t *testing.T) {
|
||||
err := InitLogs("../access.log", "../error.log", "../staff.log", true)
|
||||
_, err := os.Stat("./logtest")
|
||||
if err != nil {
|
||||
if err = os.Mkdir("./logtest", 0755); err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
err = InitLogs("./logtest/access.log", "./logtest/error.log", "./logtest/staff.log", true)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
gclog.Print(LStdLog, "os.Stdout log")
|
||||
gclog.Print(LStdLog|LAccessLog|LErrorLog|LStaffLog, "all logs")
|
||||
gclog.Print(LAccessLog, "Access log")
|
||||
gclog.Print(LErrorLog, "Error log")
|
||||
gclog.Print(LStaffLog, "Staff log")
|
||||
gclog.Print(LAccessLog|LErrorLog, "Access and error log")
|
||||
gclog.Print(LAccessLog|LStaffLog|LFatal, "Fatal access and staff log")
|
||||
gclog.Print(LAccessLog, "This shouldn't be here")
|
||||
|
||||
// test Print usage
|
||||
gclog.Print(LStdLog, "os.Stdout log", "(Print)")
|
||||
gclog.Print(LStdLog|LAccessLog|LErrorLog|LStaffLog, "all logs", "(Print)")
|
||||
gclog.Print(LAccessLog, "Access log", "(Print)")
|
||||
gclog.Print(LErrorLog, "Error log", "(Print)")
|
||||
gclog.Print(LStaffLog, "Staff log", "(Print)")
|
||||
gclog.Print(LAccessLog|LErrorLog, "Access and error log", "(Print)")
|
||||
gclog.Print(LAccessLog|LStaffLog, "Access and staff log", "(Print)")
|
||||
|
||||
// test Printf usage
|
||||
gclog.Printf(LStdLog, "os.Stdout log %q", "(Println)")
|
||||
gclog.Printf(LStdLog|LAccessLog|LErrorLog|LStaffLog, "all logs %q", "(Printf)")
|
||||
gclog.Printf(LAccessLog, "Access log %q", "(Printf)")
|
||||
gclog.Printf(LErrorLog, "Error log %q", "(Printf)")
|
||||
gclog.Printf(LStaffLog, "Staff log %q", "(Printf)")
|
||||
gclog.Printf(LAccessLog|LErrorLog, "Access and error log %q", "(Printf)")
|
||||
gclog.Printf(LAccessLog|LStaffLog, "Access and staff log %q", "(Printf)")
|
||||
|
||||
// test Println usage (proper spacing and no extra newlines)
|
||||
gclog.Println(LStdLog, "os.Stdout log", "(Println)")
|
||||
gclog.Println(LStdLog|LAccessLog|LErrorLog|LStaffLog, "all logs", "(Println)")
|
||||
gclog.Println(LAccessLog, "Access log", "(Println)")
|
||||
gclog.Println(LErrorLog, "Error log", "(Println)")
|
||||
gclog.Println(LStaffLog, "Staff log", "(Println)")
|
||||
gclog.Println(LAccessLog|LErrorLog, "Access and error log", "(Println)")
|
||||
gclog.Println(LAccessLog|LStaffLog|LFatal, "Fatal access and staff log", "(Println)")
|
||||
gclog.Println(LAccessLog, "This shouldn't be here", "(Println)")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue