Log-Any-1.708 000755 000765 000024 0 13606765203 12231 5 ustar 00doug staff 000000 000000 README 100644 000765 000024 5021 13606765203 13170 0 ustar 00doug staff 000000 000000 Log-Any-1.708 Log::Any
"Log::Any" provides a standard log production API for modules.
Log::Any::Adapter allows applications to choose the mechanism for log
consumption, whether screen, file or another logging mechanism like
Log::Dispatch or Log::Log4perl.
Many modules have something interesting to say. Unfortunately there is
no standard way for them to say it - some output to STDERR, others to
"warn", others to custom file logs. And there is no standard way to get
a module to start talking - sometimes you must call a uniquely named
method, other times set a package variable.
This being Perl, there are many logging mechanisms available on CPAN.
Each has their pros and cons. Unfortunately, the existence of so many
mechanisms makes it difficult for a CPAN author to commit his/her users
to one of them. This may be why many CPAN modules invent their own
logging or choose not to log at all.
To untangle this situation, we must separate the two parts of a logging
API. The first, *log production*, includes methods to output logs (like
"$log->debug") and methods to inspect whether a log level is activated
(like "$log->is_debug"). This is generally all that CPAN modules care
about. The second, *log consumption*, includes a way to configure where
logging goes (a file, the screen, etc.) and the code to send it there.
This choice generally belongs to the application.
A CPAN module uses "Log::Any" to get a log producer object. An
application, in turn, may choose one or more logging mechanisms via
Log::Any::Adapter, or none at all.
"Log::Any" has a very tiny footprint and no dependencies beyond Perl
5.8.1, which makes it appropriate for even small CPAN modules to use. It
defaults to 'null' logging activity, so a module can safely log without
worrying about whether the application has chosen (or will ever choose)
a logging mechanism.
See for the
original post proposing this module.
INSTALLATION
This is a Perl module distribution. It should be installed with whichever
tool you use to manage your installation of Perl, e.g. any of
cpanm .
cpan .
cpanp -i .
Consult http://www.cpan.org/modules/INSTALL.html for further instruction.
Should you wish to install this module manually, the procedure is
perl Makefile.PL
make
make test
make install
COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Jonathan Swartz, David Golden,
and Doug Bell.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
LICENSE 100644 000765 000024 44015 13606765203 13343 0 ustar 00doug staff 000000 000000 Log-Any-1.708 This software is copyright (c) 2017 by Jonathan Swartz, David Golden, and Doug Bell.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
Terms of the Perl programming language system itself
a) the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any
later version, or
b) the "Artistic License"
--- The GNU General Public License, Version 1, February 1989 ---
This software is Copyright (c) 2017 by Jonathan Swartz, David Golden, and Doug Bell.
This is free software, licensed under:
The GNU General Public License, Version 1, February 1989
GNU GENERAL PUBLIC LICENSE
Version 1, February 1989
Copyright (C) 1989 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The license agreements of most software companies try to keep users
at the mercy of those companies. By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.
When we speak of free software, we are referring to freedom, not
price. Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must tell them their rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License. The
"Program", below, refers to any such program or work, and a "work based
on the Program" means either the Program or any work containing the
Program or a portion of it, either verbatim or with modifications. Each
licensee is addressed as "you".
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program. You may charge a fee for the physical act of
transferring a copy.
2. You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:
a) cause the modified files to carry prominent notices stating that
you changed the files and the date of any change; and
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.
3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:
a) accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,
b) accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal charge
for the cost of distribution) a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of
Paragraphs 1 and 2 above; or,
c) accompany it with the information you received as to where the
corresponding source code may be obtained. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
Source code for a work means the preferred form of the work for making
modifications to it. For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.
4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License. However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.
5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions. You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.
7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of the license which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.
8. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
Copyright (C) 19yy
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 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19xx name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
program `Gnomovision' (a program to direct compilers to make passes
at assemblers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
That's all there is to it!
--- The Artistic License 1.0 ---
This software is Copyright (c) 2017 by Jonathan Swartz, David Golden, and Doug Bell.
This is free software, licensed under:
The Artistic License 1.0
The Artistic License
Preamble
The intent of this document is to state the conditions under which a Package
may be copied, such that the Copyright Holder maintains some semblance of
artistic control over the development of the package, while giving the users of
the package the right to use and distribute the Package in a more-or-less
customary fashion, plus the right to make reasonable modifications.
Definitions:
- "Package" refers to the collection of files distributed by the Copyright
Holder, and derivatives of that collection of files created through
textual modification.
- "Standard Version" refers to such a Package if it has not been modified,
or has been modified in accordance with the wishes of the Copyright
Holder.
- "Copyright Holder" is whoever is named in the copyright or copyrights for
the package.
- "You" is you, if you're thinking about copying or distributing this Package.
- "Reasonable copying fee" is whatever you can justify on the basis of media
cost, duplication charges, time of people involved, and so on. (You will
not be required to justify it to the Copyright Holder, but only to the
computing community at large as a market that must bear the fee.)
- "Freely Available" means that no fee is charged for the item itself, though
there may be fees involved in handling the item. It also means that
recipients of the item may redistribute it under the same conditions they
received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated disclaimers.
2. You may apply bug fixes, portability fixes and other modifications derived
from the Public Domain or from the Copyright Holder. A Package modified in such
a way shall still be considered the Standard Version.
3. You may otherwise modify your copy of this Package in any way, provided that
you insert a prominent notice in each changed file stating how and when you
changed that file, and provided that you do at least ONE of the following:
a) place your modifications in the Public Domain or otherwise make them
Freely Available, such as by posting said modifications to Usenet or an
equivalent medium, or placing the modifications on a major archive site
such as ftp.uu.net, or by allowing the Copyright Holder to include your
modifications in the Standard Version of the Package.
b) use the modified Package only within your corporation or organization.
c) rename any non-standard executables so the names do not conflict with
standard executables, which must also be provided, and provide a separate
manual page for each non-standard executable that clearly documents how it
differs from the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
4. You may distribute the programs of this Package in object code or executable
form, provided that you do at least ONE of the following:
a) distribute a Standard Version of the executables and library files,
together with instructions (in the manual page or equivalent) on where to
get the Standard Version.
b) accompany the distribution with the machine-readable source of the Package
with your modifications.
c) accompany any non-standard executables with their corresponding Standard
Version executables, giving the non-standard executables non-standard
names, and clearly documenting the differences in manual pages (or
equivalent), together with instructions on where to get the Standard
Version.
d) make other distribution arrangements with the Copyright Holder.
5. You may charge a reasonable copying fee for any distribution of this
Package. You may charge any fee you choose for support of this Package. You
may not charge a fee for this Package itself. However, you may distribute this
Package in aggregate with other (possibly commercial) programs as part of a
larger (possibly commercial) software distribution provided that you do not
advertise this Package as a product of your own.
6. The scripts and library files supplied as input to or produced as output
from the programs of this Package do not automatically fall under the copyright
of this Package, but belong to whomever generated them, and may be sold
commercially, and may be aggregated with this Package.
7. C or perl subroutines supplied by you and linked into this Package shall not
be considered part of this Package.
8. The name of the Copyright Holder may not be used to endorse or promote
products derived from this software without specific prior written permission.
9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
The End
Changes 100644 000765 000024 32331 13606765203 13627 0 ustar 00doug staff 000000 000000 Log-Any-1.708 Revision history for Log-Any
** denotes an incompatible change
1.708 2020-01-12 22:56:43-05:00 America/New_York
[Added]
- Added 'Capture' adapter for capturing log messages in an array or
running an arbitrary callback. This makes it easier to test log
messages, collect messages from a certain scope for later display.
Thanks @nrdvana! [Github #77]
- Added Log::Any::Adapter 'get' class method to get an adapter for
a category. This allows bypassing the Proxy and using the Adapter
directly. Doing so breaks all the features enabled by a Proxy, and
so should only be used in special circumstances (definitely not in
CPAN modules). Thanks @nrdvana! [Github #78]
- Added 'Multiplex' adapter for directing log output to one or more
Log::Any adapters. This allows, for example, basic logging to
Stderr and logging to a remote Syslogd or Elastic. Thanks
@jrubinator and @GrantStreetGroup for contributing this!
[Github #79, Github #16]
1.707 2018-08-01 22:55:01-05:00 America/Chicago
[Fixed]
- The local context hash (`$log->context`) and the log hash
(`$log->$level( $message, $hash )`) now get merged correctly,
combining contextual logging and structured logging. Thanks
@mephinet! [Github #76] [Github #73]
1.706 2018-07-06 20:20:00-05:00 America/Chicago
[Fixed]
- The File, Stderr, and Stdout adapters now correctly allow being
set to the "emergency" log level threshold. Previously, trying to
only allow "emergency" log lines would result in all logs being
written (and a warning about an invalid log level being set).
Thanks @alabamapaul! [Github #74]
1.705 2018-01-17 13:49:22-06:00 America/Chicago
[Fixed]
- Fixed the `binmode` attribute of the File adapter not working
properly. Thanks @MadLord80! [Github #72]
1.704 2017-12-17 18:13:33-06:00 America/Chicago
[Fixed]
- Fixed some invalid POD and added a test to ensure POD validity
before release. Thanks @shlomif! [Github #67][Github #68]
- Improved performance when no work needed to be done. Thanks
@mephinet! [Github #70]
1.703 2017-11-29 10:56:17-06:00 America/Chicago
[Fixed]
- Fixed log format methods (errorf, warnf, infof, etc...) not
returning the formatted message sometimes. Thanks @vshekun!
[Github #64]
1.702 2017-11-28 15:18:40-06:00 America/Chicago
[Fixed]
- Fixed log output disappearing when the `default_adapter` is set.
Thanks @dallaylaen! [Github #65]
1.701 2017-10-02 14:36:51-05:00 America/Chicago
[Fixed]
- Fixed more method aliases in Log::Any::Adapter::Syslog that were
mapped to invalid syslog priorities. Thanks @legaultp for the
patch!
1.700 2017-09-28 16:59:22-05:00 America/Chicago
[Fixed]
- Fixed version of Log::Any::Adapter::Syslog so that installing it
will also install the rest of Log-Any.
- Fixed method aliasing in Log::Any::Adapter::Syslog for "error"
log method. Thanks @legaultp for the patch!
1.051 2017-08-06 20:41:53-05:00 America/Chicago (TRIAL RELEASE)
[Fixed]
- LOG_ANY_DEFAULT_ADAPTER now correctly logs to the given adapter.
Previously, if no other adapter was set, Log::Any used its
default, super-fast "Null" proxy that simply drops all messages
without checking adapters. Now Log::Any will correctly detect the
environment variable and create the correct, normal proxy object.
Thanks @tm604 for the report and @mephinet for the patch!
1.050 2017-08-03 22:28:37-05:00 America/Chicago (TRIAL RELEASE)
[Added]
- Added structured logging to easily log single hash references in
a parsable format. Thanks @mephinet!
- Added contextual logging to attach information to log messages
based on the current context.
For example, all log messages being generated by a particular HTTP
request could be logged with the URL, even if they're from a part
of the application that doesn't know what HTTP is.
This is very similar to Log::Log4perl's Mapped Diagnostic Context.
Thanks @mephinet!
1.049 2017-03-28 16:02:10-05:00 America/Chicago
[Fixed]
- Fixed failing tests on Windows because of path separator
interpolation. Thanks @nanis [Github #56]
- Added explicit core dependency on Sys::Syslog in case of Perls
with non-standard core libraries. Thanks @nanis [Github #57]
1.048 2017-03-27 15:16:12-05:00 America/Chicago
- No changes since 1.047 trial release
1.047 2017-03-22 20:22:47-05:00 America/Chicago (TRIAL RELEASE)
[Fixed]
- Fixed backwards-compatibility with users using the Unix::Syslog
macros in Log::Any::Adapter::Syslog. This requires that the user
have Unix::Syslog installed (which Log::Any does not explicitly
depend on).
- Log level aliases are now case-insensitive to match the regular
log levels. Prior to this, "WARNING", "Warning", and "warning"
would all work, but "WARN", and "Warn" would not, only "warn".
Thanks to @0x62ash for reporting this issue. [Github #55]
- Invalid log levels for the File, Stderr, and Stdout adapters now
result in a warning, and the default level of "trace" is used.
Previously, no warning would be issued and no logs would be
generated. Thanks to @0x62ash for reporting this issue. [Github
#55]
1.046 2017-01-11 21:22:57-06:00 America/Chicago (TRIAL RELEASE)
[Added]
- The Syslog adapter is now part of the core distribution, since it
relies only on core Perl modules.
1.045 2016-11-11 21:52:46-06:00 America/Chicago
- No changes from previous (trial) release 1.044
1.044 2016-11-06 15:30:35-06:00 America/Chicago (TRIAL RELEASE)
[Fixed]
- Imported log object can now be called anything instead of just
`$log`. This means `use Log::Any '$LOG'` or `use Log::Any '$foo'`
now work.
1.043 2016-11-03 21:31:18-05:00 America/Chicago (TRIAL RELEASE)
[Fixed]
- Objects that overload stringification are now stringified
correctly (instead of run through Data::Dumper). Thanks @mephinet!
1.042 2016-08-26 23:37:33-05:00 America/Chicago
[Added]
- Default adapters can now be configured with arguments (thanks
@bjakubski!)
1.041 2016-08-18 00:00:10-05:00 America/Chicago (TRIAL RELEASE)
[Added]
- Logging methods now return the formatted log string so that it can
be used in a `die` or `warn` call.
[Changed]
- A new default log proxy (Log::Any::Proxy::Null) is used when there
are no adapters configured (and so no place for logs to go). This
proxy does no processing and is about 1000% percent faster on my
laptop.
[Fixed]
- Suppress 'redundant argument' warnings if too many arguments are
given to a log formatting string.
1.040 2016-02-24 17:47:00-05:00 America/New_York
[Fixed]
- Fixed duplicated documentation sections.
1.038 2016-02-10 14:15:31-07:00 America/Mazatlan
- No changes from 1.037
1.037 2016-02-05 20:22:34-05:00 America/New_York (TRIAL RELEASE)
[Fixed]
- Fixed t/filescreen.t Unicode string tests to use a backwards
compatible form. Should fix tests before 5.16.
1.035 2016-02-04 14:47:20-05:00 America/New_York (TRIAL RELEASE)
[Changed]
- The default formatter now replaces a code reference argument with
the results of calling the code reference ONLY when it is the first
argument (in place of a format string). Code references in
subsequent arguments (to sprintf) are not executed, as this would
break backwards compatibility.
[Documented]
- Noted that repeatedly calling 'set' to set an adapter without calling
'remove' or using the 'lexically' feature will leak memory.
1.033 2016-02-03 10:32:57-05:00 America/New_York (TRIAL RELEASE)
[Added]
- The default formatter now expands code references. If the first
argument is a code reference, it is expanded and returned. If an
argument to "sprintf" style formatting is a code reference, it is
expanded.
[Changed]
- The File adapter now opens files with the ":utf8" layer. It also
takes a 'binmode' attribute to change the default.
[Fixed]
- does_not_contain_ok test adapter function now gives proper
diagnostic message
- all diagnostic messages that output the captured log now
correctly dump the log with pretty formatting
[Documented]
- documented the 'proxy_class' argument to `get_logger`
[~Internal~]
- Data::Dumper is loaded lazily, to reduce module load times
for programs that don't need it.
1.032 2015-03-26 17:23:37-04:00 America/New_York
- no changes from 1.031
1.031 2015-03-26 06:08:17-04:00 America/New_York (TRIAL RELEASE)
[Fixed]
- Log::Any::Adapter::Test passed through all constructor arguments,
which could be fatal when mocking adapters without all key-value
pairs (like Log::Any::Adapter::File); now this only passes through
the category and ignores other parameters when used as an
adapter class override.
1.03 2015-01-01 22:39:41-05:00 America/New_York
[Changed]
- Log::Any::Proxy concatenates arguments to basic logging functions
with a space character before passing them to adapters as a single
string. This ensures consistency across adapters that handle
multiple arguments differently.
1.02 2014-12-28 07:06:49-05:00 America/New_York
[Fixed]
- Some adapters relied on Log::Any::Adapter::Util also loading
Log::Any so this behavior has been restored.
1.01 2014-12-26 22:25:13-05:00 America/New_York
[Fixed]
- 'numeric_level' was not exported properly from
Log::Any::Adapter::Util
1.00 2014-12-25 22:04:13-05:00 America/New_York
[Added]
- Logging now goes via a Log::Any::Proxy object instead of directly to
an adapter. This allows easy customization of the message production.
- File, Stdout, and Stderr adapters now support a minimum
log level parameter.
[Changed]
- Removed dead code from Log::Any::Adapter::Base; particularly this
was the formatting code, since this is now handled by
Log::Any::Proxy.
[Fixed]
- File will flock the handle when writing (if flock is avaiable).
- Won't die if adapters aren't loadable modules as long as they
provide a constructor. This allows using private adapters
defined in another file.
[Documented]
- Revised docs for creating adapters
- Fixed typos and improved docs for Log::Any::Adapter::Util; removed
stub docs for modules that didn't need it.
[Deprecated]
- Deprecated some methods in Log::Any::Adapter::Util
[Internal]
- Merged Log-Any and Log-Any-Adapter distributions; reduces code
duplication and ensures Log::Any and adapter framework stay in sync
- Eliminates all non-core dependencies (as of Perl 5.8.1), including
Capture::Tiny, Devel::GlobalDestruction and Guard
0.92 2014-12-15 07:12:38-05:00 America/New_York (TRIAL RELEASE)
0.91 2014-12-14 22:13:09-05:00 America/New_York (TRIAL RELEASE)
0.90 2014-12-12 17:08:22-05:00 America/New_York (TRIAL RELEASE)
0.15 Apr 10, 2013
* Fixes
- Hide 'package Log::Any::Adapter' from PAUSE/Module::Metadata - miyagawa
0.14 Aug 31, 2011
* Fixes
- Fix version number in Log/Any.pm - Stephen Thirlwall
0.13 Aug 2, 2011
* Fixes
- Fix typo in lib/Log/Any/Adapter/Test.pm - RT #69850 - Stephen Thirlwall
0.12 Mar 23, 2011
* Fixes
- Return false from null adapter is_xxx methods - RT #64164 - Chip Salzenberg
- Eliminate 'subroutine redefined' warning in case Log::Any::Adapter loaded before
Log::Any::Test
* Implementation
- Migrate to Dist::Zilla
0.11 Feb 12, 2010
* Improvements
- Add trace level - suggested by Szymon Swierkosz
0.10 Jan 5, 2010
* Fixes
- Fix Log::Any::Core to support references in printf-style methods
0.09 Jan 5, 2010
* Improvements
- Convert undef to string "" in printf-style methods - RT #53398, suggested by Steven Haryanto
0.08 Dec 15, 2009
* Fixes
- Fix Log::Any::Test to support full logging API (aliases and printf methods)
0.07 Dec 7, 2009
* Implementation
- Depend on Test::Simple rather than Test::More
* Improvements
- Add Log::Any::Test, to aid in testing code that uses Log::Any
0.06 Oct 31, 2009
* Fixes
- Implement Log::Any->set_adapter again for backward compatibility with 0.04 and earlier
0.05 Oct 27, 2009
* Implementation
- ** Strip Log::Any down to a relative minimum, so as to keep it stable and
unchanging. Move everything else to Log::Any::Adapter.
0.04 Sep 3, 2009
* Fixes
- Replace Test::Deep::cmp_deeply with an internal version to avoid Test::Deep dependency
0.03 Jul 17, 2009
* Improvements
- Eliminated extra '::Log' from adapter names, e.g. Log::Any::Adapter::Log::Dispatch is
now Log::Any::Adapter::Dispatch. The long name was properly descriptive but was making
me wince every time.
0.02 Jul 14, 2009
* Fixes
- Fix logging aliases like warn => warning
* Implementation
- Eliminate unnecessary Test/InternalOnly.pm class
- Precompute alias and method lists like Log::Any->logging_methods
0.01 Jul 11, 2009
- Initial version
META.yml 100644 000765 000024 6531 13606765203 13570 0 ustar 00doug staff 000000 000000 Log-Any-1.708 ---
abstract: 'Bringing loggers and listeners together'
author:
- 'Jonathan Swartz '
- 'David Golden '
- 'Doug Bell '
- 'Daniel Pittman '
- 'Stephen Thirlwall '
build_requires:
ExtUtils::MakeMaker: '0'
File::Spec: '0'
IO::Handle: '0'
IPC::Open3: '0'
Test::More: '0'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: Log-Any
no_index:
directory:
- eg
- examples
- inc
- share
- t
- xt
package:
- Log::Any::Manager::_Guard
provides:
Log::Any:
file: lib/Log/Any.pm
version: '1.708'
Log::Any::Adapter:
file: lib/Log/Any/Adapter.pm
version: '1.708'
Log::Any::Adapter::Base:
file: lib/Log/Any/Adapter/Base.pm
version: '1.708'
Log::Any::Adapter::Capture:
file: lib/Log/Any/Adapter/Capture.pm
version: '1.708'
Log::Any::Adapter::File:
file: lib/Log/Any/Adapter/File.pm
version: '1.708'
Log::Any::Adapter::Multiplex:
file: lib/Log/Any/Adapter/Multiplex.pm
version: '1.708'
Log::Any::Adapter::Null:
file: lib/Log/Any/Adapter/Null.pm
version: '1.708'
Log::Any::Adapter::Stderr:
file: lib/Log/Any/Adapter/Stderr.pm
version: '1.708'
Log::Any::Adapter::Stdout:
file: lib/Log/Any/Adapter/Stdout.pm
version: '1.708'
Log::Any::Adapter::Syslog:
file: lib/Log/Any/Adapter/Syslog.pm
version: '1.708'
Log::Any::Adapter::Test:
file: lib/Log/Any/Adapter/Test.pm
version: '1.708'
Log::Any::Adapter::Util:
file: lib/Log/Any/Adapter/Util.pm
version: '1.708'
Log::Any::Manager:
file: lib/Log/Any/Manager.pm
version: '1.708'
Log::Any::Proxy:
file: lib/Log/Any/Proxy.pm
version: '1.708'
Log::Any::Proxy::Null:
file: lib/Log/Any/Proxy/Null.pm
version: '1.708'
Log::Any::Proxy::Test:
file: lib/Log/Any/Proxy/Test.pm
version: '1.708'
Log::Any::Test:
file: lib/Log/Any/Test.pm
version: '1.708'
requires:
B: '0'
Carp: '0'
Data::Dumper: '0'
Exporter: '0'
Fcntl: '0'
File::Basename: '0'
FindBin: '0'
IO::File: '0'
List::Util: '0'
Storable: '0'
Sys::Syslog: '0'
Test::Builder: '0'
constant: '0'
strict: '0'
warnings: '0'
resources:
bugtracker: https://github.com/preaction/Log-Any/issues
homepage: https://github.com/preaction/Log-Any
repository: https://github.com/preaction/Log-Any.git
version: '1.708'
x_authority: cpan:PREACTION
x_contributors:
- 'bj5004 '
- 'cm-perl '
- 'Jonathan '
- 'Karen Etheridge '
- 'Konstantin S. Uvarin '
- 'Lucas Kanashiro '
- 'Maros Kollar '
- 'Maxim Vuets '
- 'mephinet '
- 'Michael Conrad '
- 'Nick Tonkin <1nickt@users.noreply.github.com>'
- 'Paul Durden '
- 'Philipp Gortan '
- 'Phill Legault '
- 'Shlomi Fish '
x_generated_by_perl: v5.28.0
x_serialization_backend: 'YAML::Tiny version 1.73'
MANIFEST 100644 000765 000024 2242 13606765203 13443 0 ustar 00doug staff 000000 000000 Log-Any-1.708 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.012.
CONTRIBUTING.md
Changes
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
README
cpanfile
lib/Log/.gitignore
lib/Log/Any.pm
lib/Log/Any/Adapter.pm
lib/Log/Any/Adapter/Base.pm
lib/Log/Any/Adapter/Capture.pm
lib/Log/Any/Adapter/Development.pod
lib/Log/Any/Adapter/File.pm
lib/Log/Any/Adapter/Multiplex.pm
lib/Log/Any/Adapter/Null.pm
lib/Log/Any/Adapter/Stderr.pm
lib/Log/Any/Adapter/Stdout.pm
lib/Log/Any/Adapter/Syslog.pm
lib/Log/Any/Adapter/Test.pm
lib/Log/Any/Adapter/Util.pm
lib/Log/Any/Manager.pm
lib/Log/Any/Proxy.pm
lib/Log/Any/Proxy/Null.pm
lib/Log/Any/Proxy/Test.pm
lib/Log/Any/Test.pm
t/00-compile.t
t/00-report-prereqs.dd
t/00-report-prereqs.t
t/TestAdapters.pm
t/adapter-import.t
t/author-pod-syntax.t
t/capture.t
t/context.t
t/default-adapter-env.t
t/default-adapter-params.t
t/default-adapter-use.t
t/default-adapter.t
t/default-vs-test.t
t/errors-adapter.t
t/filescreen.t
t/import.t
t/inner-adapter.t
t/log-any-test.t
t/memory.t
t/multiplex.t
t/null-proxy.t
t/proxy.t
t/release-backcompat.t
t/replace_log.t
t/sprintf.t
t/stringify.t
t/structured-logging.t
t/syslog.t
t/util.t
t/valid-methods.t
cpanfile 100644 000765 000024 1450 13606765203 14016 0 ustar 00doug staff 000000 000000 Log-Any-1.708 requires "B" => "0";
requires "Carp" => "0";
requires "Data::Dumper" => "0";
requires "Exporter" => "0";
requires "Fcntl" => "0";
requires "File::Basename" => "0";
requires "FindBin" => "0";
requires "IO::File" => "0";
requires "List::Util" => "0";
requires "Storable" => "0";
requires "Sys::Syslog" => "0";
requires "Test::Builder" => "0";
requires "constant" => "0";
requires "strict" => "0";
requires "warnings" => "0";
on 'test' => sub {
requires "ExtUtils::MakeMaker" => "0";
requires "File::Spec" => "0";
requires "IO::Handle" => "0";
requires "IPC::Open3" => "0";
requires "Test::More" => "0";
};
on 'test' => sub {
recommends "CPAN::Meta" => "2.120900";
};
on 'configure' => sub {
requires "ExtUtils::MakeMaker" => "0";
};
on 'develop' => sub {
requires "Test::Pod" => "1.41";
};
t 000755 000765 000024 0 13606765203 12415 5 ustar 00doug staff 000000 000000 Log-Any-1.708 util.t 100644 000765 000024 564 13606765203 13704 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t
use strict;
use warnings;
use Test::More tests => 3;
use Log::Any::Adapter::Util qw( numeric_level WARNING );
### Test that numeric level works with aliases, case-insensitive
is numeric_level( 'warn' ), WARNING(), 'warn alias is correct';
is numeric_level( 'Warn' ), WARNING(), 'Warn alias is correct';
is numeric_level( 'WARN' ), WARNING(), 'WARN alias is correct';
META.json 100644 000765 000024 12103 13606765203 13750 0 ustar 00doug staff 000000 000000 Log-Any-1.708 {
"abstract" : "Bringing loggers and listeners together",
"author" : [
"Jonathan Swartz ",
"David Golden ",
"Doug Bell ",
"Daniel Pittman ",
"Stephen Thirlwall "
],
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : 2
},
"name" : "Log-Any",
"no_index" : {
"directory" : [
"eg",
"examples",
"inc",
"share",
"t",
"xt"
],
"package" : [
"Log::Any::Manager::_Guard"
]
},
"prereqs" : {
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"develop" : {
"requires" : {
"Test::Pod" : "1.41"
}
},
"runtime" : {
"requires" : {
"B" : "0",
"Carp" : "0",
"Data::Dumper" : "0",
"Exporter" : "0",
"Fcntl" : "0",
"File::Basename" : "0",
"FindBin" : "0",
"IO::File" : "0",
"List::Util" : "0",
"Storable" : "0",
"Sys::Syslog" : "0",
"Test::Builder" : "0",
"constant" : "0",
"strict" : "0",
"warnings" : "0"
}
},
"test" : {
"recommends" : {
"CPAN::Meta" : "2.120900"
},
"requires" : {
"ExtUtils::MakeMaker" : "0",
"File::Spec" : "0",
"IO::Handle" : "0",
"IPC::Open3" : "0",
"Test::More" : "0"
}
}
},
"provides" : {
"Log::Any" : {
"file" : "lib/Log/Any.pm",
"version" : "1.708"
},
"Log::Any::Adapter" : {
"file" : "lib/Log/Any/Adapter.pm",
"version" : "1.708"
},
"Log::Any::Adapter::Base" : {
"file" : "lib/Log/Any/Adapter/Base.pm",
"version" : "1.708"
},
"Log::Any::Adapter::Capture" : {
"file" : "lib/Log/Any/Adapter/Capture.pm",
"version" : "1.708"
},
"Log::Any::Adapter::File" : {
"file" : "lib/Log/Any/Adapter/File.pm",
"version" : "1.708"
},
"Log::Any::Adapter::Multiplex" : {
"file" : "lib/Log/Any/Adapter/Multiplex.pm",
"version" : "1.708"
},
"Log::Any::Adapter::Null" : {
"file" : "lib/Log/Any/Adapter/Null.pm",
"version" : "1.708"
},
"Log::Any::Adapter::Stderr" : {
"file" : "lib/Log/Any/Adapter/Stderr.pm",
"version" : "1.708"
},
"Log::Any::Adapter::Stdout" : {
"file" : "lib/Log/Any/Adapter/Stdout.pm",
"version" : "1.708"
},
"Log::Any::Adapter::Syslog" : {
"file" : "lib/Log/Any/Adapter/Syslog.pm",
"version" : "1.708"
},
"Log::Any::Adapter::Test" : {
"file" : "lib/Log/Any/Adapter/Test.pm",
"version" : "1.708"
},
"Log::Any::Adapter::Util" : {
"file" : "lib/Log/Any/Adapter/Util.pm",
"version" : "1.708"
},
"Log::Any::Manager" : {
"file" : "lib/Log/Any/Manager.pm",
"version" : "1.708"
},
"Log::Any::Proxy" : {
"file" : "lib/Log/Any/Proxy.pm",
"version" : "1.708"
},
"Log::Any::Proxy::Null" : {
"file" : "lib/Log/Any/Proxy/Null.pm",
"version" : "1.708"
},
"Log::Any::Proxy::Test" : {
"file" : "lib/Log/Any/Proxy/Test.pm",
"version" : "1.708"
},
"Log::Any::Test" : {
"file" : "lib/Log/Any/Test.pm",
"version" : "1.708"
}
},
"release_status" : "stable",
"resources" : {
"bugtracker" : {
"web" : "https://github.com/preaction/Log-Any/issues"
},
"homepage" : "https://github.com/preaction/Log-Any",
"repository" : {
"type" : "git",
"url" : "https://github.com/preaction/Log-Any.git",
"web" : "https://github.com/preaction/Log-Any"
}
},
"version" : "1.708",
"x_authority" : "cpan:PREACTION",
"x_contributors" : [
"bj5004 ",
"cm-perl ",
"Jonathan ",
"Karen Etheridge ",
"Konstantin S. Uvarin ",
"Lucas Kanashiro ",
"Maros Kollar ",
"Maxim Vuets ",
"mephinet ",
"Michael Conrad ",
"Nick Tonkin <1nickt@users.noreply.github.com>",
"Paul Durden ",
"Philipp Gortan ",
"Phill Legault ",
"Shlomi Fish "
],
"x_generated_by_perl" : "v5.28.0",
"x_serialization_backend" : "Cpanel::JSON::XS version 4.06"
}
proxy.t 100644 000765 000024 4601 13606765203 14124 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use strict;
use warnings;
use Test::More;
use Log::Any::Test;
use Log::Any::Adapter 'Test';
plan tests => 18;
my ( $log, $out );
$log = Log::Any->get_logger( prefix => 'Foo: ' );
$out = $log->info("test");
$log->contains_ok(qr/^Foo: test$/, 'prefix added');
is $out, 'Foo: test', 'log message built is returned';
$log->clear;
$log = Log::Any->get_logger;
$out = $log->info(qw/one two three four/);
$log->contains_ok(qr/^one two three four$/, 'arguments concatenated');
is $out, 'one two three four', 'log message built is returned';
$log->clear;
$log = Log::Any->get_logger;
$out = $log->infof(sub { "ran sub" } );
$log->contains_ok(qr/^ran sub$/, 'default formatter expands coderefs');
is $out, 'ran sub', 'log message built is returned';
$log->clear;
$log = Log::Any->get_logger;
$out = $log->infof("got %s %s", "coderef", sub { "expanded" } );
$log->contains_ok(qr/DUMMY/, 'default formatter does not expand coderefs as sprintf args');
like $out, qr/DUMMY/, 'log message built is returned';
$log->clear;
{
# check that redundant parameters don't issue warnings (only on 5.22+)
my $w = '';
local $SIG{__WARN__} = sub { $w = shift };
$log = Log::Any->get_logger;
$log->infof("got %s", qw/Einstein Feynman/ );
$log->contains_ok(qr/Einstein/);
is( $w, '', 'no warning' );
$log->clear;
}
$log = Log::Any->get_logger( filter => sub { "@_"} );
$out = $log->emergency("test");
$log->contains_ok(qr/^main 0 test$/, 'filter has category and numeric level');
is $out, 'main 0 test', 'log message run through filter is returned';
$log->clear;
$log = Log::Any->get_logger( formatter => sub { "@_"} );
$out = $log->tracef("test foo");
$log->contains_ok(qr/^main 8 test foo$/, 'formatter has category and numeric level');
is $out, 'main 8 test foo', 'log message run through formatter is returned';
$log->clear;
$log = Log::Any->get_logger( category => 'Foo', filter => sub { "@_"} );
$out = $log->info("test");
$log->contains_ok(qr/^Foo 6 test$/, 'category override');
is $out, 'Foo 6 test', 'log message with category and run through filter is returned';
$log->clear;
$log = Log::Any->get_logger( category => 'Foo', prefix => 'foo', formatter => sub { "@_" } );
$log = $log->clone( prefix => 'bar ' );
$out = $log->tracef( 'test' );
$log->contains_ok( qr/^bar Foo 8 test$/, 'clone keeps existing properties and allows override' );
is $out, 'bar Foo 8 test', 'log message is returned';
$log->clear;
import.t 100644 000765 000024 1415 13606765203 14255 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t
# This file tests the import() method of the main Log::Any class. The
# tests in this file will frequently simply die if they fail.
#
use strict;
use warnings;
use Test::More tests => 2;
use Log::Any::Test;
# Test that we are allowed to call the imported Log::Any::Proxy object
# anything we want
{
package test1;
use Log::Any qw( $ANYTHING );
$ANYTHING->info( 'This must not die' );
$ANYTHING->contains_ok( qr/This must not die/, 'logged correctly' );
}
# Test that only the first thing that looks like a scalar is used to
# name the Log::Any::Proxy object
{
package test2;
use Log::Any qw( $LOG ), category => '$script';
$LOG->info( 'This must not die' );
$LOG->category_contains_ok( '$script', qr/This must not die/, 'logged correctly' );
}
memory.t 100644 000765 000024 6740 13606765203 14261 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use strict;
use warnings;
use Test::More tests => 34;
use Log::Any;
use Log::Any::Adapter::Util qw(cmp_deeply);
BEGIN {
$Log::Any::OverrideDefaultProxyClass = 'Log::Any::Proxy::Test';
}
{
package Foo;
use Log::Any qw($log);
sub log_debug {
my ( $class, $text ) = @_;
$log->debug($text) if $log->is_debug();
}
}
{
package Bar;
use Log::Any qw($log);
sub log_info {
my ( $class, $text ) = @_;
$log->info($text) if $log->is_info();
}
}
require Log::Any::Adapter;
$Baz::log = Log::Any->get_logger( category => 'Baz' );
my $main_log = Log::Any->get_logger();
is( $main_log->adapter, Log::Any->get_logger()->adapter, "memoization - no cat" );
is( $main_log->adapter, Log::Any->get_logger( category => 'main' )->adapter,
"memoization - cat" );
my $memclass = 'Log::Any::Adapter::Test';
my $nullclass = 'Log::Any::Adapter::Null';
isa_ok( $Foo::log->adapter, $nullclass, 'Foo::log before set' );
isa_ok( $Bar::log->adapter, $nullclass, 'Bar::log before set' );
isa_ok( $Baz::log->adapter, $nullclass, 'Baz::log before set' );
isa_ok( $main_log->adapter, $nullclass, 'main_log before set' );
my $entry = Log::Any::Adapter->set( { category => qr/Foo|Bar/ }, "+$memclass" );
isa_ok( $Foo::log->adapter, $memclass, 'Foo::log after first set' );
isa_ok( $Bar::log->adapter, $memclass, 'Bar::log after first set' );
isa_ok( $Baz::log->adapter, $nullclass, 'Baz::log after first set' );
isa_ok( $main_log->adapter, $nullclass, 'main_log after first set' );
my $entry2 =
Log::Any::Adapter->set( { category => qr/Baz|main/ }, "+$memclass" );
isa_ok( $Foo::log->adapter, $memclass, 'Foo::log after second set' );
isa_ok( $Bar::log->adapter, $memclass, 'Bar::log after second set' );
isa_ok( $Baz::log->adapter, $memclass, 'Baz::log after second set' );
isa_ok( $main_log->adapter, $memclass, 'main_log after second set' );
ok( $Foo::log ne $Bar::log, 'Foo::log and Bar::log are different' );
is( $main_log->adapter, Log::Any->get_logger()->adapter, "memoization - no cat" );
is( $main_log->adapter, Log::Any->get_logger( category => 'main' )->adapter,
"memoization - cat" );
cmp_deeply( $Foo::log->msgs, [], 'Foo::log has empty buffer' );
cmp_deeply( $Bar::log->msgs, [], 'Bar::log has empty buffer' );
cmp_deeply( $main_log->msgs, [], 'Bar::log has empty buffer' );
ok( $Foo::log ne $Bar::log, 'Foo::log and Bar::log are different objects' );
Foo->log_debug('for foo');
Bar->log_info('for bar');
$main_log->error('for main');
$Foo::log->category_contains_ok(
Foo => qr/for foo/,
'Foo log appeared in memory'
);
$Bar::log->category_contains_ok(
Bar => qr/for bar/,
'Bar log appeared in memory'
);
$main_log->category_contains_ok(
main => qr/for main/,
'main log appeared in memory'
);
Log::Any::Adapter->remove($entry);
isa_ok( $Foo::log->adapter, $nullclass, 'Foo::log' );
isa_ok( $Bar::log->adapter, $nullclass, 'Bar::log' );
isa_ok( $Baz::log->adapter, $memclass, 'Baz::log' );
isa_ok( $main_log->adapter, $memclass, 'main_log' );
Log::Any::Adapter->remove($entry2);
isa_ok( $Foo::log->adapter, $nullclass, 'Foo::log' );
isa_ok( $Bar::log->adapter, $nullclass, 'Bar::log' );
isa_ok( $Baz::log->adapter, $nullclass, 'Baz::log' );
isa_ok( $main_log->adapter, $nullclass, 'main_log' );
{
Log::Any::Adapter->set( { category => 'Foo', lexically => \my $lex },
"+$memclass" );
isa_ok( $Foo::log->adapter, $memclass, 'Foo::log in lexical scope' );
}
isa_ok( $Foo::log->adapter, $nullclass, 'Foo::log outside lexical scope' );
syslog.t 100644 000765 000024 3564 13606765203 14272 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t
use strict;
use warnings;
use Test::More tests => 27;
use Log::Any qw{$log};
use Log::Any::Adapter;
use Log::Any::Adapter::Syslog;
# Mock the Sys::Syslog classes to behave as we desire.
my @logs;
my @openlogs;
no warnings qw( redefine once );
local *Log::Any::Adapter::Syslog::openlog = sub { push @openlogs, \@_ };
local *Log::Any::Adapter::Syslog::syslog = sub { push @logs, \@_ };
local *Log::Any::Adapter::Syslog::closelog = sub { };
Log::Any::Adapter->set('Syslog');
my %tests = (
trace => "debug",
debug => "debug",
info => "info",
notice => "notice",
warning => "warning",
error => "err",
critical => "crit",
alert => "alert",
emergency => "emerg",
);
for my $level (sort keys %tests) {
my $msg = "${level} level log";
$log->$level($msg);
is $logs[-1][0], $tests{$level}, "Log::Any ${level} maps to the right syslog priority";
is $logs[-1][1], $msg, "Log::Any passed through the right message";
}
# Check that the log was opened
is $openlogs[-1][0], 'syslog.t', 'log opened with correct name';
is $openlogs[-1][1], 'pid', 'log opened with correct options';
is $openlogs[-1][2], 'local7', 'log opened with correct facility';
# Check that we can open another log
Log::Any::Adapter->set( 'Syslog',
name => 'foo',
options => "pid,perror",
facility => 'user',
);
$log->error( "foo" );
is $openlogs[-1][0], 'foo', 'log opened with correct name';
is $openlogs[-1][1], 'pid,perror', 'log opened with correct options';
is $openlogs[-1][2], 'user', 'log opened with correct facility';
# Check that log level works
@logs = ();
Log::Any::Adapter->set( 'Syslog', log_level => 'emergency' );
$log->error( 'foo' );
is scalar @logs, 0, 'no log written because log_level too high';
$log->emergency( 'help' );
is $logs[-1][0], 'emerg', 'emergency log is logged';
is $logs[-1][1], 'help', 'emergency log is logged';
Makefile.PL 100644 000765 000024 3540 13606765203 14266 0 ustar 00doug staff 000000 000000 Log-Any-1.708 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.012.
use strict;
use warnings;
use ExtUtils::MakeMaker;
my %WriteMakefileArgs = (
"ABSTRACT" => "Bringing loggers and listeners together",
"AUTHOR" => "Jonathan Swartz , David Golden , Doug Bell , Daniel Pittman , Stephen Thirlwall ",
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => 0
},
"DISTNAME" => "Log-Any",
"LICENSE" => "perl",
"NAME" => "Log::Any",
"PREREQ_PM" => {
"B" => 0,
"Carp" => 0,
"Data::Dumper" => 0,
"Exporter" => 0,
"Fcntl" => 0,
"File::Basename" => 0,
"FindBin" => 0,
"IO::File" => 0,
"List::Util" => 0,
"Storable" => 0,
"Sys::Syslog" => 0,
"Test::Builder" => 0,
"constant" => 0,
"strict" => 0,
"warnings" => 0
},
"TEST_REQUIRES" => {
"ExtUtils::MakeMaker" => 0,
"File::Spec" => 0,
"IO::Handle" => 0,
"IPC::Open3" => 0,
"Test::More" => 0
},
"VERSION" => "1.708",
"test" => {
"TESTS" => "t/*.t"
}
);
my %FallbackPrereqs = (
"B" => 0,
"Carp" => 0,
"Data::Dumper" => 0,
"Exporter" => 0,
"ExtUtils::MakeMaker" => 0,
"Fcntl" => 0,
"File::Basename" => 0,
"File::Spec" => 0,
"FindBin" => 0,
"IO::File" => 0,
"IO::Handle" => 0,
"IPC::Open3" => 0,
"List::Util" => 0,
"Storable" => 0,
"Sys::Syslog" => 0,
"Test::Builder" => 0,
"Test::More" => 0,
"constant" => 0,
"strict" => 0,
"warnings" => 0
);
unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {
delete $WriteMakefileArgs{TEST_REQUIRES};
delete $WriteMakefileArgs{BUILD_REQUIRES};
$WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs;
}
delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
unless eval { ExtUtils::MakeMaker->VERSION(6.52) };
WriteMakefile(%WriteMakefileArgs);
capture.t 100644 000765 000024 5771 13606765203 14417 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use strict;
use warnings;
use Test::More tests => 12;
use Log::Any;
use Log::Any::Adapter::Util qw(cmp_deeply);
BEGIN {
$Log::Any::OverrideDefaultProxyClass = 'Log::Any::Proxy::Test';
}
{
package Foo;
use Log::Any qw($log);
sub log_debug {
my ( $class, $text ) = @_;
$log->debug($text) if $log->is_debug();
}
}
{
package Bar;
use Log::Any qw($log);
sub log_info {
my ( $class, $text ) = @_;
$log->info($text) if $log->is_info();
}
}
require Log::Any::Adapter;
my $main_log = Log::Any->get_logger();
my $foo_log = $Foo::log;
# redirect to array
{
Log::Any::Adapter->set( { lexically => \my $scope }, Capture => to => \my @array );
$main_log->info('Test');
is_deeply( shift @array, [ 'info', 'main', 'Test' ], 'main logged to arrayref' );
$main_log->info('Test', 'Test2', { val => 42 });
is_deeply( shift @array, [ 'info', 'main', 'Test Test2 {val => 42}' ], 'main logged flattened arguments' );
$foo_log->trace('Test2');
is_deeply( shift @array, [ 'trace', 'Foo', 'Test2' ], 'Foo logged to arrayref' );
}
# redirect_to_coderef
{
my @last;
Log::Any::Adapter->set( { lexically => \my $scope }, Capture => to => sub { @last= @_ } );
$main_log->info('Test');
is_deeply( \@last, [ 'info', 'main', 'Test' ], 'main logged to coderef' );
$foo_log->trace('Test2');
is_deeply( \@last, [ 'trace', 'Foo', 'Test2' ], 'Foo logged to coderef' );
}
# redirect text only
{
Log::Any::Adapter->set(
{ lexically => \my $scope },
Capture => ( text => \my @array, log_level => 'info' )
);
$main_log->info('Test');
is_deeply( shift @array, 'Test', 'main logged text-only to arrayref' );
$main_log->info('Test', 'Test2', { val => 42 });
is_deeply( shift @array, 'Test Test2 {val => 42}', 'main logged flattened arguments' );
$foo_log->trace('Test2');
is_deeply( shift @array, undef, 'Foo ->trace was ignored' );
}
# redirect structured
{
{
Log::Any::Adapter->set(
{ lexically => \my $scope },
Capture => ( structured => \my @array )
);
$main_log->info('Test', 'Test2', { blah => 1 });
is_deeply( shift @array, [ 'info', 'main', 'Test', 'Test2', { blah => 1 } ], 'main logged full data' );
local $main_log->context->{val} = 42;
$main_log->info('Test', 'Test2', { blah => 1 });
is_deeply( shift @array, [ 'info', 'main', 'Test', 'Test2', { blah => 1, val => 42 } ], 'main logged combined context' );
}
{
Log::Any::Adapter->set(
{ lexically => \my $scope },
Capture => ( format => 'structured', to => \my @array )
);
$foo_log->trace('Test3', ['Test4']);
is_deeply( shift @array, [ 'trace', 'Foo', 'Test3', ['Test4'] ], 'Foo logged full data' );
local $foo_log->context->{val} = 42;
$foo_log->trace('Test3', ['Test4']);
is_deeply( shift @array, [ 'trace', 'Foo', 'Test3', ['Test4'], { val => 42 } ], 'Foo logged combined context' );
}
}
context.t 100755 000765 000024 3263 13606765203 14435 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t #! /usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 2;
use Log::Any::Adapter;
use Log::Any '$log';
use File::Basename;
use FindBin;
use lib $FindBin::RealBin;
use TestAdapters;
$log->context->{progname} = basename($0);
$log->context->{pid} = 42;
sub process_file {
my ($file) = @_;
my $log2 = Log::Any->get_logger( category => 'MyApp::FileProcessor' );
$log2->info('Performing work', {file => $file});
}
sub process_dir {
my ($dir) = @_;
my $log1 = Log::Any->get_logger( category => 'MyApp::DirWalker' );
local $log1->context->{directory} = $dir;
local $log1->context->{file} = 'will be overwritten...';
for ( 1 .. 3 ) {
local $log1->context->{pass} = $_;
process_file("$dir/$_");
}
}
Log::Any::Adapter->set('+TestAdapters::Normal');
process_dir('/foo');
{
local $log->context->{pid} = 84;
Log::Any::Adapter->set('+TestAdapters::Structured');
process_dir('/bar');
}
my @expected_text_log = map {
qq(Performing work {directory => "/foo",file => "/foo/$_",pass => $_,pid => 42,progname => "context.t"})
} ( 1 .. 3 );
my @expected_structured_log = map {
{ category => 'MyApp::FileProcessor',
data => [
{ directory => '/bar',
file => "/bar/$_",
pass => $_,
pid => 84,
progname => 'context.t'
}
],
level => 'info',
messages => ['Performing work']
}
} ( 1 .. 3 );
is_deeply( \@TestAdapters::TEXT_LOG, \@expected_text_log,
'text log is correct' );
is_deeply( \@TestAdapters::STRUCTURED_LOG,
\@expected_structured_log, 'structured log is correct' );
sprintf.t 100644 000765 000024 1231 13606765203 14424 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use strict;
use warnings;
use Test::More;
use Log::Any::Test;
use Log::Any::Adapter 'Test';
use Log::Any::Adapter::Util qw(cmp_deeply);
plan tests => 1;
my $log = Log::Any->get_logger();
my @params = ( "args for %s: %s", 'app', [ 'foo', { 'bar' => 5 } ] );
$log->info("not %s", "sprintf");
$log->debugf(@params);
cmp_deeply(
$log->msgs,
[
{
message => "not \%s sprintf",
level => 'info',
category => 'main'
},
{
message => q|args for app: ["foo",{bar => 5}]|,
level => 'debug',
category => 'main'
}
],
'message was formatted'
);
multiplex.t 100644 000765 000024 10754 13606765203 15014 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use strict;
use warnings;
use Test::More tests => 16;
use Log::Any;
use Log::Any::Adapter;
{
package _My::Structured::Adapter;
use base 'Log::Any::Adapter::Base';
use Log::Any::Adapter::Util qw(make_method);
our $instance;
our $is_logging = 0;
our @structured_args = ();
sub init { $instance = shift }
sub structured { @structured_args = @_ }
foreach my $method ( Log::Any->detection_methods() ) {
make_method( $method, sub { $is_logging } );
}
}
{
package _My::Unstructured::Adapter;
use base 'Log::Any::Adapter::Base';
use Log::Any::Adapter::Util qw(make_method);
our $instance;
our $is_logging = 0;
our %unstructured_args = ();
sub init { $instance = shift }
# Log what we called at each severity
foreach my $method ( Log::Any->logging_methods() ) {
make_method( $method, sub { $unstructured_args{$method} = [@_] } );
}
foreach my $method ( Log::Any->detection_methods() ) {
make_method( $method, sub { $is_logging } );
}
}
require_ok('Log::Any::Adapter::Multiplex');
# basic_arg_validation
{
# helpful for making sure init() is called on each set() below
my $log = Log::Any->get_logger;
eval { Log::Any::Adapter->set( 'Multiplex' ) };
ok $@, 'adapters are required';
eval {
Log::Any::Adapter->set(
'Multiplex',
adapters => 'Stdout'
)
};
ok $@, 'adapters must be a hash';
eval {
Log::Any::Adapter->set(
'Multiplex',
adapters => 'Stdout'
)
};
ok $@, 'adapters must be a hash';
eval {
Log::Any::Adapter->set(
'Multiplex',
adapters => {
Stdout => {}
}
)
};
ok $@, 'adapters values must be arrays';
eval {
Log::Any::Adapter->set(
'Multiplex',
adapters => {
Stdout => [ log_level => 'info' ],
Stderr => [],
}
)
};
ok !$@, "Multiplex set up as expected"
or diag $@;
}
# multiplex_implementation
{
my %random_args = ( log_level => 'scream' );
my $entry = Log::Any::Adapter->set(
'Multiplex',
adapters => {
'+_My::Structured::Adapter' => [ %random_args ],
'+_My::Unstructured::Adapter' => [ %random_args ],
}
);
my $log = Log::Any->get_logger();
ok !$log->is_info, "multiplex logging off for both destinations";
$_My::Structured::Adapter::is_logging = 1;
$_My::Unstructured::Adapter::is_logging = 0;
ok $log->is_info, "multiplex logging on for one destination";
$_My::Structured::Adapter::is_logging = 0;
$_My::Unstructured::Adapter::is_logging = 1;
ok $log->is_info, "multiplex logging on for other destination";
$_My::Structured::Adapter::is_logging = 1;
$_My::Unstructured::Adapter::is_logging = 1;
ok $log->is_info, "multiplex logging on for both destinations";
my $structured_adapter = $_My::Structured::Adapter::instance;
my $unstructured_adapter = $_My::Unstructured::Adapter::instance;
is $structured_adapter->{log_level},
$random_args{log_level},
"Arguments passed to structured adapter";
is $unstructured_adapter->{log_level},
$random_args{log_level},
"Arguments passed to unstructured adapter";
my $message = "In a bottle";
my $level = 'info';
my $cat = __PACKAGE__;
$log->context->{foo} = 'bar';
my $ctx_str = '{foo => "bar"}';
$log->$level($message);
is_deeply [ @_My::Structured::Adapter::structured_args ],
[ $structured_adapter, $level, $cat, $message, $log->context ],
"Passed appropriate structured args";
is_deeply $_My::Unstructured::Adapter::unstructured_args{$level},
[ $unstructured_adapter, $message, $ctx_str ],
"Passed appropriate unstructured args";
@_My::Structured::Adapter::structured_args = ();
$_My::Structured::Adapter::is_logging = 0;
$log->$level($message);
is_deeply [ @_My::Structured::Adapter::structured_args ],
[ ],
"structured adapter not called when not logging";
$_My::Structured::Adapter::is_logging = 1;
%_My::Unstructured::Adapter::unstructured_args = ();
$_My::Unstructured::Adapter::is_logging = 0;
$log->$level($message);
is_deeply { %_My::Unstructured::Adapter::unstructured_args },
{ },
"unstructured adapter not called when not logging";
}
stringify.t 100644 000765 000024 1067 13606765203 14764 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use warnings;
use strict;
use Test::More tests => 1;
{
package Test_URI;
use overload '""' => \&stringify;
sub new {
my ( $class, $s ) = @_;
return bless { s => $s }, $class;
}
sub stringify {
my ($self) = @_;
return $self->{s};
}
}
use Log::Any '$log';
use Log::Any::Adapter 'Test';
my $uri = Test_URI->new('http://slashdot.org/');
$log->infof( 'Fetching %s', $uri );
is(
Log::Any::Adapter::Test->msgs->[0]->{message},
'Fetching http://slashdot.org/',
'URI was correctly stringified'
);
00-compile.t 100644 000765 000024 3572 13606765203 14616 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use 5.006;
use strict;
use warnings;
# this test was generated with Dist::Zilla::Plugin::Test::Compile 2.058
use Test::More;
plan tests => 17 + ($ENV{AUTHOR_TESTING} ? 1 : 0);
my @module_files = (
'Log/Any.pm',
'Log/Any/Adapter.pm',
'Log/Any/Adapter/Base.pm',
'Log/Any/Adapter/Capture.pm',
'Log/Any/Adapter/File.pm',
'Log/Any/Adapter/Multiplex.pm',
'Log/Any/Adapter/Null.pm',
'Log/Any/Adapter/Stderr.pm',
'Log/Any/Adapter/Stdout.pm',
'Log/Any/Adapter/Syslog.pm',
'Log/Any/Adapter/Test.pm',
'Log/Any/Adapter/Util.pm',
'Log/Any/Manager.pm',
'Log/Any/Proxy.pm',
'Log/Any/Proxy/Null.pm',
'Log/Any/Proxy/Test.pm',
'Log/Any/Test.pm'
);
# no fake home requested
my @switches = (
-d 'blib' ? '-Mblib' : '-Ilib',
);
use File::Spec;
use IPC::Open3;
use IO::Handle;
open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!";
my @warnings;
for my $lib (@module_files)
{
# see L
my $stderr = IO::Handle->new;
diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
$^X, @switches, '-e', "require q[$lib]"))
if $ENV{PERL_COMPILE_TEST_DEBUG};
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
binmode $stderr, ':crlf' if $^O eq 'MSWin32';
my @_warnings = <$stderr>;
waitpid($pid, 0);
is($?, 0, "$lib loaded ok");
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
and not eval { +require blib; blib->VERSION('1.01') };
if (@_warnings)
{
warn @_warnings;
push @warnings, @_warnings;
}
}
is(scalar(@warnings), 0, 'no warnings found')
or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING};
Log 000755 000765 000024 0 13606765203 13441 5 ustar 00doug staff 000000 000000 Log-Any-1.708/lib Any.pm 100644 000765 000024 36657 13606765203 14727 0 ustar 00doug staff 000000 000000 Log-Any-1.708/lib/Log use 5.008001;
use strict;
use warnings;
package Log::Any;
# ABSTRACT: Bringing loggers and listeners together
our $VERSION = '1.708';
use Log::Any::Manager;
use Log::Any::Proxy::Null;
use Log::Any::Adapter::Util qw(
require_dynamic
detection_aliases
detection_methods
log_level_aliases
logging_aliases
logging_and_detection_methods
logging_methods
);
# This is overridden in Log::Any::Test
our $OverrideDefaultAdapterClass;
our $OverrideDefaultProxyClass;
# singleton and accessor
{
my $manager = Log::Any::Manager->new();
sub _manager { return $manager }
}
sub import {
my $class = shift;
my $caller = caller();
my @export_params = ( $caller, @_ );
$class->_export_to_caller(@export_params);
}
sub _export_to_caller {
my $class = shift;
my $caller = shift;
# Parse parameters passed to 'use Log::Any'
my $saw_log_param;
my @params;
while ( my $param = shift @_ ) {
if ( !$saw_log_param && $param =~ /^\$(\w+)/ ) {
$saw_log_param = $1; # defer until later
next; # singular
}
else {
push @params, $param, shift @_; # pairwise
}
}
unless ( @params % 2 == 0 ) {
require Carp;
Carp::croak("Argument list not balanced: @params");
}
# get logger if one was requested
if ( defined $saw_log_param ) {
no strict 'refs';
my $proxy = $class->get_logger( category => $caller, @params );
my $varname = "${caller}::${saw_log_param}";
*$varname = \$proxy;
}
}
sub get_logger {
my ( $class, %params ) = @_;
no warnings 'once';
my $category =
defined $params{category} ? delete $params{'category'} : caller;
if ( my $default = delete $params{'default_adapter'} ) {
my @default_adapter_params = ();
if (ref $default eq 'ARRAY') {
($default, @default_adapter_params) = @{ $default };
}
# Every default adapter is set only for a given logger category.
# When another adapter is configured (by using
# Log::Any::Adapter->set) for this category, it takes
# precedence, but if that adapter is later removed, the default
# we set here takes over again.
$class->_manager->set_default(
$category, $default, @default_adapter_params
);
}
my $proxy_class = $class->_get_proxy_class( delete $params{proxy_class} );
my $adapter = $class->_manager->get_adapter( $category );
my $context = $class->_manager->get_context();
require_dynamic($proxy_class);
return $proxy_class->new(
%params, adapter => $adapter, category => $category, context => $context
);
}
sub _get_proxy_class {
my ( $self, $proxy_name ) = @_;
return $Log::Any::OverrideDefaultProxyClass
if $Log::Any::OverrideDefaultProxyClass;
return "Log::Any::Proxy" if !$proxy_name && _manager->has_consumer;
return "Log::Any::Proxy::Null" if !$proxy_name;
my $proxy_class = (
substr( $proxy_name, 0, 1 ) eq '+'
? substr( $proxy_name, 1 )
: "Log::Any::Proxy::$proxy_name"
);
return $proxy_class;
}
# For backward compatibility
sub set_adapter {
my $class = shift;
Log::Any->_manager->set(@_);
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Log::Any - Bringing loggers and listeners together
=head1 VERSION
version 1.708
=head1 SYNOPSIS
In a CPAN or other module:
package Foo;
use Log::Any qw($log);
# log a string
$log->error("an error occurred");
# log a string and some data
$log->info("program started",
{progname => $0, pid => $$, perl_version => $]});
# log a string and data using a format string
$log->debugf("arguments are: %s", \@_);
# log an error and throw an exception
die $log->fatal("a fatal error occurred");
In a Moo/Moose-based module:
package Foo;
use Log::Any ();
use Moo;
has log => (
is => 'ro',
default => sub { Log::Any->get_logger },
);
In your application:
use Foo;
use Log::Any::Adapter;
# Send all logs to Log::Log4perl
Log::Any::Adapter->set('Log4perl');
# Send all logs to Log::Dispatch
my $log = Log::Dispatch->new(outputs => [[ ... ]]);
Log::Any::Adapter->set( 'Dispatch', dispatcher => $log );
# See Log::Any::Adapter documentation for more options
=head1 DESCRIPTION
C provides a standard log production API for modules.
L allows applications to choose the mechanism for log
consumption, whether screen, file or another logging mechanism like
L or L.
Many modules have something interesting to say. Unfortunately there is no
standard way for them to say it - some output to STDERR, others to C,
others to custom file logs. And there is no standard way to get a module to
start talking - sometimes you must call a uniquely named method, other times
set a package variable.
This being Perl, there are many logging mechanisms available on CPAN. Each has
their pros and cons. Unfortunately, the existence of so many mechanisms makes
it difficult for a CPAN author to commit his/her users to one of them. This may
be why many CPAN modules invent their own logging or choose not to log at all.
To untangle this situation, we must separate the two parts of a logging API.
The first, I, includes methods to output logs (like
C<$log-Edebug>) and methods to inspect whether a log level is activated
(like C<$log-Eis_debug>). This is generally all that CPAN modules care
about. The second, I, includes a way to configure where
logging goes (a file, the screen, etc.) and the code to send it there. This
choice generally belongs to the application.
A CPAN module uses C to get a log producer object. An application,
in turn, may choose one or more logging mechanisms via L, or
none at all.
C has a very tiny footprint and no dependencies beyond Perl 5.8.1,
which makes it appropriate for even small CPAN modules to use. It defaults to
'null' logging activity, so a module can safely log without worrying about
whether the application has chosen (or will ever choose) a logging mechanism.
See L for the
original post proposing this module.
=head1 LOG LEVELS
C supports the following log levels and aliases, which is meant to be
inclusive of the major logging packages:
trace
debug
info (inform)
notice
warning (warn)
error (err)
critical (crit, fatal)
alert
emergency
Levels are translated as appropriate to the underlying logging mechanism. For
example, log4perl only has six levels, so we translate 'notice' to 'info' and
the top three levels to 'fatal'. See the documentation of an adapter class
for specifics.
=head1 CATEGORIES
Every logger has a category, generally the name of the class that asked for the
logger. Some logging mechanisms, like log4perl, can direct logs to different
places depending on category.
=head1 PRODUCING LOGS (FOR MODULES)
=head2 Getting a logger
The most convenient way to get a logger in your module is:
use Log::Any qw($log);
This creates a package variable I<$log> and assigns it to the logger for the
current package. It is equivalent to
our $log = Log::Any->get_logger;
In general, to get a logger for a specified category:
my $log = Log::Any->get_logger(category => $category)
If no category is specified, the calling package is used.
A logger object is an instance of L, which passes
on messages to the L handling its category.
If the C argument is passed, an alternative to
L (such as a subclass) will be instantiated and returned
instead. The argument is automatically prepended with "Log::Any::Proxy::".
If instead you want to pass the full name of a proxy class, prefix it with
a "+". E.g.
# Log::Any::Proxy::Foo
my $log = Log::Any->get_logger(proxy_class => 'Foo');
# MyLog::Proxy
my $log = Log::Any->get_logger(proxy_class => '+MyLog::Proxy');
=head2 Logging
To log a message, pass a single string to any of the log levels or aliases. e.g.
$log->error("this is an error");
$log->warn("this is a warning");
$log->warning("this is also a warning");
The log string will be returned so that it can be used further (e.g. for a C or
C call).
You should B include a newline in your message; that is the responsibility
of the logging mechanism, which may or may not want the newline.
If you want to log additional structured data alongside with your string, you
can add a single hashref after your log string. e.g.
$log->info("program started",
{progname => $0, pid => $$, perl_version => $]});
If the configured L does not support logging structured data,
the hash will be converted to a string using L.
There are also versions of each of the logging methods with an additional "f" suffix
(C, C, C, etc.) that format a list of arguments. The
specific formatting mechanism and meaning of the arguments is controlled by the
L object.
$log->errorf("an error occurred: %s", $@);
$log->debugf("called with %d params: %s", $param_count, \@params);
By default it renders like L|perlfunc/"sprintf FORMAT, LIST">,
with the following additional features:
=over
=item *
Any complex references (like C<\@params> above) are automatically converted to
single-line strings with L.
=item *
Any undefined values are automatically converted to the string "".
=back
=head2 Log level detection
To detect whether a log level is on, use "is_" followed by any of the log
levels or aliases. e.g.
if ($log->is_info()) { ... }
$log->debug("arguments are: " . Dumper(\@_))
if $log->is_debug();
This is important for efficiency, as you can avoid the work of putting together
the logging message (in the above case, stringifying C<@_>) if the log level is
not active.
The formatting methods (C, C, etc.) check the log level for you.
Some logging mechanisms don't support detection of log levels. In these cases
the detection methods will always return 1.
In contrast, the default logging mechanism - Null - will return 0 for all
detection methods.
=head2 Log context data
C supports logging context data by exposing the C
hashref. All the key/value pairs added to this hash will be printed
with every log message. You can localize the data so that it will be
removed again automatically at the end of the block:
$log->context->{directory} = $dir;
for my $file (glob "$dir/*") {
local $log->context->{file} = basename($file);
$log->warn("Can't read file!") unless -r $file;
}
This will produce the following line:
Can't read file! {directory => '/foo',file => 'bar'}
If the configured L does not support structured
data, the context hash will be converted to a string using
L, and will be appended to the log message.
=head2 Setting an alternate default logger
When no other adapters are configured for your logger, C
uses the C. To choose something other than Null as
the default, either set the C environment
variable, or pass it as a parameter when loading C
use Log::Any '$log', default_adapter => 'Stderr';
The name of the default class follows the same rules as used by L.
To pass arguments to the default adapter's constructor, use an arrayref:
use Log::Any '$log', default_adapter => [ 'File' => '/var/log/mylog.log' ];
When a consumer configures their own adapter, the default adapter will be
overridden. If they later remove their adapter, the default adapter will be
used again.
=head2 Configuring the proxy
Any parameters passed on the import line or via the C method
are passed on to the L constructor.
use Log::Any '$log', filter => \&myfilter;
=head2 Testing
L provides a mechanism to test code that uses C.
=head1 CONSUMING LOGS (FOR APPLICATIONS)
Log::Any provides modules with a L object, which is the log
producer. To consume its output and direct it where you want (a file, the
screen, syslog, etc.), you use L along with a
destination-specific subclass.
For example, to send output to a file via L, your
application could do this:
use Log::Any::Adapter ('File', '/path/to/file.log');
See the L documentation for more details.
=head1 Q & A
=over
=item Isn't Log::Any just yet another logging mechanism?
No. C does not include code that knows how to log to a particular
place (file, screen, etc.) It can only forward logging requests to another
logging mechanism.
=item Why don't you just pick the best logging mechanism, and use and promote it?
Each of the logging mechanisms have their pros and cons, particularly in terms
of how they are configured. For example, log4perl offers a great deal of power
and flexibility but uses a global and potentially heavy configuration, whereas
L is extremely configuration-light but doesn't handle
categories. There is also the unnamed future logger that may have advantages
over either of these two, and all the custom in-house loggers people have
created and cannot (for whatever reason) stop using.
=item Is it safe for my critical module to depend on Log::Any?
Our intent is to keep C minimal, and change it only when absolutely
necessary. Most of the "innovation", if any, is expected to occur in
C, which your module should not have to depend on (unless it
wants to direct logs somewhere specific). C has no non-core dependencies.
=item Why doesn't Log::Any use I?
To encourage CPAN module authors to adopt and use C, we aim to have
as few dependencies and chances of breakage as possible. Thus, no C or
other niceties.
=back
=head1 AUTHORS
=over 4
=item *
Jonathan Swartz
=item *
David Golden
=item *
Doug Bell
=item *
Daniel Pittman
=item *
Stephen Thirlwall
=back
=head1 CONTRIBUTORS
=for stopwords bj5004 cm-perl Jonathan Karen Etheridge Konstantin S. Uvarin Lucas Kanashiro Maros Kollar Maxim Vuets mephinet Michael Conrad Nick Tonkin Paul Durden Philipp Gortan Phill Legault Shlomi Fish
=over 4
=item *
bj5004
=item *
cm-perl
=item *
Jonathan
=item *
Karen Etheridge
=item *
Konstantin S. Uvarin
=item *
Lucas Kanashiro
=item *
Maros Kollar
=item *
Maxim Vuets
=item *
mephinet
=item *
Michael Conrad
=item *
Nick Tonkin <1nickt@users.noreply.github.com>
=item *
Paul Durden
=item *
Philipp Gortan
=item *
Phill Legault
=item *
Shlomi Fish
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Jonathan Swartz, David Golden, and Doug Bell.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
filescreen.t 100644 000765 000024 12570 13606765203 15106 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use strict;
use warnings;
use Test::More;
use File::Temp qw(tempdir);
use Log::Any::Adapter::Util qw(cmp_deeply read_file);
plan tests => 33;
my $__FILE__ = quotemeta __FILE__;
require Log::Any::Adapter;
{
my $tempdir = tempdir( 'name-XXXX', TMPDIR => 1, CLEANUP => 1 );
my $file = "$tempdir/temp.log";
Log::Any::Adapter->set( 'File', $file, log_level => 'info' );
my $log = Log::Any->get_logger();
ok( ! $log->is_debug, "file won't log debugs" );
ok( $log->is_warn, "file will log warnings" );
$log->debug("to file");
is( scalar( read_file($file) ), '', "debug not logged to file" );
$log->warn("to file");
like( scalar( read_file($file) ), qr/^\[.*\] to file\n$/, "warn logged to file" );
$log->warn("\x{263A} \x{263B}");
like( scalar( read_file($file) ), qr/\x{263A} \x{263B}$/ms, "warn logged UTF-8 to file" );
{
my $file = "$tempdir/temp2.log";
Log::Any::Adapter->set({lexically => \my $lex}, 'File', $file);
ok( $log->is_trace, "file will log trace lexically" );
}
{ # Test that File adapter validates log level properly
my @warnings;
local $SIG{__WARN__} = sub { push @warnings, $_[0] };
Log::Any::Adapter->set( {lexically => \my $lex}, 'File', $file, log_level => 'FOOBAR' );
my $log = Log::Any->get_logger();
ok( $log->is_trace, "log defaults to trace level" );
is scalar @warnings, 1, 'one warning issued';
like $warnings[0],
qr{Invalid log level "FOOBAR"\. Defaulting to "trace" at $__FILE__ line \d+},
'warning is correct';
}
{ # Test that File adapter accepts binmode properly
my @warnings;
local $SIG{__WARN__} = sub { push @warnings, $_[0] };
Log::Any::Adapter->set( {lexically => \my $lex}, 'File', $file, binmode => 'raw' );
my $log = Log::Any->get_logger();
$log->warn("\x{263A} \x{263B}");
like( scalar( read_file($file) ), qr/\x{263A} \x{263B}$/ms, "warn logged raw to file" );
like $warnings[0], qr{Wide character in print}, 'got warning printing UTF-8 as raw';
}
{ # Test that File adapter allows critical log_level
Log::Any::Adapter->set( {lexically => \my $lex}, 'File', $file, log_level => 'emergency' );
my $log = Log::Any->get_logger();
ok $log->is_emergency, 'emergency log level file will log emergency';
ok !$log->is_alert, 'emergency log level file will not log alert';
}
}
{
my $buf = '';
open my $fh, ">", \$buf;
local *STDOUT = $fh;
Log::Any::Adapter->set('Stdout', log_level => 'info');
my $log = Log::Any->get_logger();
ok( ! $log->is_debug, "stdout won't log debugs" );
ok( $log->is_warn, "stdout will log warnings" );
$log->debug("to stdout");
is( $buf, '', "debug not logged to stdout" );
$log->warn("to stdout");
like( $buf, qr/^to stdout\n$/, "warn logged to stdout" );
{
Log::Any::Adapter->set({lexically => \my $lex}, 'Stdout');
ok( $log->is_trace, "stdout will log trace lexically" );
}
{ # Test that Stdout adapter validates log level properly
my @warnings;
local $SIG{__WARN__} = sub { push @warnings, $_[0] };
Log::Any::Adapter->set( {lexically => \my $lex}, 'Stdout', log_level => 'FOOBAR' );
my $log = Log::Any->get_logger();
ok( $log->is_trace, "log defaults to trace level" );
is scalar @warnings, 1, 'one warning issued';
like $warnings[0],
qr{Invalid log level "FOOBAR"\. Defaulting to "trace" at $__FILE__ line \d+},
'warning is correct';
}
{ # Test that Stdout adapter allows critical log_level
Log::Any::Adapter->set( {lexically => \my $lex}, 'Stdout', log_level => 'emergency' );
my $log = Log::Any->get_logger();
ok $log->is_emergency, 'emergency log level file will log emergency';
ok !$log->is_alert, 'emergency log level file will not log alert';
}
}
{
my $buf = '';
open my $fh, ">", \$buf;
local *STDERR = $fh;
Log::Any::Adapter->set('Stderr', log_level => 'info');
my $log = Log::Any->get_logger();
ok( ! $log->is_debug, "stderr won't log debugs" );
ok( $log->is_warn, "stderr will log warnings" );
$log->debug("to stderr");
is( $buf, '', "debug not logged to stderr" );
$log->warn("to stderr");
like( $buf, qr/^to stderr\n$/, "warn logged to stderr" );
{
Log::Any::Adapter->set({lexically => \my $lex}, 'Stderr');
ok( $log->is_trace, "stderr will log trace lexically" );
}
{ # Test that Stderr adapter validates log level properly
my @warnings;
local $SIG{__WARN__} = sub { push @warnings, $_[0] };
Log::Any::Adapter->set( {lexically => \my $lex}, 'Stderr', log_level => 'FOOBAR' );
my $log = Log::Any->get_logger();
ok( $log->is_trace, "log defaults to trace level" );
is scalar @warnings, 1, 'one warning issued';
like $warnings[0],
qr{Invalid log level "FOOBAR"\. Defaulting to "trace" at $__FILE__ line \d+},
'warning is correct';
}
{ # Test that Stderr adapter allows critical log_level
Log::Any::Adapter->set( {lexically => \my $lex}, 'Stderr', log_level => 'emergency' );
my $log = Log::Any->get_logger();
ok $log->is_emergency, 'emergency log level file will log emergency';
ok !$log->is_alert, 'emergency log level file will not log alert';
}
}
null-proxy.t 100644 000765 000024 3314 13606765203 15074 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t
use strict;
use warnings;
use Test::More;
use Log::Any;
plan tests => 14;
my $out;
my $log = Log::Any->get_logger;
isa_ok $log, 'Log::Any::Proxy::Null', 'no adapter proxy is Null';
my $log_complex = Log::Any->get_logger(
category => 'Category:',
prefix => 'Prefix: ',
formatter => sub { "Formatter: @_" },
filter => sub { "Filter: @_" },
);
isa_ok $log_complex, 'Log::Any::Proxy::Null',
'no adapter proxy with formatter is Null';
my $log_explicit = Log::Any->get_logger( proxy_class => 'Test' );
isa_ok $log_explicit, 'Log::Any::Proxy::Test', 'explicit proxy class is correct';
$out = $log->info("test");
is $out, 'test', 'output of test method is returned';
isa_ok $log, 'Log::Any::Proxy::Null',
'no adapter proxy is still Null after logging';
$out = $log_complex->infof('test');
is $out, 'Prefix: Filter: Category: 6 Formatter: Category: 6 test',
'output of test method is returned';
isa_ok $log_complex, 'Log::Any::Proxy::Null',
'no adapter proxy with formatter is still Null after logging';
Log::Any->set_adapter( 'Test' );
isa_ok $log, 'Log::Any::Proxy', 'existing logger reblessed';
isa_ok $log_complex, 'Log::Any::Proxy', 'existing logger reblessed';
isa_ok $log_explicit, 'Log::Any::Proxy::Test', 'explicit proxy class is not reblessed';
$out = $log->info("test");
is Log::Any::Adapter::Test->msgs->[-1]{message}, 'test', 'log is logged';
is $out, 'test', 'output of test method is returned';
$out = $log_complex->infof('test');
is Log::Any::Adapter::Test->msgs->[-1]{message},
'Prefix: Filter: Category: 6 Formatter: Category: 6 test',
'proxy attributes are preserved';
is $out, 'Prefix: Filter: Category: 6 Formatter: Category: 6 test',
'output of test method is returned';
CONTRIBUTING.md 100644 000765 000024 17472 13606765203 14576 0 ustar 00doug staff 000000 000000 Log-Any-1.708 # CONTRIBUTING
This project is free software for the express purpose of collaboration.
We welcome all input, bug reports, feature requests, general comments,
and patches.
## Communication
If you're not sure about anything, please open an issue and ask, or
e-mail the project founder or [talk to us on IRC on
irc.perl.org channel #cpantesters-discuss](https://chat.mibbit.com/?channel=%23cpantesters-discuss&server=irc.perl.org)!
## Standard of Conduct
To ensure a welcoming, safe, collaborative environment, this project
will enforce a standard of conduct:
* The topic of this project is the project itself. Please stay on-topic.
* Stick to the facts
* Avoid demeaning remarks and sarcasm
Unacceptable behavior will receive a single, public warning. Repeated
unacceptable behavior will result in removal from the project.
Remember, all the people who contribute to this project are volunteers.
## About this Project
### Project Goals
This project provides a thin, fast logging API for modules to allow
interoperability between logging systems and integration into existing
systems' logging.
When a project starts depending on a module that uses Log::Any, they
should be able to easily integrate their new dependency's logging to
their existing logging system.
When a project without logging starts depending on a module that uses
Log::Any, they should not notice that any logging exists: Logs should
not be written, and performance should not degrade significantly by the
inclusion of logging.
This distribution must be installable on a clean Perl 5.8 without
additional dependencies.
### Repository Layout
This project follows CPAN conventions with some additions, explained
below.
#### `lib/`
Modules are located in the `lib/` directory. Most of the functionality
of the project should be in a module. If the functionality should be
available to users from a script, the script should call the module.
#### `bin/`
Command-line scripts go in the `bin/` directory. Most of the real
functionality of these should be in a library, but these scripts must
call the library function and document the command-line interface.
#### `t/`
All the tests are located in the `t/` directory. See "Getting Started"
below for how to build the project and run its tests.
#### `xt/`
Any extra tests that are not to be bundled with the CPAN module and run
by consumers is located here. These tests are run at release time and
may test things that are expensive or esoteric.
## What to Contribute
### Comments
The issue tracker is used for both bug reports and to-do list. Anything
on the issue tracker, open or closed, is available for discussion.
### Fixes
For fixes, simply fork and send a pull request. Fixes to anything,
documentation, code, tests, are equally welcome, appreciated, and
addressed!
If you are fixing a bug in the code, please add a regression test to
ensure it stays fixed in the future.
### Features
All contributions are welcome if they fit the scope of this project. If
you're not sure if your feature fits, open an issue and ask. If it doesn't
fit, we will try to find a way to enable you to add your feature in a
related project (if it means changes in this project).
When contributing a feature, please add some basic functionality tests
to ensure the feature is working properly. These tests do not need to be
comprehensive or paranoid, but must at least demonstrate that the
feature is working as documented.
## Getting Started Building and Running Tests
This project uses Dist::Zilla for its releases, but you aren't required
to use it for contributing.
These instructions do require you have
[App::cpanminus (cpanm)](https://metacpan.org/pod/App::cpanminus) installed.
`cpanm` is a CPAN client to install Perl modules and programs. You can
install `cpanm` by doing:
```
curl -L https://cpanmin.us | perl - App::cpanminus
```
Or, if you (not incorrectly) do not trust that, by using the existing
`cpan` client that comes with Perl:
```
cpan App::cpanminus
```
You may need to be root or Administrator to install cpanminus.
### Using `cpanm` to install prereqs
The [`cpanm`](https://metacpan.org/pod/App::cpanminus) command is the
easiest way to install this project's dependencies. In the root of the
project, just run `cpanm --installdeps .` and the dependencies will be
installed.
### Using `carton` to install prereqs in an isolated directory
If you with to isolate the prerequisites of this project so they do not
interfere with other projects, you can use the
[Carton](http://metacpan.org/pod/Carton) tool. Install Carton normally
from CPAN using `cpanm Carton`, then use the `carton` command to install
this module's prereqs in the `local/` directory:
```
carton install
```
Once the prereqs are installed, you can use `carton exec prove -lr t`
to run all the tests with the right prereqs. Putting `carton exec` in
front of the command makes sure Perl uses the right library
directories.
### Using `prove` to run tests
Perl comes with a utility called `prove` which runs tests and gives
a report on failures. To run the test suite with `prove`, do:
```
prove -lr t
```
This will run all the tests in the `t` directory, recursively, while
adding the current `lib/` directory to the library path.
You can run individual test files more quickly by passing them as
arguments to prove:
```
prove -l t/my-test.t
```
### Using Dist::Zilla to install prereqs and run tests
Once you have installed Dist::Zilla via `cpanm Dist::Zilla`, you can get
this distributions's dependencies by doing:
```
dzil listdeps --author --missing | cpanm
```
Once all that is done, testing is as easy as:
```
dzil test
```
## Before you Submit Your Contribution
### Copyright and License
All contributions are copyright their respective owners, so make sure you
agree with the project license (found in the LICENSE file) before
contributing.
The list of Contributors is calculated automatically from the Git commit
log. If you do not wish to be listed as a contributor, or if you wish to
be listed as a contributor with a different e-mail address, tell me so
in the ticket or e-mail me at doug@preaction.me.
### Code Formatting and Style
Please try to maintain the existing code formatting and style.
* 4-space indents
* Opening brace on the same line as the opening keyword
* Exceptions made for lengthy conditionals
* Closing brace on the same column as the opening keyword
### Documentation
Documentation is incredibly important, and contributions will not be
accepted until documentated.
* Methods must be documented inline, above the code of the method
* Method documentation must include name, sample usage, and description
of inputs and outputs
* Attributes must be documented inline, above the attribute declaration
* Attribute documentation must include name, sample value, and
description
* User-executable scripts must be documented with a short synopsis,
a longer description, and all the arguments and options explained
* Tests must be documented with the purpose of the test and any useful
information for understanding the test.
### New Prerequisites
Though this project has a `cpanfile`, a `Makefile.PL`, and maybe even
a `Build.PL`, these files are auto-generated and should not be edited.
To add new prereqs, you must add them to the `dist.ini` file in the
following sections:
* `[Prereqs]` - Runtime requirements
* `[Prereqs / TestRequires]` - Test-only requirements
* `[Prereqs / Recommends]` - Runtime recommendations, for optional
modules
* `[Prereqs / TestRecomments]` - Test-only recommendations, for optional
modules
If the section doesn't already exist, you can add it to the bottom of
the `dist.ini` file.
The `Recommends` and `TestRecommends` will be automatically installed by
Travis CI to test those parts of the code.
OS-specific prerequisites can be added using the
[Dist::Zilla::Plugin::OSPrereqs](http://metacpan.org/pod/Dist::Zilla::Plugin::OSPrereqs)
module.
replace_log.t 100644 000765 000024 430 13606765203 15173 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use strict;
use warnings;
use Test::More;
use Log::Any qw($log), proxy_class => 'Test';
use Log::Any::Adapter ();
plan tests => 1;
Log::Any::Adapter->set('Test');
$log->info("for main");
$log->category_contains_ok(
main => qr/for main/,
'main log appeared in memory'
);
log-any-test.t 100644 000765 000024 1326 13606765203 15267 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use strict;
use warnings;
use Test::More tests => 5;
use Log::Any::Test;
use Log::Any qw($log);
$log->err("this is an error") if $log->is_error;
$log->debugf( "this is a %s with a defined (%s) value and an %s value",
"debug", [ 1, 2 ], undef )
if $log->is_debug;
$log->debugf( "this is a %s value", ["multi\nline"] ) if $log->is_debug;
$log->contains_ok( qr/this is an error/, 'got error' );
$log->contains_ok(
qr/this is a debug with a defined \(\[1,2\]\) value and an value/,
'got debug' );
$log->contains_ok( qr/this is a \["multi\\nline"\] value/, 'got multi-line' );
$log->empty_ok();
TODO: {
local $TODO = 'to do';
$log->contains_ok(qr/should not be there/, "this is TODO on purpose");
}
TestAdapters.pm 100644 000765 000024 2044 13606765203 15516 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t package TestAdapters;
use warnings;
use strict;
our @TEXT_LOG;
our @STRUCTURED_LOG;
package TestAdapters::Normal;
use base qw(Log::Any::Adapter::Base);
foreach my $method ( Log::Any->logging_methods() ) {
no strict 'refs';
*$method = sub { push @TestAdapters::TEXT_LOG, $_[1] };
}
foreach my $method ( Log::Any->detection_methods() ) {
no strict 'refs';
*$method = sub {1};
}
package TestAdapters::Structured;
use base qw(Log::Any::Adapter::Base);
use Storable 'dclone';
sub structured {
my ( $self, $level, $category, @args ) = @_;
my ( $messages, $data );
for (@args) {
if (ref) {
push @$data, dclone($_);
}
else {
push @$messages, $_;
}
}
my $log_hash = { level => $level, category => $category };
$log_hash->{messages} = $messages if $messages;
$log_hash->{data} = $data if $data;
push @TestAdapters::STRUCTURED_LOG, $log_hash;
}
foreach my $method ( Log::Any->detection_methods() ) {
no strict 'refs';
*$method = sub {1};
}
1;
inner-adapter.t 100644 000765 000024 1212 13606765203 15467 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use strict;
use warnings;
use Test::More;
plan tests => 2;
our $BUF;
package MyApp::Log::Adapter;
use base qw(Log::Any::Adapter::Base);
foreach my $method ( Log::Any->logging_methods() ) {
no strict 'refs';
*$method = sub { $main::BUF .= "$_[1]\n"};
}
foreach my $method ( Log::Any->detection_methods() ) {
no strict 'refs';
*$method = sub { 1 };
}
package main;
use Log::Any::Adapter;
eval { Log::Any::Adapter->set('+MyApp::Log::Adapter') };
is( $@, "", "setting inner package as adapter is OK");
my $log = Log::Any->get_logger;
$log->critical("DIE DIE DIE");
is( $BUF, "DIE DIE DIE\n", "logged a message via inner adapter" );
valid-methods.t 100644 000765 000024 1625 13606765203 15506 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use strict;
use warnings;
use Test::More tests => 87;
use Log::Any qw($log);
my @logs;
push( @logs, $log );
push( @logs, Log::Any->get_logger() );
push( @logs, Log::Any->get_logger( category => 'Foo' ) );
my $logging_method_count = scalar( Log::Any->logging_methods() );
my $detection_method_count = scalar( Log::Any->logging_methods() );
foreach my $log (@logs) {
foreach my $method ( Log::Any->detection_methods() ) {
ok( !$log->$method, "!$method" );
}
ok(
scalar( map { $log->$_ } Log::Any->detection_methods() ) ==
Log::Any->detection_methods() );
foreach my $method ( Log::Any->logging_methods() ) {
ok( $log->$method("") || 1, "$method runs" );
my $methodf = $method . "f";
ok( $log->$methodf("") || 1, "$methodf runs" );
}
eval { $log->bad_method() };
ok( $@ =~ qr{Can\'t locate object method "bad_method"}, "bad method" );
}
.gitignore 100644 000765 000024 15 13606765203 15525 0 ustar 00doug staff 000000 000000 Log-Any-1.708/lib/Log log-any.html
adapter-import.t 100644 000765 000024 410 13606765203 15645 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use strict;
use warnings;
use Test::More tests => 1;
use Log::Any::Adapter qw(Stdout);
{
open my $fh, ">", \my $buf;
local *STDOUT = $fh;
my $log = Log::Any->get_logger();
$log->debug("to stdout");
like( $buf, qr/^to stdout\n$/, "stdout" );
}
errors-adapter.t 100644 000765 000024 634 13606765203 15657 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use strict;
use warnings;
use Test::More tests => 3;
use Log::Any::Adapter;
eval { Log::Any::Adapter->set('Blah') };
like( $@, qr{Can't locate Log/Any/Adapter/Blah}, "adapter = Blah" );
eval { Log::Any::Adapter->set('+My::Adapter::Blah') };
like( $@, qr{Can't locate My/Adapter/Blah}, "adapter = +My::Adapter::Blah" );
eval { Log::Any::Adapter->set('') };
like( $@, qr{expected adapter name}, "adapter = ''" );
Any 000755 000765 000024 0 13606765203 14170 5 ustar 00doug staff 000000 000000 Log-Any-1.708/lib/Log Test.pm 100644 000765 000024 7232 13606765203 15611 0 ustar 00doug staff 000000 000000 Log-Any-1.708/lib/Log/Any use 5.008001;
use strict;
use warnings;
package Log::Any::Test;
# ABSTRACT: Test what you're logging with Log::Any
our $VERSION = '1.708';
no warnings 'once';
$Log::Any::OverrideDefaultAdapterClass = 'Log::Any::Adapter::Test';
$Log::Any::OverrideDefaultProxyClass = 'Log::Any::Proxy::Test';
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Log::Any::Test - Test what you're logging with Log::Any
=head1 VERSION
version 1.708
=head1 SYNOPSIS
use Test::More;
use Log::Any::Test; # should appear before 'use Log::Any'!
use Log::Any qw($log);
# ...
# call something that logs using Log::Any
# ...
# now test to make sure you logged the right things
$log->contains_ok(qr/good log message/, "good message was logged");
$log->does_not_contain_ok(qr/unexpected log message/, "unexpected message was not logged");
$log->empty_ok("no more logs");
# or
my $msgs = $log->msgs;
cmp_deeply($msgs, [{message => 'msg1', level => 'debug'}, ...]);
=head1 DESCRIPTION
C is a simple module that allows you to test what has been
logged with Log::Any. Most of its API and implementation have been taken from
L.
Using C signals C to send all subsequent log
messages to a single global in-memory buffer and to make the log proxy
provide a number of testing functions. To use it, load C
before anything that loads C. To actually use the test methods,
you need to load C and get a log object from it, as shown in the
L.
=head1 METHODS
The test_name is optional in the *_ok methods; a reasonable default will be
provided.
=over
=item msgs ()
Returns the current contents of the global log buffer as an array reference,
where each element is a hash containing a I, I, and I
key. e.g.
{
category => 'Foo',
level => 'error',
message => 'this is an error'
},
{
category => 'Bar::Baz',
level => 'debug',
message => 'this is a debug'
}
=item contains_ok ($regex[, $test_name])
Tests that a message in the log buffer matches I<$regex>. On success, the
message is I from the log buffer (but any other matches are left
untouched).
=item does_not_contain_ok ($regex[, $test_name])
Tests that no message in the log buffer matches I<$regex>.
=item category_contains_ok ($category, $regex[, $test_name])
Tests that a message in the log buffer from a specific category matches
I<$regex>. On success, the message is I from the log buffer (but any
other matches are left untouched).
=item category_does_not_contain_ok ($category, $regex[, $test_name])
Tests that no message from a specific category in the log buffer matches
I<$regex>.
=item empty_ok ([$test_name])
Tests that there is no log buffer left. On failure, the log buffer is cleared
to limit further cascading failures.
=item contains_only_ok ($regex[, $test_name])
Tests that there is a single message in the log buffer and it matches
I<$regex>. On success, the message is removed.
=item clear ()
Clears the log buffer.
=back
=head1 SEE ALSO
L, L
=head1 AUTHORS
=over 4
=item *
Jonathan Swartz
=item *
David Golden
=item *
Doug Bell
=item *
Daniel Pittman
=item *
Stephen Thirlwall
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Jonathan Swartz, David Golden, and Doug Bell.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
default-adapter.t 100644 000765 000024 1201 13606765203 15776 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use strict;
use warnings;
use Test::More tests => 4;
use Log::Any '$log', proxy_class => 'Test', default_adapter => 'Test';
$log->err("this is an error") if $log->is_error;
$log->debugf( "this is a %s with a defined (%s) value and an %s value",
"debug", [ 1, 2 ], undef )
if $log->is_debug;
$log->debugf( "this is a %s value", ["multi\nline"] ) if $log->is_debug;
$log->contains_ok( qr/this is an error/, 'got error' );
$log->contains_ok(
qr/this is a debug with a defined \(\[1,2\]\) value and an value/,
'got debug' );
$log->contains_ok( qr/this is a \["multi\\nline"\] value/, 'got multi-line' );
$log->empty_ok();
default-vs-test.t 100644 000765 000024 1176 13606765203 15776 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t use strict;
use warnings;
use Test::More tests => 4;
use Log::Any::Test;
use Log::Any '$log', default_adapter => 'Null';
$log->err("this is an error") if $log->is_error;
$log->debugf( "this is a %s with a defined (%s) value and an %s value",
"debug", [ 1, 2 ], undef )
if $log->is_debug;
$log->debugf( "this is a %s value", ["multi\nline"] ) if $log->is_debug;
$log->contains_ok( qr/this is an error/, 'got error' );
$log->contains_ok(
qr/this is a debug with a defined \(\[1,2\]\) value and an value/,
'got debug' );
$log->contains_ok( qr/this is a \["multi\\nline"\] value/, 'got multi-line' );
$log->empty_ok();
Proxy.pm 100644 000765 000024 25244 13606765203 16036 0 ustar 00doug staff 000000 000000 Log-Any-1.708/lib/Log/Any use 5.008001;
use strict;
use warnings;
package Log::Any::Proxy;
# ABSTRACT: Log::Any generator proxy object
our $VERSION = '1.708';
use Log::Any::Adapter::Util ();
use overload;
sub _stringify_params {
my @params = @_;
return map {
!defined($_)
? ''
: ref($_) ? (
overload::OverloadedStringify($_)
? "$_"
: Log::Any::Adapter::Util::dump_one_line($_)
)
: $_
} @params;
}
sub _default_formatter {
my ( $cat, $lvl, $format, @params ) = @_;
return $format->() if ref($format) eq 'CODE';
my @new_params = _stringify_params(@params);
# Perl 5.22 adds a 'redundant' warning if the number parameters exceeds
# the number of sprintf placeholders. If a user does this, the warning
# is issued from here, which isn't very helpful. Doing something
# clever would be expensive, so instead we just disable warnings for
# the final line of this subroutine.
no warnings;
return sprintf( $format, @new_params );
}
sub new {
my $class = shift;
my $self = { formatter => \&_default_formatter, @_ };
unless ( $self->{adapter} ) {
require Carp;
Carp::croak("$class requires an 'adapter' parameter");
}
unless ( $self->{category} ) {
require Carp;
Carp::croak("$class requires a 'category' parameter");
}
unless ( $self->{context} ) {
require Carp;
Carp::croak("$class requires a 'context' parameter");
}
bless $self, $class;
$self->init(@_);
return $self;
}
sub clone {
my $self = shift;
return (ref $self)->new( %{ $self }, @_ );
}
sub init { }
for my $attr (qw/adapter filter formatter prefix context/) {
no strict 'refs';
*{$attr} = sub { return $_[0]->{$attr} };
}
my %aliases = Log::Any::Adapter::Util::log_level_aliases();
# Set up methods/aliases and detection methods/aliases
foreach my $name ( Log::Any::Adapter::Util::logging_methods(), keys(%aliases) )
{
my $realname = $aliases{$name} || $name;
my $namef = $name . "f";
my $is_name = "is_$name";
my $is_realname = "is_$realname";
my $numeric = Log::Any::Adapter::Util::numeric_level($realname);
no strict 'refs';
*{$is_name} = sub {
my ($self) = @_;
return $self->{adapter}->$is_realname;
};
*{$name} = sub {
my ( $self, @parts ) = @_;
return if !$self->{adapter}->$is_realname && !defined wantarray;
my $structured_logging =
$self->{adapter}->can('structured') && !$self->{filter};
my $data_from_parts = pop @parts
if ( @parts && ( ( ref $parts[-1] || '' ) eq ref {} ) );
my $data_from_context = $self->{context};
my $data =
{ map {%$_} grep {$_ && %$_} $data_from_context, $data_from_parts };
if ($structured_logging) {
unshift @parts, $self->{prefix} if $self->{prefix};
$self->{adapter}
->structured( $realname, $self->{category}, @parts, grep {%$_} $data );
return unless defined wantarray;
}
@parts = grep { defined($_) && length($_) } @parts;
push @parts, _stringify_params($data) if %$data;
my $message = join( " ", @parts );
if ( length $message && !$structured_logging ) {
$message =
$self->{filter}->( $self->{category}, $numeric, $message )
if defined $self->{filter};
if ( defined $message and length $message ) {
$message = "$self->{prefix}$message"
if defined $self->{prefix} && length $self->{prefix};
$self->{adapter}->$realname($message);
}
}
return $message if defined wantarray;
};
*{$namef} = sub {
my ( $self, @args ) = @_;
return if !$self->{adapter}->$is_realname && !defined wantarray;
my $message =
$self->{formatter}->( $self->{category}, $numeric, @args );
return unless defined $message and length $message;
return $self->$name($message);
};
}
1;
# vim: ts=4 sts=4 sw=4 et tw=75:
__END__
=pod
=encoding UTF-8
=head1 NAME
Log::Any::Proxy - Log::Any generator proxy object
=head1 VERSION
version 1.708
=head1 SYNOPSIS
# prefix log messages
use Log::Any '$log', prefix => 'MyApp: ';
# transform log messages
use Log::Any '$log', filter => \&myfilter;
# format with String::Flogger instead of the default
use String::Flogger;
use Log::Any '$log', formatter => sub {
my ($cat, $lvl, @args) = @_;
String::Flogger::flog( @args );
};
# create a clone with different attributes
my $bar_log = $log->clone( prefix => 'bar: ' );
=head1 DESCRIPTION
Log::Any::Proxy objects are what modules use to produce log messages. They
construct messages and pass them along to a configured adapter.
=head1 ATTRIBUTES
=head2 adapter
A L object to receive any messages logged. This is
generated by L and can not be overridden.
=head2 category
The category name of the proxy. If not provided, L will set it
equal to the calling when the proxy is constructed.
=head2 filter
A code reference to transform messages before passing them to a
Log::Any::Adapter. It gets three arguments: a category, a numeric level
and a string. It should return a string to be logged.
sub {
my ($cat, $lvl, $msg) = @_;
return "[$lvl] $msg";
}
If the return value is undef or the empty string, no message will be
logged. Otherwise, the return value is passed to the logging adapter.
Numeric levels range from 0 (emergency) to 8 (trace). Constant functions
for these levels are available from L.
Configuring a filter disables structured logging, even if the
configured adapter supports it.
=head2 formatter
A code reference to format messages given to the C<*f> methods (C,
C, C, etc..)
It get three or more arguments: a category, a numeric level and the list
of arguments passsed to the C<*f> method. It should return a string to
be logged.
sub {
my ($cat, $lvl, $format, @args) = @_;
return sprintf($format, @args);
}
The default formatter does the following:
=head2 prefix
If defined, this string will be prepended to all messages. It will not
include a trailing space, so add that yourself if you want. This is less
flexible/powerful than L, but avoids an extra function call.
=head1 USAGE
=head2 Simple logging
Your library can do simple logging using logging methods corresponding to
the log levels (or aliases):
=for :list * trace
* debug
* info (inform)
* notice
* warning (warn)
* error (err)
* critical (crit, fatal)
* alert
* emergency
Pass a string to be logged. Do not include a newline.
$log->info("Got some new for you.");
The log string will be transformed via the C attribute (if any) and
the C (if any) will be prepended. Returns the transformed log string.
B: While you are encouraged to pass a single string to be logged, if
multiple arguments are passed, they are concatenated with a space character
into a single string before processing. This ensures consistency across
adapters, some of which may support multiple arguments to their logging
functions (and which concatenate in different ways) and some of which do
not.
=head2 Advanced logging
Your library can do advanced logging using logging methods corresponding to
the log levels (or aliases), but with an "f" appended:
=for :list * tracef
* debugf
* infof (informf)
* noticef
* warningf (warnf)
* errorf (errf)
* criticalf (critf, fatalf)
* alertf
* emergencyf
When these methods are called, the adapter is first checked to see if it is
logging at that level. If not, the method returns without logging.
Next, arguments are transformed to a message string via the C
attribute.
The default formatter first checks if the first log argument is a code
reference. If so, it will executed and the result used as the formatted
message. Otherwise, the formatter acts like C with some helpful
formatting.
Finally, the message string is logged via the simple logging functions,
which can transform or prefix as described above. The transformed log
string is then returned.
=for :list * if the first argument is a code reference, it is executed and the result
returned
* otherwise, it acts like C, except that undef arguments are
changed to C<< >> and any references or objects are dumped via
L (but without newlines).
Numeric levels range from 0 (emergency) to 8 (trace). Constant functions
for these levels are available from L.
=head2 Logging Structured Data
If you have data in addition to the text you want to log, you can
specify a hashref after your string. If the configured adapter
supports structured data, it will receive the hashref as-is, otherwise
it will be converted to a string using L and will be
appended to your text.
=head1 TIPS
=head2 UTF-8 in Data Structures
If you have high-bit characters in a data structure being passed to a log
method, Log::Any will output that data structure with the high-bit
characters encoded as C<\x{###}>, Perl's escape sequence for high-bit
characters. This is because the L module escapes those
characters.
use utf8;
use Log::Any qw( $log );
my @data = ( "Привет мир" ); # Hello, World!
$log->infof("Got: %s", \@data);
# Got: ["\x{41f}\x{440}\x{438}\x{432}\x{435}\x{442} \x{43c}\x{438}\x{440}"]
If you want to instead display the actual characters in your log file or
terminal, you can use the L module. To wire this
up into Log::Any, you must pass a custom C sub:
use utf8;
use Data::Dumper::AutoEncode;
sub log_formatter {
my ( $category, $level, $format, @params ) = @_;
# Run references through Data::Dumper::AutoEncode
@params = map { ref $_ ? eDumper( $_ ) : $_ } @params;
return sprintf $format, @params;
}
use Log::Any '$log', formatter => \&log_formatter;
This formatter changes the output to:
Got: $VAR1 = [
'Привет мир'
];
Thanks to L<@denis-it|https://github.com/denis-it> for this tip!
=head1 AUTHORS
=over 4
=item *
Jonathan Swartz
=item *
David Golden
=item *
Doug Bell
=item *
Daniel Pittman
=item *
Stephen Thirlwall
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Jonathan Swartz, David Golden, and Doug Bell.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
author-pod-syntax.t 100644 000765 000024 454 13606765203 16333 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t #!perl
BEGIN {
unless ($ENV{AUTHOR_TESTING}) {
print qq{1..0 # SKIP these tests are for testing by the author\n};
exit
}
}
# This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests.
use strict; use warnings;
use Test::More;
use Test::Pod 1.41;
all_pod_files_ok();
00-report-prereqs.t 100644 000765 000024 13426 13606765203 16177 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t #!perl
use strict;
use warnings;
# This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.027
use Test::More tests => 1;
use ExtUtils::MakeMaker;
use File::Spec;
# from $version::LAX
my $lax_version_re =
qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )?
|
(?:\.[0-9]+) (?:_[0-9]+)?
) | (?:
v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )?
|
(?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)?
)
)/x;
# hide optional CPAN::Meta modules from prereq scanner
# and check if they are available
my $cpan_meta = "CPAN::Meta";
my $cpan_meta_pre = "CPAN::Meta::Prereqs";
my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic
# Verify requirements?
my $DO_VERIFY_PREREQS = 1;
sub _max {
my $max = shift;
$max = ( $_ > $max ) ? $_ : $max for @_;
return $max;
}
sub _merge_prereqs {
my ($collector, $prereqs) = @_;
# CPAN::Meta::Prereqs object
if (ref $collector eq $cpan_meta_pre) {
return $collector->with_merged_prereqs(
CPAN::Meta::Prereqs->new( $prereqs )
);
}
# Raw hashrefs
for my $phase ( keys %$prereqs ) {
for my $type ( keys %{ $prereqs->{$phase} } ) {
for my $module ( keys %{ $prereqs->{$phase}{$type} } ) {
$collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module};
}
}
}
return $collector;
}
my @include = qw(
);
my @exclude = qw(
);
# Add static prereqs to the included modules list
my $static_prereqs = do './t/00-report-prereqs.dd';
# Merge all prereqs (either with ::Prereqs or a hashref)
my $full_prereqs = _merge_prereqs(
( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ),
$static_prereqs
);
# Add dynamic prereqs to the included modules list (if we can)
my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml';
my $cpan_meta_error;
if ( $source && $HAS_CPAN_META
&& (my $meta = eval { CPAN::Meta->load_file($source) } )
) {
$full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs);
}
else {
$cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source)
$source = 'static metadata';
}
my @full_reports;
my @dep_errors;
my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs;
# Add static includes into a fake section
for my $mod (@include) {
$req_hash->{other}{modules}{$mod} = 0;
}
for my $phase ( qw(configure build test runtime develop other) ) {
next unless $req_hash->{$phase};
next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING});
for my $type ( qw(requires recommends suggests conflicts modules) ) {
next unless $req_hash->{$phase}{$type};
my $title = ucfirst($phase).' '.ucfirst($type);
my @reports = [qw/Module Want Have/];
for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) {
next if $mod eq 'perl';
next if grep { $_ eq $mod } @exclude;
my $file = $mod;
$file =~ s{::}{/}g;
$file .= ".pm";
my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC;
my $want = $req_hash->{$phase}{$type}{$mod};
$want = "undef" unless defined $want;
$want = "any" if !$want && $want == 0;
my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required";
if ($prefix) {
my $have = MM->parse_version( File::Spec->catfile($prefix, $file) );
$have = "undef" unless defined $have;
push @reports, [$mod, $want, $have];
if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) {
if ( $have !~ /\A$lax_version_re\z/ ) {
push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)";
}
elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) {
push @dep_errors, "$mod version '$have' is not in required range '$want'";
}
}
}
else {
push @reports, [$mod, $want, "missing"];
if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) {
push @dep_errors, "$mod is not installed ($req_string)";
}
}
}
if ( @reports ) {
push @full_reports, "=== $title ===\n\n";
my $ml = _max( map { length $_->[0] } @reports );
my $wl = _max( map { length $_->[1] } @reports );
my $hl = _max( map { length $_->[2] } @reports );
if ($type eq 'modules') {
splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl];
push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports;
}
else {
splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl];
push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports;
}
push @full_reports, "\n";
}
}
}
if ( @full_reports ) {
diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports;
}
if ( $cpan_meta_error || @dep_errors ) {
diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n";
}
if ( $cpan_meta_error ) {
my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml';
diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n";
}
if ( @dep_errors ) {
diag join("\n",
"\nThe following REQUIRED prerequisites were not satisfied:\n",
@dep_errors,
"\n"
);
}
pass;
# vim: ts=4 sts=4 sw=4 et:
00-report-prereqs.dd 100644 000765 000024 3603 13606765203 16277 0 ustar 00doug staff 000000 000000 Log-Any-1.708/t do { my $x = {
'configure' => {
'requires' => {
'ExtUtils::MakeMaker' => '0'
}
},
'develop' => {
'requires' => {
'Test::Pod' => '1.41'
}
},
'runtime' => {
'requires' => {
'B' => '0',
'Carp' => '0',
'Data::Dumper' => '0',
'Exporter' => '0',
'Fcntl' => '0',
'File::Basename' => '0',
'FindBin' => '0',
'IO::File' => '0',
'List::Util' => '0',
'Storable' => '0',
'Sys::Syslog' => '0',
'Test::Builder' => '0',
'constant' => '0',
'strict' => '0',
'warnings' => '0'
}
},
'test' => {
'recommends' => {
'CPAN::Meta' => '2.120900'
},
'requires' => {
'ExtUtils::MakeMaker' => '0',
'File::Spec' => '0',
'IO::Handle' => '0',
'IPC::Open3' => '0',
'Test::More' => '0'
}
}
};
$x;
} Adapter.pm 100644 000765 000024 15672 13606765203 16301 0 ustar 00doug staff 000000 000000 Log-Any-1.708/lib/Log/Any use 5.008001;
use strict;
use warnings;
package Log::Any::Adapter;
# ABSTRACT: Tell Log::Any where to send its logs
our $VERSION = '1.708';
use Log::Any;
our @CARP_NOT = ( 'Log::Any::Manager' );
sub import {
my $pkg = shift;
Log::Any->_manager->set(@_) if (@_);
}
sub set {
my $pkg = shift;
Log::Any->_manager->set(@_)
}
sub remove {
my $pkg = shift;
Log::Any->_manager->remove(@_)
}
sub get {
my $pkg = shift;
Log::Any->_manager->get_adapter(@_);
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Log::Any::Adapter - Tell Log::Any where to send its logs
=head1 VERSION
version 1.708
=head1 SYNOPSIS
# Log to a file, or stdout, or stderr for all categories
#
use Log::Any::Adapter ('File', '/path/to/file.log');
use Log::Any::Adapter ('Stdout');
use Log::Any::Adapter ('Stderr');
# Use Log::Log4perl for all categories
#
Log::Log4perl::init('/etc/log4perl.conf');
Log::Any::Adapter->set('Log4perl');
# Use Log::Dispatch for Foo::Baz
#
use Log::Dispatch;
my $log = Log::Dispatch->new(outputs => [[ ... ]]);
Log::Any::Adapter->set( { category => 'Foo::Baz' },
'Dispatch', dispatcher => $log );
# Use Log::Dispatch::Config for Foo::Baz and its subcategories
#
use Log::Dispatch::Config;
Log::Dispatch::Config->configure('/path/to/log.conf');
Log::Any::Adapter->set(
{ category => qr/^Foo::Baz/ },
'Dispatch', dispatcher => Log::Dispatch::Config->instance() );
# Use your own adapter for all categories
#
Log::Any::Adapter->set('+My::Log::Any::Adapter', ...);
=head1 DESCRIPTION
Log::Any::Adapter connects log producers and log consumers. Its methods
instantiate a logging adapter (a subclass of L)
and route log messages from one or more categories to it.
=head1 ADAPTERS
In order to use a logging mechanism with C, there needs to be an
adapter class for it. Typically this is named Log::Any::Adapter::I.
=head2 Adapters in this distribution
Three basic adapters come with this distribution -- L,
L and L:
use Log::Any::Adapter ('File', '/path/to/file.log');
use Log::Any::Adapter ('Stdout');
use Log::Any::Adapter ('Stderr');
# or
use Log::Any::Adapter;
Log::Any::Adapter->set('File', '/path/to/file.log');
Log::Any::Adapter->set('Stdout');
Log::Any::Adapter->set('Stderr');
All of them simply output the message and newline to the specified destination;
a datestamp prefix is added in the C case. For anything more complex
you'll want to use a more robust adapter from CPAN.
=head2 Adapters on CPAN
A sampling of adapters available on CPAN as of this writing:
=over
=item *
L
=item *
L
=item *
L
=item *
L
=back
You may find other adapters on CPAN by searching for "Log::Any::Adapter", or
create your own adapter. See
L for more
information on the latter.
=head1 SETTING AND REMOVING ADAPTERS
=over
=item Log::Any::Adapter->set ([options, ]adapter_name, adapter_params...)
This method sets the adapter to use for all log categories, or for a particular
set of categories.
I is the name of an adapter. It is automatically prepended with
"Log::Any::Adapter::". If instead you want to pass the full name of an adapter,
prefix it with a "+". e.g.
# Use My::Adapter class
Log::Any::Adapter->set('+My::Adapter', arg => $value);
I are passed along to the adapter constructor. See the
documentation for the individual adapter classes for more information.
An optional hash of I may be passed as the first argument. Options
are:
=over
=item category
A string containing a category name, or a regex (created with C) matching
multiple categories. If not specified, all categories will be routed to the
adapter.
=item lexically
A reference to a lexical variable. When the variable goes out of scope, the
adapter setting will be removed. e.g.
{
Log::Any::Adapter->set({lexically => \my $lex}, ...);
# in effect here
...
}
# no longer in effect here
=back
C returns an entry object, which can be passed to C. If you
call C repeatedly without calling C you will leak memory. For
most programs that set an adapter once until the end of the program, this
shouldn't matter.
=item use Log::Any::Adapter (...)
If you pass arguments to C