I am using a third party fastlane plugin and it contains an action that will display vital information I need to capture, such as a link.
I am trying to find an elegant way to capture these logs within the fastlane actions, I am trying to avoid using a shell command but if it's the only way, then I suppose I have no choice.
I need this link as it is a unique and random link that contains resources I'd like to download.
I have tried redirecting stdout to no avail since fastlane uses their own logger (usually UI.message) and was about to submit a feature request to fastlane but figured perhaps someone else has ran into this and managed to get past it.
Is there anyway to redirect this type of log and capture it?
Here is the fastlane source code around UI: https://github.com/fastlane/fastlane/tree/master/fastlane_core/lib/fastlane_core/ui
And here is one of the ways I tried redirecting output: Capturing logger output inside a method
Any help / advice / resources would be appreciated!
I forgot to update this, but in the end I solved it as such:
module Fastlane
module Helper
class UtilHelper
# Redirects standard output and standard error to a file
# (currently only way we know how to capture fastlane ui messages)
def self.redirect_stdout_to_file(filename)
original_stdout = $stdout.clone
original_stderr = $stderr.clone
$stderr.reopen File.new(filename, 'w')
$stdout.reopen File.new(filename, 'w')
yield
ensure
$stdout.reopen original_stdout
$stderr.reopen original_stderr
end
end
end
end
and I utilized it like this:
temp_file = 'testlab.log'
UtilHelper.redirect_stdout_to_file(temp_file) { upload_xctestrun() }
What upload_xctrestrun
does is irrelevant, just know that it is a function from a fastlane plugin which outputs messages using the fastlane UI
object like so:
UI.message("Some fastlane decorated message here")
Hope this helps anyone :)