#++
# NAME
#	logfs.pl 3p
# SUMMARY
#	log selected file system operations
# SYNOPSIS
#	require 'logfs.pl';
#
#	log_open(handle, $path)
#
#	log_link($old, $new)
#
#	log_symlink($old, $new)
#
#	log_rename($old, $new)
#
#	log_remove($path)
#
#	log_stat($path)
# DESCRIPTION
#	This module logs and performs common file system operations.
# LICENSE
#	This software is distributed under the IBM Public License.
# AUTHOR(S)
#	Wietse Venema
#	IBM T.J. Watson Research
#	P.O. Box 704Yorktown Heights, NY 10598, USA
#--

if (!$running_under_grave_robber) {
    require "../conf/coroner.cf";
}
require "logger.pl";

# log_open($path) - open logfile for append mode

sub log_open
{
    my($path) = @_;
    my($saved_handle);

    # Open for append mode, and turn on micro buffering.

    open(LOG, ">>$path") || die "Cannot open/append logfile $path: $!\n";
    print "log_open: opened $path\n" if $verbose;
    $saved_handle = select(LOG);
    $| = 1;
    select($saved_handle);
}

# log_item($stuff) - log time stamp and stuff

sub log_item
{
    my(@stuff) = @_;
    my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$hr_off,$min_off)
        = localtimez(time());

    printf LOG "%4d/%02d/%02d %02d:%02d:%02d %+03d%02d %s\n",
	$year+1900, $mon+1, $mday, $hour, $min, $sec, $hr_off, $min_off,
	join(' ', @stuff);
    printf "log_item: %s\n", join(' ', @stuff) if $verbose;
}

# Scaffolding...

if (!$running_under_grave_robber) {
    $verbose = 1;
    log_open("/tmp/foobar");
    log_item("PIPEFROM_CMD", "ls", "-l");
}

1;
