Recently we started working on an improvement of our Apple push notification service and we noticed that there is a massive log generated by that service. It didn’t take that long to find out the reason why this happens.

Here is a brief extract from the log:

DEBUG: .../IO/Socket/SSL.pm:1653: new ctx 941571936
DEBUG: .../IO/Socket/SSL.pm:363: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:365: socket connected
DEBUG: .../IO/Socket/SSL.pm:383: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:433: set socket to non-blocking to enforce timeout=180
DEBUG: .../IO/Socket/SSL.pm:446: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:456: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:466: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:486: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:1641: ok=1 cert=941683424
DEBUG: .../IO/Socket/SSL.pm:1641: ok=1 cert=941939952
DEBUG: .../IO/Socket/SSL.pm:1641: ok=1 cert=942089536
DEBUG: .../IO/Socket/SSL.pm:1641: ok=1 cert=941385168
DEBUG: .../IO/Socket/SSL.pm:1201: scheme=www cert=941385168
DEBUG: .../IO/Socket/SSL.pm:456: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:466: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:486: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:446: Net::SSLeay::connect -> 1
DEBUG: .../IO/Socket/SSL.pm:501: ssl handshake done

And on and on and on until it writes 113225 lines and this get logged on every single iteration! Everyone who has played around with SSL and Perl, definitely knows what the DEBUG of Net::SSLeay looks like and how to switch it off. But there was only one problem - there was no option which allows us to do that in the code which uses the SSL module. Even worse - it was hard coded to the highest possible value. And it gets set inside the method which is sending the message so there is no way for this to be changed from outside that method.

sub write {
    # ... some more code here...
    $Net::SSLeay::trace       = 4;
    $Net::SSLeay::ssl_version = 10;

We had a look at the code of Net::APNS::Notification and there was an easy way to implement a change to give back control of the SSL debug values. By simply converting the SSL version and debug to accessors, it makes possible to have as much debug information as we want and bring the control of the values out of the scope of the method which uses them.

sub write {
    # ... some more code here...
    $Net::SSLeay::trace       = $self->ssl_trace_level;
    $Net::SSLeay::ssl_version = $self->ssl_version;

In order to be backward compatible we set the default values of these accessors to be exactly the same as it was, so as not to stress people out about where their logs have gone :)

See the updated code at https://github.com/haoyayoi/Net-APNS. Many thanks to haoyayoi for merging our patch, we’re looking forward to the next release of Net-APNS!