Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 t
Octocat-spinner-32 xt
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Build.PL
Octocat-spinner-32 Changes
Octocat-spinner-32 LICENSE
Octocat-spinner-32 META.json
Octocat-spinner-32 README.md
Octocat-spinner-32 README.mkdn
Octocat-spinner-32 cpanfile
README.md

NAME

File::Stamped - time stamped log file

SYNOPSIS

use File::Stamped;
my $fh = File::Stamped->new(pattern => '/var/log/myapp.log.%Y%m%d.txt');
$fh->print("OK\n");

# with Log::Minimal
use Log::Minimal;
my $fh = File::Stamped->new(pattern => '/var/log/myapp.log.%Y%m%d.txt');
local $Log::Minimal::PRINT = sub {
    my ( $time, $type, $message, $trace) = @_;
    print {$fh} "$time [$type] $message at $trace\n";
};

DESCRIPTION

File::Stamped is utility library for logging. File::Stamped object mimic file handle.

You can use "myapp.log.%Y%m%d.log" style log file.

METHODS

  • my $fh = File::Stamped->new(%args);

    This method creates new instance of File::Stamped. The arguments are followings.

    You need to specify one of pattern or callback.

    • pattern : Str

      This is file name pattern. It is the pattern for filename. The format is POSIX::strftime(), see also POSIX.

    • callback : CodeRef

      You can use a CodeRef to generate file name.

      File::Stamped pass only one arguments to callback function.

      Here is a example code:

      my $pattern = '/path/to/myapp.log.%Y%m%d.log';
      my $f = File::Stamped->new(callback => sub {
          my $file_stamped = shift;
          local $_ = $pattern;
          s/!!/$$/ge;
          $_ = POSIX::strftime($_, localtime());
          return $_;
      });
      
    • close_after_write : Bool

      Default value is 1.

    • iomode: Str

      This is IO mode for opening file.

      Default value is '>>:utf8'.

    • autoflush: Bool

      This attribute changes $|.

    • rotationtime: Int

      The time between log file generates in seconds. Default value is 1.

    • auto_make_dir: Bool

      If this attribute is true, auto make directry of log file. Default value is false.

    • symlink: Str

      generate symlink file for log file.

  • $fh->print($str: Str)

    This method prints the $str to the file.

  • $fh->syswrite($str: Str [, $len: Int, $offset: Int])

    This method prints the $str to the file. This method uses syswrite internally. Writing is not buffered.

AUTHOR

Tokuhiro Matsuno

SEE ALSO

Log::Dispatch::File::Stamped

LICENSE

Copyright (C) Tokuhiro Matsuno

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Something went wrong with that request. Please try again.