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 |
iannucci
2015/05/21 23:19:23
2? not 1?
Vadim Sh.
2015/05/21 23:24:50
Don't know why. Found by experiment...
|
+ DefaultLogger = &logger{l} |
+} |