Mojo::UserAgent logging request/response to file #2060
-
I have a requirement to log all HTTP Requests / Responses to a file. How can I accomplish that using In SOAP::Lite, I do: use SOAP::Lite 1.27 +trace => [ debug => \&Debug, ];
sub Debug { my ($in) = @_; log_to_file($in); } Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
You can do that kind of logging from a prepare hook when you set up your UserAgent: has ua => sub {
my $self = shift;
use Mojo::UserAgent;
use Mojo::Util qw( dumper );
my $ua = Mojo::UserAgent->new;
$ua->on(prepare => sub ($ua, $tx) {
$self->log->trace("about to do an http: ".dumper $tx);
});
$ua
} you can also set the |
Beta Was this translation helpful? Give feedback.
-
I don't know if this will work for you, like if there are certain formatting requirements, but have you tried setting |
Beta Was this translation helpful? Give feedback.
Look in here for the DEBUG constant: https://github.com/mojolicious/mojo/blob/main/lib/Mojo/UserAgent.pm
Probably you just need to subscribe to the read and write events of the underlying socket like it does