File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 77 "context"
88 "fmt"
99 "io"
10+ "log"
1011 "os"
1112 "strings"
1213 "sync"
@@ -153,3 +154,30 @@ func isValidLogLevel(level string) bool {
153154
154155 return false
155156}
157+
158+ // RegisterStdlogSink sets up a logging sink for use with test sweepers and
159+ // other cases where plugin logs don't get routed through Terraform and the
160+ // built-in Go `log` package is also used.
161+ //
162+ // RegisterStdlogSink should only ever be called by test sweepers, providers
163+ // should never call it.
164+ //
165+ // RegisterStdlogSink must be called prior to any loggers being setup or
166+ // instantiated.
167+ func RegisterStdlogSink (ctx context.Context ) context.Context {
168+ logger , loggerOptions := newStdlogSink ()
169+
170+ ctx = logging .SetSink (ctx , logger )
171+ ctx = logging .SetSinkOptions (ctx , loggerOptions )
172+
173+ return ctx
174+ }
175+
176+ func newStdlogSink () (hclog.Logger , * hclog.LoggerOptions ) {
177+ loggerOptions := & hclog.LoggerOptions {
178+ IndependentLevels : true ,
179+ JSONFormat : false ,
180+ }
181+
182+ return hclog .FromStandardLogger (log .Default (), loggerOptions ), loggerOptions
183+ }
You can’t perform that action at this time.
0 commit comments