Skip to content
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

noc/uninitialized_value_concatenation #97

Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/Mojo/WebSocketProxy/Dispatcher.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ sub ok {
sub open_connection {
my ($c) = @_;

my $log = $c->app->log;
$log->debug("accepting a websocket connection from " . $c->tx->remote_address);
my $log = $c->app->log;
my $remote_address = $c->tx->remote_address // 'undef';
$log->debug('accepting a websocket connection from ' . $remote_address);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log::any format log can handle undef

Suggested change
$log->debug('accepting a websocket connection from ' . $remote_address);
$log->debugf('accepting a websocket connection from %s', $c->tx->remote_address);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Introduced Log::Any

# Enable permessage-deflate
denissafiullin-deriv marked this conversation as resolved.
Show resolved Hide resolved
$c->tx->with_compression;

Expand Down Expand Up @@ -123,7 +124,7 @@ sub on_message {
my $req_storage = {};
$req_storage->{args} = $args;

$req_storage->{logger} = Mojo::WebSocketProxy::RequestLogger->new;
$req_storage->{logger} = Mojo::WebSocketProxy::RequestLogger->new;
# We still want to run any hooks even for invalid requests.
if (my $err = Mojo::WebSocketProxy::Parser::parse_req($c, $req_storage)) {
$c->send({json => $err}, $req_storage);
Expand Down
15 changes: 7 additions & 8 deletions lib/Mojo/WebSocketProxy/RequestLogger.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ Create a new `Mojo::WebSocketProxy::RequestLogger` object.

=cut


field $context;

our $log_handler = sub {
my ($level, $message, $context, @params) = @_;

if(scalar @params) {
if (scalar @params) {
return $log->$level($message, @params);
}

Expand All @@ -83,10 +82,10 @@ set the handler for message logging
sub set_handler {
my ($self, $custom_handler) = @_;
$log_handler = $custom_handler;
}
}

BUILD{
$context->{correlation_id} = UUID::Tiny::create_UUID_as_string(UUID::Tiny::UUID_V4);
BUILD {
$context->{correlation_id} = UUID::Tiny::create_UUID_as_string(UUID::Tiny::UUID_V4);
}

=head2 infof
Expand Down Expand Up @@ -166,7 +165,7 @@ trace message logging
=cut

method trace($message) {
$log_handler->('trace', $message , $context);
$log_handler->('trace', $message, $context);
}

=head2 error
Expand Down Expand Up @@ -215,7 +214,7 @@ get the value of context

=cut

method get_context(){
method get_context() {
return $context;
}

Expand All @@ -235,7 +234,7 @@ remove key from context

=cut

method remove_context_key($key){
method remove_context_key($key) {
delete $context->{$key};
}

Expand Down
2 changes: 1 addition & 1 deletion t/29-request_logger_test.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ subtest 'Test log_message method' => sub {
$logger->infof('This is a info message %s', ['abc', '221']);
$logger->warnf('%s This is a warning message ', {with => 'params'});
$logger->tracef('This is a trace %s message', "with params");
$logger->errorf('This is an error %s message',"with params");
$logger->errorf('This is an error %s message', "with params");
$logger->debugf('This is debug message with %s', 'params');
pass('All log levels tested');
};
denissafiullin-deriv marked this conversation as resolved.
Show resolved Hide resolved
Expand Down