Name

log — write custom message to arbitrary log file

ATTRIBUTES

Attribute Pos. Req. Default Description
file | arg Yes LogFile Name of the log file.
create No. Yes if file begins with ">". Create the log file if it doesn't exist?
process Strip leading and trailing whitespace, "normalize" newlines. Special actions to perform on the log message before writing to the log file. By default, this includes removing leading and trailing whitespace, and forcing every \r\n sequence to a single Unix line-feed character (\n). Use a value of "nostrip" to prevent default processing.
type text Log type to produce. Possible options are text (standard), quot (quotes each field, where fields are separated by delimiter), error (formats and logs message like the standard Interchange error message) and debug (formats and logs message like standard Interchange debug message). Options error and debug actually invoke Interchange's logError or logDebug functions in addition to writing to the log file (if any was specified).
record_delim A newline (\n) Line delimiter. Allows the tag to identify multiple "records" in input submitted at once.
delimiter A TAB (\t) Field delimiter. Allows the tag to identify fields within the line.
interpolate     0 interpolate input?
reparse     1 interpolate output?
hide     0 Hide the tag return value?

DESCRIPTION

The [log] tag can be used to write custom, possibly multiline, log messages to arbitrary log files.

BEHAVIOR

This tag does not appear to be affected by, or affect, the rest of Interchange.

EXAMPLES

Example: Log message to catalog's error.log

[log type=error]
An error occured.
[/log]

Or the same example that interpolates message text:

[log type=error interpolate=1]
An error occured, inform [value fname] at [value email].
[/log]

Example: Log to custom log

[log file=var/log/custom.log]
Custom log message.
[/log]

NOTES

AVAILABILITY

log is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/SystemTag/log.coretag
Lines: 16


# Copyright 2002-2007 Interchange Development Group and others
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.
# 
# $Id: log.coretag,v 1.4 2007-03-30 23:40:49 pajamian Exp $

UserTag log                 Order        file
UserTag log                 addAttr
UserTag log                 attrAlias    arg file
UserTag log                 hasEndTag
UserTag log                 PosNumber    1
UserTag log                 Version      $Revision: 1.4 $
UserTag log                 MapRoutine   Vend::Interpolate::log

Source: lib/Vend/Interpolate.pm
Lines: 2048

sub log {
my($file, $opt, $data) = @_;
my(@lines);
my(@fields);

my $status;

$file = $opt->{file} || $Vend::Cfg->{LogFile};
if($file =~ s/^\s*>\s*//) {
  $opt->{create} = 1;
}

$file = Vend::Util::escape_chars($file);
unless(Vend::File::allowed_file($file)) {
  Vend::File::log_file_violation($file, 'log');
  return undef;
}

$file = ">$file" if $opt->{create};

unless($opt->{process} and $opt->{process} =~ /\bnostrip\b/i) {
  $data =~ s/\r\n/\n/g;
  $data =~ s/^\s+//;
  $data =~ s/\s+$/\n/;
}

my ($delim, $record_delim);
for(qw/delim record_delim/) {
  next unless defined $opt->{$_};
  $opt->{$_} = $ready_safe->reval(qq{$opt->{$_}});
}

if($opt->{type}) {
  if($opt->{type} =~ /^text/) {
    $status = Vend::Util::writefile($file, $data, $opt);
  }
  elsif($opt->{type} =~ /^\s*quot/) {
    $record_delim = $opt->{record_delim} || "\n";
    @lines = split /$record_delim/, $data;
    for(@lines) {
      @fields = Text::ParseWords::shellwords $_;
      $status = logData($file, @fields)
        or last;
    }
  }
  elsif($opt->{type} =~ /^(?:error|debug)/) {
    if ($opt->{file}) {
      $data =~ s/\n\z//;
      $data = format_log_msg($data) unless $data =~ s/^\\//;;
      $status = Vend::Util::writefile($file, $data . "\n", $opt);
    }
    elsif ($opt->{type} =~ /^debug/) {
      $status = Vend::Util::logDebug($data);
    }
    else {
      $status = Vend::Util::logError($data);
    }
  }
}
else {
  $record_delim = $opt->{record_delim} || "\n";
  $delim = $opt->{delimiter} || "\t";
  @lines = split /$record_delim/, $data;
  for(@lines) {
    @fields = split /$delim/, $_;
    $status = logData($file, @fields)
      or last;
  }
}

return $status unless $opt->{hide};
return '';
}

AUTHORS

Interchange Development Group

SEE ALSO

DEBUG(7ic), LogFile(7ic), Message(7ic)

DocBook! Interchange!