Skip to content

Commit 4b03637

Browse files
authoredOct 30, 2018
Merge pull request #52 from ipfs/feat/tracing-file
add environment variable for writing tracing information to a file
2 parents 5e6883f + 9f93581 commit 4b03637

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed
 

‎oldlog.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"sync"
88

99
tracer "github.com/ipfs/go-log/tracer"
10+
lwriter "github.com/ipfs/go-log/writer"
1011

1112
colorable "github.com/mattn/go-colorable"
1213
opentrace "github.com/opentracing/opentracing-go"
@@ -36,7 +37,8 @@ const (
3637
envLogging = "IPFS_LOGGING"
3738
envLoggingFmt = "IPFS_LOGGING_FMT"
3839

39-
envLoggingFile = "GOLOG_FILE" // /path/to/file
40+
envLoggingFile = "GOLOG_FILE" // /path/to/file
41+
envTracingFile = "GOLOG_TRACING_FILE" // /path/to/file
4042
)
4143

4244
// ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger
@@ -93,6 +95,15 @@ func SetupLogging() {
9395
opentrace.SetGlobalTracer(lgblTracer)
9496

9597
SetAllLoggers(lvl)
98+
99+
if tracingfp := os.Getenv(envTracingFile); len(tracingfp) > 0 {
100+
f, err := os.Create(tracingfp)
101+
if err != nil {
102+
log.Error("failed to create tracing file: %s", tracingfp)
103+
} else {
104+
lwriter.WriterGroup.AddWriter(f)
105+
}
106+
}
96107
}
97108

98109
// SetDebugLogging calls SetAllLoggers with logging.DEBUG

0 commit comments

Comments
 (0)
Please sign in to comment.