Replies: 2 comments
-
Current status quoCurrently it's possible to enable partial debug logging from within Rex code by setting This is a viable approach, but the recommended debugging approach is still to use Potential new featureA task only needs a few things to be useful, and I would prefer to keep it tidy like that to preserve simplicity:
But there is an internally used task 'debug_this_task', sub {
say 'I want to debug this task';
}, { debug => TRUE, }; It might be a candidate for a feature request issue, but I'm afraid it has a high potential to raise more questions than it solves. I already wonder about things like:
Does it worth it?Overall, I'm not yet convinced about the return on the investment needed to explore, specify, and then implement these details with tests. Even with my reservations about the missing debug context during initialization when while partially debugging, I find it way less effort and more precise to put a Of course, it's just my quick opinion, and that doesn't automatically mean I'm right about all the details. It's more of an initial list of aspects to be considered by someone who would like to hack on this. |
Beta Was this translation helpful? Give feedback.
-
More task debugging patternsThinking about this more, another useful pattern could be to trigger debug logging via task parameters, like: task 'mytask', sub {
my $parameters = shift;
$Rex::Logger::debug = 1 if exists $parameters->{debug};
say 'something';
$Rex::Logger::debug = 0 if exists $parameters->{debug};
}; Then it can be run on the CLI as If this pattern must be added to multiple tasks, then task hooks might be useful too: # tasks
task 'mytask', sub {
say 'something';
};
# task hooks
## replace ALL with a regex to match only some tasks by their name
before 'ALL' => sub {
my ( $server, $server_ref, $cli_args ) = @_;
$Rex::Logger::debug = 1 if exists $cli_args->{debug};
};
## replace ALL with a regex to match only some tasks by their name
after 'ALL' => sub {
my ( $server, $failed, $cli_args ) = @_;
$Rex::Logger::debug = 0 if exists $cli_args->{debug};
}; The hooks-based approach also prints out more debug context compared to the case where In summary, we have examples of how to control debug behavior various levels:
This also feels like a good demonstration of the "Rex is a framework, not a tool" mantra. While sometimes it's good to provide convenience shortcuts solutions for common situations into Rex core, the focus is on providing building blocks which enables users to build the tool their situation needs. More notes for possible core implementationLooking into this more, the following might be a viable implementation approach to address the second question from above:
|
Beta Was this translation helpful? Give feedback.
-
It can be useful to have a
debug => 'yes'
option as withgroup
for tasks rather that specifying manually with-d
CLI switch.So it's inferred from the context that this task is to be run with debugging enabled.
And for laziness/forgetfulnes of course :-)
Beta Was this translation helpful? Give feedback.
All reactions