mirror of
https://github.com/taigrr/log-socket
synced 2025-01-18 04:53:14 -08:00
make pass gofumpt
This commit is contained in:
parent
2492509b6b
commit
e21fb8a614
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
|||||||
Copyright (C) 2019-2021 by Tai Groot <tai@taigrr.com>
|
Copyright (C) 2019-2022 by Tai Groot <tai@taigrr.com>
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted.
|
purpose with or without fee is hereby granted.
|
||||||
|
22
log/log.go
22
log/log.go
@ -26,18 +26,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) logStdErr() {
|
func (c *Client) logStdErr() {
|
||||||
for {
|
for e := range c.writer {
|
||||||
select {
|
if e.level >= c.LogLevel {
|
||||||
case e, more := <-c.writer:
|
fmt.Fprintf(os.Stderr, "%s\t%s\t%s\t%s\n", e.Timestamp.String(), e.Level, e.Output, e.File)
|
||||||
if e.level >= c.LogLevel {
|
|
||||||
fmt.Fprintf(os.Stderr, "%s\t%s\t%s\t%s\n", e.Timestamp.String(), e.Level, e.Output, e.File)
|
|
||||||
}
|
|
||||||
if !more {
|
|
||||||
stderrFinished <- true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stderrFinished <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateClient() *Client {
|
func CreateClient() *Client {
|
||||||
@ -61,7 +55,7 @@ func Flush() {
|
|||||||
func (c *Client) Destroy() error {
|
func (c *Client) Destroy() error {
|
||||||
var otherClients []*Client
|
var otherClients []*Client
|
||||||
if !c.initialized {
|
if !c.initialized {
|
||||||
panic(errors.New("Cannot delete uninitialized client, did you use CreateClient?"))
|
panic(errors.New("cannot delete uninitialized client, did you use CreateClient?"))
|
||||||
}
|
}
|
||||||
sliceTex.Lock()
|
sliceTex.Lock()
|
||||||
c.writer = nil
|
c.writer = nil
|
||||||
@ -78,7 +72,7 @@ func (c *Client) Destroy() error {
|
|||||||
|
|
||||||
func (c *Client) GetLogLevel() Level {
|
func (c *Client) GetLogLevel() Level {
|
||||||
if !c.initialized {
|
if !c.initialized {
|
||||||
panic(errors.New("Cannot get level for uninitialized client, use CreateClient instead"))
|
panic(errors.New("cannot get level for uninitialized client, use CreateClient instead"))
|
||||||
}
|
}
|
||||||
return c.LogLevel
|
return c.LogLevel
|
||||||
}
|
}
|
||||||
@ -109,14 +103,14 @@ func SetLogLevel(level Level) {
|
|||||||
// SetLogLevel set log level of logger
|
// SetLogLevel set log level of logger
|
||||||
func (c *Client) SetLogLevel(level Level) {
|
func (c *Client) SetLogLevel(level Level) {
|
||||||
if !c.initialized {
|
if !c.initialized {
|
||||||
panic(errors.New("Cannot set level for uninitialized client, use CreateClient instead"))
|
panic(errors.New("cannot set level for uninitialized client, use CreateClient instead"))
|
||||||
}
|
}
|
||||||
c.LogLevel = level
|
c.LogLevel = level
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Get() Entry {
|
func (c *Client) Get() Entry {
|
||||||
if !c.initialized {
|
if !c.initialized {
|
||||||
panic(errors.New("Cannot get logs for uninitialized client, did you use CreateClient?"))
|
panic(errors.New("cannot get logs for uninitialized client, did you use CreateClient?"))
|
||||||
}
|
}
|
||||||
return <-c.writer
|
return <-c.writer
|
||||||
}
|
}
|
||||||
|
@ -55,8 +55,7 @@ func BenchmarkDebugSerial(b *testing.B) {
|
|||||||
// Trace ensure logs come out in the right order
|
// Trace ensure logs come out in the right order
|
||||||
func TestOrder(t *testing.T) {
|
func TestOrder(t *testing.T) {
|
||||||
testString := "Testing trace: "
|
testString := "Testing trace: "
|
||||||
var c *Client
|
c := CreateClient()
|
||||||
c = CreateClient()
|
|
||||||
c.SetLogLevel(LTrace)
|
c.SetLogLevel(LTrace)
|
||||||
|
|
||||||
for i := 0; i < 5000; i++ {
|
for i := 0; i < 5000; i++ {
|
||||||
|
@ -25,7 +25,7 @@ func LogSocketHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
logger.Info("Websocket client attached.")
|
logger.Info("Websocket client attached.")
|
||||||
for {
|
for {
|
||||||
logEvent := lc.Get()
|
logEvent := lc.Get()
|
||||||
logJSON, err := json.Marshal(logEvent)
|
logJSON, _ := json.Marshal(logEvent)
|
||||||
err = c.WriteMessage(websocket.TextMessage, logJSON)
|
err = c.WriteMessage(websocket.TextMessage, logJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("write:", err)
|
logger.Error("write:", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user