From 9f935812f19d2b1e0125787ab6af3d2de112f41a Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 3 Oct 2018 16:50:03 -0700 Subject: [PATCH] add environment variable for writing tracing information to a file --- oldlog.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/oldlog.go b/oldlog.go index 9201ecc..c09ec84 100644 --- a/oldlog.go +++ b/oldlog.go @@ -7,6 +7,7 @@ import ( "sync" tracer "github.com/ipfs/go-log/tracer" + lwriter "github.com/ipfs/go-log/writer" colorable "github.com/mattn/go-colorable" opentrace "github.com/opentracing/opentracing-go" @@ -36,7 +37,8 @@ const ( envLogging = "IPFS_LOGGING" envLoggingFmt = "IPFS_LOGGING_FMT" - envLoggingFile = "GOLOG_FILE" // /path/to/file + envLoggingFile = "GOLOG_FILE" // /path/to/file + envTracingFile = "GOLOG_TRACING_FILE" // /path/to/file ) // ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger @@ -93,6 +95,15 @@ func SetupLogging() { opentrace.SetGlobalTracer(lgblTracer) SetAllLoggers(lvl) + + if tracingfp := os.Getenv(envTracingFile); len(tracingfp) > 0 { + f, err := os.Create(tracingfp) + if err != nil { + log.Error("failed to create tracing file: %s", tracingfp) + } else { + lwriter.WriterGroup.AddWriter(f) + } + } } // SetDebugLogging calls SetAllLoggers with logging.DEBUG