]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/log.go
Move .seen and .hdr to subdirectories
[nncp.git] / src / log.go
index 9a8d2e7505b7fc4b5eecdeb77d4d2b49dbab12dd..a2e72b238f61e1a570e194d91edca8c58263c80b 100644 (file)
@@ -21,6 +21,7 @@ import (
        "bytes"
        "fmt"
        "os"
+       "sync"
        "time"
 
        "go.cypherpunks.ru/recfile"
@@ -29,7 +30,10 @@ import (
 
 const LogFdPrefix = "FD:"
 
-var LogFd *os.File
+var (
+       LogFd     *os.File
+       LogFdLock sync.Mutex
+)
 
 type LE struct {
        K string
@@ -69,7 +73,9 @@ func (les LEs) Rec() string {
 
 func (ctx *Ctx) Log(rec string) {
        if LogFd != nil {
+               LogFdLock.Lock()
                LogFd.WriteString(rec)
+               LogFdLock.Unlock()
                return
        }
        fdLock, err := os.OpenFile(
@@ -98,8 +104,8 @@ func (ctx *Ctx) Log(rec string) {
                fmt.Fprintln(os.Stderr, "Can not open log:", err)
                return
        }
-       fd.WriteString(rec) // #nosec G104
-       fd.Close()          // #nosec G104
+       fd.WriteString(rec)
+       fd.Close()
 }
 
 func (ctx *Ctx) LogD(who string, les LEs, msg func(LEs) string) {