Codebase list liblog-log4perl-perl / f5c8661
use module_available instead of eval { require } to avoid triggering the __DIE__ handler mschilli 20 years ago
1 changed file(s) with 9 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
55 use strict;
66 use warnings;
77 use Carp;
8 use Log::Log4perl::Util;
89 use Log::Log4perl::Level;
910 use Log::Log4perl::DateFormat;
1011 use Log::Log4perl::NDC;
2627 # just set a flag so we know later on that we can't have fine-grained
2728 # time stamps
2829 $TIME_HIRES_AVAILABLE = 0;
29 eval { require Time::HiRes; };
30 if($@) {
31 $PROGRAM_START_TIME = time();
32 } else {
30 if(Log::Log4perl::Util::module_available("Time::HiRes")) {
31 require Time::HiRes;
3332 $TIME_HIRES_AVAILABLE = 1;
3433 $PROGRAM_START_TIME = [Time::HiRes::gettimeofday()];
34 } else {
35 $PROGRAM_START_TIME = time();
3536 }
3637
3738 # Check if we've got Sys::Hostname. If not, just punt.
3839 $HOSTNAME = "unknown.host";
39 eval { require Sys::Hostname; };
40 $HOSTNAME = Sys::Hostname::hostname() unless $@;
40 if(Log::Log4perl::Util::module_available("Sys::Hostname")) {
41 require Sys::Hostname;
42 $HOSTNAME = Sys::Hostname::hostname();
43 }
4144 }
4245
4346 ##################################################