Log::Di...ch::File(3)

okay bestie, welcome to the manual page Log::Di...ch::File(3) β€” that's the manual name, and it's chillin' under User Contributed Perl Documentation. we're talking about Log::Dispatch::File here, version 2.71, and it's giving β€œlet me write your logs to a file” energy. no cap.

πŸ’– NAME πŸ’–

Log::Dispatch::File β€” Object for logging to files

✨ VERSION ✨

version 2.71

🌸 SYNOPSIS 🌸

use Log::Dispatch;

my $log = Log::Dispatch->new(
    outputs => [
        [
            'File',
            min_level => 'info',
            filename  => 'Somefile.log',
            mode      => '>>',
            newline   => 1
        ]
    ],
);

$log->emerg("I've fallen and I can't get up");

πŸ¦‹ DESCRIPTION πŸ¦‹

This module gives you a simple object for logging to files under the Log::Dispatch::* system. literally its whole job, and it ate.

Heads up: by default, a newline will not be added automatically at the end of a message. if you want that little line break, pass newline => 1. periodt.

NOTE: if you're writing to a single log file from multiple processes, the log output may become interleaved and garbled. that's the messy group-chat-with-no-thread-discipline vibe. use the Log::Dispatch::File::Locked output instead, which allows multiple processes to safely share a single file. slay.

πŸ’… CONSTRUCTOR πŸ’…

The constructor takes the following parameters in addition to the standard parameters documented in Log::Dispatch::Output:

  • filename ($) β€” the filename to be opened for writing. that's the main character, obviously.
  • mode ($) β€” the mode the file should be opened with. valid options are 'write', '>', 'append', '>>', or the relevant constants from Fcntl. the default is 'write'. iconic little default.
  • binmode ($) β€” a layer name to be passed to binmode, like ":encoding(UTF-8)" or ":raw". very layer, very demure.
  • close_after_write ($) β€” whether or not the file should be closed after each write. this defaults to false.

if this is true, then the mode will always be append, so that the file is not re-written for each new message. important detail, bestie.

  • lazy_open ($) β€” whether or not the file should be opened only on first write. this defaults to false. lowkey patient of it.
  • autoflush ($) β€” whether or not the file should be autoflushed. this defaults to true.
  • syswrite ($) β€” whether or not to perform the write using syswrite in perlfunc(), as opposed to print in perlfunc(). this defaults to false. the usual caveats and warnings as documented in syswrite in perlfunc apply. don't say i didn't warn you.
  • permissions ($) β€” if the file does not already exist, the permissions that it should be created with. optional. the argument passed must be a valid octal value, such as 0600 or the constants available from Fcntl, like S_IRUSR|S_IWUSR.

see chmod in perlfunc for more on potential traps when passing octal values around. most importantly, remember that if you pass a string that looks like an octal value, like this:

my $mode = '0644';

then the resulting file will end up with permissions like this:

--w----r-T

which is probably not what you want. seriously, bestie, that permission set is cursed 😭

🫢 SUPPORT 🫢

Bugs may be submitted at https://github.com/houseabsolute/Log-Dispatch/issues. go off, report responsibly πŸ’–

🌈 SOURCE 🌈

The source code repository for Log-Dispatch can be found at https://github.com/houseabsolute/Log-Dispatch. iykyk.

πŸ‘‘ AUTHOR πŸ‘‘

Dave Rolsky <autarch@urth.org>

This software is Copyright (c) 2023 by Dave Rolsky.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

The full text of the license can be found in the LICENSE file included with this distribution.


bye bestie πŸ’– this page came from perl v5.42.0, dated 2023-04-21, and yes the manual name is still Log::Di...ch::File(3). go forth and log responsibly, mwah πŸ’…βœ¨

πŸ“¦ where this page comes from