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

Unified Diff: go/src/infra/libs/logging/go-logging.go

Issue 1149313002: go: Replace Logrus with go-logging. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 7 months 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
Index: go/src/infra/libs/logging/go-logging.go
diff --git a/go/src/infra/libs/logging/go-logging.go b/go/src/infra/libs/logging/go-logging.go
new file mode 100644
index 0000000000000000000000000000000000000000..7a9839f558cb67f1ef666a538b6870b8b94d5416
--- /dev/null
+++ b/go/src/infra/libs/logging/go-logging.go
@@ -0,0 +1,37 @@
+// Copyright 2014 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.
+
+// +build !appengine
+
+package logging
+
+import (
+ "os"
+
+ "github.com/op/go-logging"
+)
+
+const fmt string = "%{color}[P%{pid} %{time:15:04:05.000} %{shortfile} %{level:.4s} %{id:03x}]%{color:reset} %{message}"
+
+type logger struct {
+ l *logging.Logger
+}
+
+func (l *logger) Infof(format string, args ...interface{}) { l.l.Info(format, args...) }
+func (l *logger) Warningf(format string, args ...interface{}) { l.l.Warning(format, args...) }
+func (l *logger) Errorf(format string, args ...interface{}) { l.l.Error(format, args...) }
+
+func init() {
+ // TODO(vadimsh): Reimplement when moved to luci-go. luci-go has this function
+ // already.
+ IsTerminal = true
+
+ backend := logging.NewLogBackend(os.Stdout, "", 0)
+ formatted := logging.NewBackendFormatter(backend, logging.MustStringFormatter(fmt))
+ logging.SetBackend(formatted)
+
+ l := logging.MustGetLogger("")
+ l.ExtraCalldepth = 2
+ DefaultLogger = &logger{l}
+}

Powered by Google App Engine
This is Rietveld 408576698