in reply to Is print faster than syswrite?

What would you use if you had to write a logging module in perl - print or syswrite?
Neither. For logging, I use the syslog service. That allows configuration of what to log where without having to modify the program, or figuring out what command line options to use. It also makes it easy to send the logs elsewhere.

Why reinvent the wheel?

Replies are listed 'Best First'.
Re^2: Is print faster than syswrite?
by saurabh.hirani (Beadle) on Jan 28, 2009 at 05:02 UTC

    Thanks a lot for your responses guys. I appreciate your viewpoints.

    I have used syslog till now for all of my work and it works like charm. But we wanted to have a logging module which we can customize from ground up and through which we can do the following:


    1. log to file or database directly. I know that logging to a database would be a major I/O hit so read on.
    2. log to a file using standard templates. As in I should be able to make a call like
    $logobj(245, {'name' => 'saurabh', 'game' => 'tennis'})

    That would check whether 245 is a valid message template id in a db file and if it is log a message to the log file of the format - program_name|program_action|tmpl_id|tmpl_params

    This log file output would be uploaded to the database on a regular basis (better than doing the database directly) and then reporting would be a much easier job.


    3. We wanted logging on a per program basis and not a facility, priority basis.
    4. We wanted to enforce the method of logging to be extremely uniform. It is better to use templates than to assume that the next guy will surely follow the "Failed to open file $file" rather than "Opening of file $file failed"

    As far as reinventing the wheel goes, I had to - as the wheel of a jeep cannot be used in a Jaguar. :)
    I haven't used this work till now in production environment. So will see how it goes.