mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 13:18:53 +00:00
logtail,logpolicy: tweak minor cosmetic things
Just reading the code again in prep for some alloc reductions. Change-Id: I065226ea794b7ec7144c2b15942d35131c9313a8 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
ab60f28227
commit
48e73e147a
@@ -21,6 +21,8 @@ type Buffer interface {
|
||||
TryReadLine() ([]byte, error)
|
||||
|
||||
// Write writes a log line into the ring buffer.
|
||||
//
|
||||
// Write takes ownership of the provided slice.
|
||||
Write([]byte) (int, error)
|
||||
}
|
||||
|
||||
|
@@ -167,8 +167,9 @@ type Logger struct {
|
||||
|
||||
procID uint32
|
||||
includeProcSequence bool
|
||||
writeLock sync.Mutex // guards increments of procSequence
|
||||
procSequence uint64
|
||||
|
||||
writeLock sync.Mutex // guards increments of procSequence
|
||||
procSequence uint64
|
||||
|
||||
shutdownStart chan struct{} // closed when shutdown begins
|
||||
shutdownDone chan struct{} // closed when shutdown complete
|
||||
@@ -454,7 +455,7 @@ func Disable() {
|
||||
logtailDisabled.Set(true)
|
||||
}
|
||||
|
||||
func (l *Logger) send(jsonBlob []byte) (int, error) {
|
||||
func (l *Logger) sendLocked(jsonBlob []byte) (int, error) {
|
||||
if logtailDisabled.Get() {
|
||||
return len(jsonBlob), nil
|
||||
}
|
||||
@@ -578,7 +579,7 @@ func (l *Logger) encodeText(buf []byte, skipClientTime bool, procID uint32, proc
|
||||
return b
|
||||
}
|
||||
|
||||
func (l *Logger) encode(buf []byte, level int) []byte {
|
||||
func (l *Logger) encodeLocked(buf []byte, level int) []byte {
|
||||
if l.includeProcSequence {
|
||||
l.procSequence++
|
||||
}
|
||||
@@ -659,10 +660,12 @@ func (l *Logger) Write(buf []byte) (int, error) {
|
||||
l.stderr.Write(withNL)
|
||||
}
|
||||
}
|
||||
|
||||
l.writeLock.Lock()
|
||||
b := l.encode(buf, level)
|
||||
_, err := l.send(b)
|
||||
l.writeLock.Unlock()
|
||||
defer l.writeLock.Unlock()
|
||||
|
||||
b := l.encodeLocked(buf, level)
|
||||
_, err := l.sendLocked(b)
|
||||
return len(buf), err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user