Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: client/internal/logdog/butler/output/log/logOutput.go

Issue 1211053004: LogDog: Add Butler Output package. (Closed) Base URL: https://github.com/luci/luci-go@logdog-review-streamserver
Patch Set: Relocate butlerproto to common, document. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/internal/logdog/butler/output/log/doc.go ('k') | client/internal/logdog/butler/output/output.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/internal/logdog/butler/output/log/logOutput.go
diff --git a/client/internal/logdog/butler/output/log/logOutput.go b/client/internal/logdog/butler/output/log/logOutput.go
new file mode 100644
index 0000000000000000000000000000000000000000..2ab073c61c5a3364122ce4091de5f78e17a22275
--- /dev/null
+++ b/client/internal/logdog/butler/output/log/logOutput.go
@@ -0,0 +1,99 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package log
+
+import (
+ "encoding/hex"
+ "strconv"
+ "sync"
+
+ "github.com/golang/protobuf/proto"
+ "github.com/luci/luci-go/client/internal/logdog/butler/output"
+ "github.com/luci/luci-go/common/logdog/protocol"
+ "github.com/luci/luci-go/common/logdog/types"
+ log "github.com/luci/luci-go/common/logging"
+ "golang.org/x/net/context"
+)
+
+// logOutput is an Output implementation that logs messages to its contexts'
+// Logger instance.
+type logOutput struct {
+ sync.Mutex
+ ctx context.Context
+
+ // bundleSize is the maximum size of the Butler bundle to use.
+ bundleSize int
+
+ stats output.StatsBase
+}
+
+// logOutput implements output.Output.
+var _ output.Output = (*logOutput)(nil)
+
+// New instantes a new log output instance.
+func New(ctx context.Context, bundleSize int) output.Output {
+ o := logOutput{
+ ctx: ctx,
+ bundleSize: bundleSize,
+ }
+ o.ctx = log.SetFields(o.ctx, log.Fields{
+ "output": &o,
+ })
+ return &o
+}
+
+func (o *logOutput) SendBundle(bundle *protocol.ButlerLogBundle) error {
+ o.Lock()
+ defer o.Unlock()
+
+ for _, e := range bundle.Entries {
+ path := types.StreamName(e.Desc.Prefix).Join(types.StreamName(e.Desc.Name))
+ ctx := log.SetField(o.ctx, "streamPath", path)
+
+ log.Fields{
+ "count": len(e.Logs),
+ "descriptor": e.Desc.String(),
+ }.Infof(ctx, "Received stream logs.")
+
+ for _, le := range e.Logs {
+ log.Fields{
+ "timeOffset": le.TimeOffset.Duration(),
+ "prefixIndex": le.PrefixIndex,
+ "streamIndex": le.StreamIndex,
+ "sequence": le.Sequence,
+ }.Infof(ctx, "Received message.")
+ if c := le.GetText(); c != nil {
+ for idx, l := range c.Lines {
+ log.Infof(ctx, "Line %d) %s (%s)", idx, l.Value, strconv.Quote(l.Delimiter))
+ }
+ }
+ if c := le.GetBinary(); c != nil {
+ log.Infof(ctx, "Binary) %s", hex.EncodeToString(c.Data))
+ }
+ if c := le.GetDatagram(); c != nil {
+ log.Infof(ctx, "Datagram %d: %s", c.Size, hex.EncodeToString(c.Data))
+ }
+
+ o.stats.F.SentMessages++
+ }
+ }
+ o.stats.F.SentBytes += proto.Size(bundle)
+
+ return nil
+}
+
+func (o *logOutput) MaxSize() int {
+ return o.bundleSize
+}
+
+func (o *logOutput) Stats() output.Stats {
+ o.Lock()
+ defer o.Unlock()
+
+ st := o.stats
+ return &st
+}
+
+func (o *logOutput) Close() {}
« no previous file with comments | « client/internal/logdog/butler/output/log/doc.go ('k') | client/internal/logdog/butler/output/output.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698