1Log::Trivial(3)       User Contributed Perl Documentation      Log::Trivial(3)
2
3
4

NAME

6       Log::Trivial - Very simple tool for writing very simple log files
7

SYNOPSIS

9         use Log::Trivial;
10         my $logger = Log::Trivial->new(log_file => "path/to/my/file.log");
11         $logger->set_level(3);
12         $logger->write(comment => "foo");
13

DESCRIPTION

15       Use this module when you want use "Yet Another" very simple, light
16       weight log file writer.
17

SUBROUTINES/METHODS

19   new
20       The constructor can be called empty or with a number of optional
21       parameters.
22
23         $logger = Log::Trivial->new();
24
25       or
26
27         $logger = Log::Trivial->new(
28           log_file  => "/my/config/file",
29           log_tag   => $$,
30           log_level => "2");
31
32       The log_tag is an optional string that is written to every log event
33       between the date at the comment, and is intended to help separate
34       logging events in environments when multiple applictions are
35       simultaneously writing to the same log file. For example you could pass
36       the PID of the applications, as shown in the example above.
37
38   set_log_file
39       The log file can be set after the constructor has been called.  Simply
40       set the path to the file you want to use as the log file.
41
42         $logger->set_log_file("/path/to/log.file");
43
44   set_log_mode
45       Log::Trivial runs in two modes. The default mode is Multi mode: in this
46       mode the file will be opened and closed for each log file write.  This
47       may be slower but allows multiple applications to write to the log file
48       at the same time. The alternative mode is called single mode: once you
49       start to write to the log no other application honouring flock will
50       write to the log. Single mode is potentially faster, and may be
51       appropriate if you know that only one copy of your application can
52       should be writing to the log at any given point in time.
53
54       WARNING: Not all system honour flock.
55
56         $logger->set_log_mode("multi");    # Sets multi mode (the default)
57
58       or
59
60         $logger->set_log_mode("single");    # Sets single mode
61
62   set_log_level
63       Log::Trivial uses very simple arbitrary logging level logic. Level 0 is
64       the highest priority log level, the lowest is the largest number
65       possible in Perl on your platform. You set the global log level for
66       your application using this function, and only log events of this level
67       or higher priority will be logged. The default level is 3.
68
69         $logger->set_log_level(4);
70
71   set_write_mode
72       Log::Trivial write log enteries using the POSIX synchronous mode by
73       default. This mode ensures that the data has actually been written to
74       the disk. This feature is not supported in all operating systems and
75       will slow down the disk write. By default this mode is enabled, in
76       future it may be disabled by default.
77
78         $logger->set_write_mode('s');     # sets synchronous (default)
79         $logger->set_write_mode('a');     # sets asynchronous
80
81   write
82       Write a log file entry.
83
84         $logger->write(
85           comment => "My comment to be logged",
86           level   => 3);
87
88       or
89
90         $logger->write("My comment to be logged");
91
92       It will fail if the log file hasn't be defined, or isn't writable. It
93       will return the string written on success.
94
95       If you don't specify a log level, it will default to the current log
96       level and therefore log the event. Therefore if you always wish to log
97       something either specify a level of 0 or never specify a log level.
98
99       Log file entries are time stamped and have a newline carriage return
100       added automatically.
101
102   get_error
103       In normal operation the module should never die. All errors are non-
104       fatal. If an error occurs it will be stored internally within the
105       object and the method will return undef. The error can be read with the
106       get_error method. Only the most recent error is stored.
107
108         $logger->write("Log this") || print $logger->get_error;
109

LOG FORMAT

111       The log file format is very simple and fixed:
112
113       Time & date [tab] Your log comment [carriage return new line]
114
115       If you have enabled a log_tag then the log format will have an extra
116       element inserted in it.
117
118       Time & date [tab] log_tag [tab] Your log comment [carriage return new
119       line]
120
121   DEPENDENCIES
122       At the moment the module only uses core modules. The test suite
123       optionally uses "Pod::Coverage", "Test::Pod::Coverage" and "Test::Pod",
124       which will be skipped if you don't have them.
125
126   History
127       See Changes file.
128

BUGS AND LIMITATIONS

130       By default log write are POSIX synchronous, it is very unlikely that it
131       will run on any OS that does not support POSIX synchronous file
132       writing, this means it probably won't run on a VAX, Windows or other
133       antique system. It does run under Windows/Cygwin. To use non-POSIX
134       systems you need to turn off synchronous write.
135
136       Patches Welcome... ;-)
137
138   To Do
139       ·   Much better test suite.
140
141       ·   See if it's possible to work on non-POSIX like systems
142           automatically
143

EXPORT

145       None.
146

AUTHOR

148       Adam Trickett, <atrickett@cpan.org>
149

SEE ALSO

151       perl, Log::Agent, Log::Log4perl, Log::Dispatch, Log::Simple
152
154       "Log::Trivial", Copyright iredale consulting 2005-2007
155
156       OSI Certified Open Source Software.  Free Software Foundation Free
157       Software.
158
159       This program is free software: you can redistribute it and/or modify it
160       under the terms of the GNU General Public License as published by the
161       Free Software Foundation, either version 3 of the License, or (at your
162       option) any later version.
163
164       This program is distributed in the hope that it will be useful, but
165       WITHOUT ANY WARRANTY; without even the implied warranty of
166       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
167       General Public License for more details.
168
169       You should have received a copy of the GNU General Public License along
170       with this program.  If not, see <http://www.gnu.org/licenses/>.
171
172
173
174perl v5.12.0                      2010-05-03                   Log::Trivial(3)
Impressum