package Log; my $singleton; sub new{ my ($class,$logpath) = @_; unless ( ref $singleton eq 'Log' ) { $singleton = {}; bless( $singleton, $class ); $singleton->create_path($logpath); } return $singleton; } sub create_path{ my ($self,$logpath) = @_; my $logfile = $logpath . 'yyyymmdd' . '.txt'; $self->{'log'} = $logfile; return; } sub get_log_instance { $singleton ||= (shift)->new(); } sub log { my $self = shift; my $error_msg = shift; my $logfile = $self->{'log'}; my $handle; open ( $handle, '>>', $logfile ) or die "Can't open $logfile: $!"; print {$handle} "ERROR: $error_msg\n"; close $handle; return; } 1; package DoStuff; use Log; sub new { my $class = shift; my $log_obj = Log->get_log_instance(); my $self = bless {}, $class; # Store log object. Is this OK to do? $self->{'log_obj'} = $log_obj; return $self; } sub get_log_obj { my $self = shift; return $self->{'_log_obj'}; } sub do_something { my $self = shift; ..... # Get log object and pass error msg to it's log sub routine $self->get_log_obj()->log('Error Error Error'); # Do some logging ..... return; } 1;