From 1f52dc7138d13c30f8bb75d2f4342e483c6ce124 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Wed, 21 Sep 2022 13:06:15 -0700 Subject: [PATCH] enable logging support for torrc builder --- tor/torrcBuilder.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tor/torrcBuilder.go b/tor/torrcBuilder.go index 6937d7c..dc04c04 100644 --- a/tor/torrcBuilder.go +++ b/tor/torrcBuilder.go @@ -10,6 +10,14 @@ import ( "strings" ) +type TorLogLevel string + +const TorLogLevelDebug TorLogLevel = "debug" +const TorLogLevelNotice TorLogLevel = "notice" +const TorLogLevelInfo TorLogLevel = "info" +const TorLogLevelWarn TorLogLevel = "warn" +const TorLogLevelErr TorLogLevel = "err" + // TorrcBuilder is a a helper for building torrc files type TorrcBuilder struct { lines []string @@ -34,6 +42,12 @@ func (tb *TorrcBuilder) WithControlPort(port int) *TorrcBuilder { return tb } +// WithLog sets the Log to file directive to the specified with with the specified log level +func (tb *TorrcBuilder) WithLog(logfile string, level TorLogLevel) *TorrcBuilder { + tb.lines = append(tb.lines, fmt.Sprintf("Log %v file %v", level, logfile)) + return tb +} + // WithCustom clobbers the torrc builder and allows the client to set any option they want, while benefiting // from other configuration options. func (tb *TorrcBuilder) WithCustom(lines []string) *TorrcBuilder {