-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option for :exec
mixin to print commands
#47
Comments
The include :exec
def run
exec ["echo", "hello"]
end % toys foo
hello
% toys foo -v
[2020-07-06 10:02:03 INFO] ["echo", "hello"]
hello
% You can also change the log level used by include :exec
def run
# Log at the "any" level, i.e. always log.
sh "echo hello", log_level: Logger::UNKNOWN
end % toys foo
[2020-07-06 10:03:17 ANY] echo hello
hello
% Alternatively, to set the log level for all commands: # Set the default log level for all exec commands:
include :exec, log_level: Logger::UNKNOWN
def run
sh "echo hello"
end See the configuration options section of https://dazuma.github.io/toys/gems/toys-core/v0.10.3/Toys/StandardMixins/Exec.html |
OK, but |
You can change the logger by constructing a new logger with whatever formatter you want, and passing it in the @AlexWayfer Question for you: would you prefer seeing all log entries with a different simpler format, or just the ones related to exec commands? |
What kind of logs are here beside "exec commands"? |
Exec is the only standard mixin that makes heavy use of the logger. But any tool can log: tool "foo" do
def run
logger.info "Hello, world!"
logger.warn "This is a warning"
end
end |
Oh… I didn't know about available |
I've discovered a So, in the current version of subtool_apply do
unless include? :exec
include :exec,
exit_on_nonzero_status: true,
logger: Logger.new(
$stdout, formatter: ->(_severity, _datetime, _progname, msg) { "> #{msg}\n" }
),
log_level: Logger::UNKNOWN
end
end It's a huge, but does what I want. And this is should be duplicated in outer code if there is another It can be simplified via adding a But! I think, we should change a formatter only when we print exactly subtool_apply do
unless include? :exec
exec_logger = Logger.new($stdout)
original_formatter = exec_logger.formatter
exec_logger.formatter = lambda do |severity, datetime, progname, msg|
if severity == 'ANY'
"> #{msg}\n"
else
original_formatter.call(severity, datetime, progname, msg)
end
end
include :exec,
exit_on_nonzero_status: true,
logger: exec_logger,
log_level: Logger::UNKNOWN
end
end So, you know… after a day of usage default logger I think I'm OK with its format, although it's still a bit ugly. If you want, you can add an option with separate logger exactly for logging |
Hello.
I'm switching to
toys
fromrake
.And there is in
rake
sh
command prints executing command itself, like:In
toys
there issh
method afterinclude :exec
, but without ability to print getting command.Maybe it even be with
true
default.The text was updated successfully, but these errors were encountered: