mikejones has asked for the wisdom of the Perl Monks concerning the following question:

Is AUDIT_LEVEL a Perl variable? And if I set it like this:
my $audit_trail = $ENV{AUDIT_LEVEL} || 0;
then when invoked, Perl will automagically print a detailed log, like so? If not what module will help with this?
## LOG ## Process: daily_upd started at 00:30:00 25 Mar 2000 Data source: /data/input/daily.dat Data sink: database customer on server DATA_SERVER (using id 'maint') Input record: D:CUS-00123 Action: Delete Translation: CUS-00123 = database id 2364 Record 2364 deleted successfully Input record: U:CUS-00124:Jones & Co| [etc …] Action: Update Translation: CUS-00124 = database id 2365 Record 2365 updated successfully Input record: I:CUS-01000:Magnum Solutions Ltd| [etc …] Action: Insert Integrity Check: CUS-01000 does not exist on database Record 3159 inserted successfully End of file on data source 1037 records processed (60 ins, 964 upd, 13 del) Process: daily_upd complete at 00:43:14 25 Mar 2000
This is mentioned in the Data munging with Perl book.

2.5.1 What to write to an audit trail.

At different points in the life of a program, different levels of audi +ting will be appropriate. While the program is being developed and tested it is common practice +to have a much more detailed audit trail than when it is being used day t +o day in a production environment. For this reason, it is often useful to write auditing cod +e that allows you to generate different levels of output depending on the val +ue of a variable that defines the audit level. This variable might be read from an envi +ronment variable like this: my $audit_level = $ENV{AUDIT_LEVEL} || 0; In this example we set the value of $audit_level from the environment +variable AUDIT_LEVEL. If this level is not set then we default to 0, the minimu +m level. Later in the script we can write code like: print LOG 'Starting processing at ', scalar localtime, "\n" if $audit_level > 0; to print audit information to the previously opened file handle, LOG. Standards for audit trails will typically vary from company to company +, but some things that you might consider auditing are:  start and end times of the process  source and sink parameters (filenames, database connection parameter +s, etc.)  ID of every record processed  results of each data translation  final count of records processed

Replies are listed 'Best First'.
Re: AUDIT_TRAIL in Data Munging with Perl
by mr_mischief (Monsignor) on Aug 22, 2008 at 20:00 UTC
    my $audit_trail = $ENV{AUDIT_LEVEL} || 0;

    That means to take the environment variable from your environment (a group of variables provided by your OS, command shell, or the program which called this program) and assign it to the Perl variable $audit_trail if it is defined and non-zero. If the environment doesn't have that variable or it's set to zero, then set $audit_trail to zero.

    The program in which that line was used a variable called $audit_trail in its computations or control logic (probably just control logic, and probably just about how much data to log). This could have been explicit in the main program or it could be a feature of a module the main program was using.

      Thank you, but I know what it means. : )

      I asked if this is a default variable provided by Perl like PATH or LOGDIR or PERL_BADLANG are?

        It isn't as far as perlrun tells me. That's why I specifically said that the code of the application made use of it. AFAICT from my own knowledge and the Perl documentation, perl does not.
Re: AUDIT_TRAIL in Data Munging with Perl
by davorg (Chancellor) on Aug 23, 2008 at 07:34 UTC

    It's not a special variable. It's just a name I made up to control the level of auditing.

    So, no, there's nothing magical about it at all. You need to write the code which handles it yourself. I hoped that I had made that obvious with the sample code:

    print LOG 'Starting processing at ', scalar localtime, "\n" if $audit_level > 0;

    I apologise for any confusion caused :-)

    --

    See the Copyright notice on my home node.

    "The first rule of Perl club is you do not talk about Perl club." -- Chip Salzenberg