Skip to content

Commit 12261b0

Browse files
authored
add helper to retrieve log utils from action (#126)
1 parent d9fca72 commit 12261b0

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

pkg/action/utils.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,20 @@ func exportScriptToFile(script string) (string, error) {
211211

212212
return path, nil
213213
}
214+
215+
// GetLoggerAndTerminal returns action logger and terminal if any.
216+
func GetLoggerAndTerminal(a *Action) (log *launchr.Logger, term *launchr.Terminal) {
217+
// Fallback to default launchr logger.
218+
log = launchr.Log()
219+
if rt, ok := a.Runtime().(RuntimeLoggerAware); ok {
220+
log = rt.LogWith()
221+
}
222+
223+
// Fallback to default launchr term.
224+
term = launchr.Term()
225+
if rt, ok := a.Runtime().(RuntimeTermAware); ok {
226+
term = rt.Term()
227+
}
228+
229+
return
230+
}

plugins/builder/plugin.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,8 @@ func (p *Plugin) DiscoverActions(_ context.Context) ([]*action.Action, error) {
7070
nocache: input.Opt("no-cache").(bool),
7171
}
7272

73-
log := launchr.Log()
74-
if rt, ok := a.Runtime().(action.RuntimeLoggerAware); ok {
75-
log = rt.LogWith()
76-
}
73+
log, term := action.GetLoggerAndTerminal(a)
7774
flags.SetLogger(log)
78-
79-
term := launchr.Term()
80-
if rt, ok := a.Runtime().(action.RuntimeTermAware); ok {
81-
term = rt.Term()
82-
}
8375
flags.SetTerm(term)
8476

8577
return Execute(ctx, &flags)

0 commit comments

Comments
 (0)