Have a look at Log::Log4perl. It provides the PID functionality you want, besides being a powerful log framework:
#!/usr/bin/perl use strict; use warnings; use Log::Dispatch::FileRotate; use Log::Log4perl; my $conf = qq( log4perl.category.Pid = INFO, ScreenAppender, PidFileRotate +Appender log4perl.appender.ScreenAppender = Log::Log4perl::Appender:: +Screen log4perl.appender.ScreenAppender.stderr = 0 log4perl.appender.ScreenAppender.layout = PatternLayout log4perl.appender.ScreenAppender.layout.ConversionPattern=[%P] %p %d + %F:%L %m%n log4perl.appender.ScreenAppender.Threshold = DEBUG log4perl.appender.PidFileRotateAppender = Log::Dispatch::F +ileRotate log4perl.appender.PidFileRotateAppender.filename = pid.$$.log log4perl.appender.PidFileRotateAppender.mode = append log4perl.appender.PidFileRotateAppender.size = 10000 log4perl.appender.PidFileRotateAppender.max = 5 log4perl.appender.PidFileRotateAppender.layout = PatternLayout log4perl.appender.PidFileRotateAppender.layout.ConversionPattern=[%P +] %p %d %F:%L %m%n ); Log::Log4perl::init( \$conf ); my $log = Log::Log4perl::->get_logger(q(Pid)); # log messages of various severity $log->debug(qq{Hey hey my my}) if $log->is_debug(); $log->info(qq{Hey hey my my}) if $log->is_info(); $log->warn(qq{Hey hey my my}) if $log->is_warn(); $log->error(qq{Hey hey my my}) if $log->is_error(); $log->fatal(qq{Hey hey my my}) if $log->is_fatal(); # die with a log message $log->logdie(qq{Hey hey my my});
Writes both to screen (STDOUT) and a file named pid.pid.log that is rotated on 50K:
[4548] INFO 2006/11/30 07:36:31 586445.pl:30 Hey hey my my [4548] WARN 2006/11/30 07:36:31 586445.pl:31 Hey hey my my [4548] ERROR 2006/11/30 07:36:31 586445.pl:32 Hey hey my my [4548] FATAL 2006/11/30 07:36:31 586445.pl:33 Hey hey my my [4548] FATAL 2006/11/30 07:36:31 586445.pl:35 Hey hey my my
Andreas
--

In reply to Re: Find the PID of current program by andreas1234567
in thread Find the PID of current program by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.