Log-Any-1.038/000755 000765 000024 00000000000 12656724173 013242 5ustar00davidstaff000000 000000 Log-Any-1.038/Changes000644 000765 000024 00000014532 12656724173 014542 0ustar00davidstaff000000 000000 Revision history for Log-Any ** denotes an incompatible change 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 Log-Any-1.038/CONTRIBUTING.mkdn000644 000765 000024 00000005751 12656724173 016034 0ustar00davidstaff000000 000000 ## HOW TO CONTRIBUTE Thank you for considering contributing to this distribution. This file contains instructions that will help you work with the source code. The distribution is managed with Dist::Zilla. This means than many of the usual files you might expect are not in the repository, but are generated at release time, as is much of the documentation. Some generated files are kept in the repository as a convenience (e.g. Makefile.PL or cpanfile). Generally, **you do not need Dist::Zilla to contribute patches**. You do need Dist::Zilla to create a tarball. See below for guidance. ### Getting dependencies If you have App::cpanminus 1.6 or later installed, you can use `cpanm` to satisfy dependencies like this: $ cpanm --installdeps . Otherwise, look for either a `Makefile.PL` or `cpanfile` file for a list of dependencies to satisfy. ### Running tests You can run tests directly using the `prove` tool: $ prove -l $ prove -lv t/some_test_file.t For most of my distributions, `prove` is entirely sufficient for you to test any patches you have. I use `prove` for 99% of my testing during development. ### Code style and tidying Please try to match any existing coding style. If there is a `.perltidyrc` file, please install Perl::Tidy and use perltidy before submitting patches. If there is a `tidyall.ini` file, you can also install Code::TidyAll and run `tidyall` on a file or `tidyall -a` to tidy all files. ### Patching documentation Much of the documentation Pod is generated at release time. Some is generated boilerplate; other documentation is built from pseudo-POD directives in the source like C<=method> or C<=func>. If you would like to submit a documentation edit, please limit yourself to the documentation you see. If you see typos or documentation issues in the generated docs, please email or open a bug ticket instead of patching. ### Installing and using Dist::Zilla Dist::Zilla is a very powerful authoring tool, optimized for maintaining a large number of distributions with a high degree of automation, but it has a large dependency chain, a bit of a learning curve and requires a number of author-specific plugins. To install it from CPAN, I recommend one of the following approaches for the quickest installation: # using CPAN.pm, but bypassing non-functional pod tests $ cpan TAP::Harness::Restricted $ PERL_MM_USE_DEFAULT=1 HARNESS_CLASS=TAP::Harness::Restricted cpan Dist::Zilla # using cpanm, bypassing *all* tests $ cpanm -n Dist::Zilla In either case, it's probably going to take about 10 minutes. Go for a walk, go get a cup of your favorite beverage, take a bathroom break, or whatever. When you get back, Dist::Zilla should be ready for you. Then you need to install any plugins specific to this distribution: $ cpan `dzil authordeps` $ dzil authordeps | cpanm Once installed, here are some dzil commands you might try: $ dzil build $ dzil test $ dzil xtest You can learn more about Dist::Zilla at http://dzil.org/ Log-Any-1.038/cpanfile000644 000765 000024 00000002551 12656724173 014751 0ustar00davidstaff000000 000000 requires "B" => "0"; requires "Carp" => "0"; requires "Data::Dumper" => "0"; requires "Exporter" => "0"; requires "Fcntl" => "0"; requires "IO::File" => "0"; requires "Test::Builder" => "0"; requires "constant" => "0"; requires "perl" => "5.008001"; requires "strict" => "0"; requires "warnings" => "0"; on 'test' => sub { requires "ExtUtils::MakeMaker" => "0"; requires "File::Spec" => "0"; requires "File::Temp" => "0"; requires "Test::More" => "0"; requires "base" => "0"; requires "perl" => "5.008001"; }; on 'test' => sub { recommends "CPAN::Meta" => "2.120900"; }; on 'configure' => sub { requires "ExtUtils::MakeMaker" => "6.17"; requires "perl" => "5.008001"; }; on 'develop' => sub { requires "Dist::Zilla" => "5"; requires "Dist::Zilla::Plugin::OnlyCorePrereqs" => "0.003"; requires "Dist::Zilla::Plugin::SurgicalPodWeaver" => "0.0021"; requires "Dist::Zilla::PluginBundle::DAGOLDEN" => "0.072"; requires "English" => "0"; requires "File::Spec" => "0"; requires "File::Temp" => "0"; requires "IO::Handle" => "0"; requires "IPC::Open3" => "0"; requires "Pod::Wordlist" => "0"; requires "Software::License::Perl_5" => "0"; requires "Test::CPAN::Meta" => "0"; requires "Test::More" => "0"; requires "Test::Pod" => "1.41"; requires "Test::Spelling" => "0.12"; requires "Test::Version" => "1"; requires "blib" => "1.01"; }; Log-Any-1.038/dist.ini000644 000765 000024 00000001677 12656724173 014721 0ustar00davidstaff000000 000000 name = Log-Any abstract = Bringing loggers and listeners together author = Jonathan Swartz author = David Golden license = Perl_5 copyright_year = 2014 copyright_holder = Jonathan Swartz and David Golden [@DAGOLDEN] :version = 0.072 MetaNoIndex.package[0] = Log::Any::Manager::_Guard -remove = PodWeaver authority = cpan:JSWARTZ no_coverage = 1 stopwords = alertf stopwords = crit stopwords = critf stopwords = criticalf stopwords = debugf stopwords = emergencyf stopwords = errf stopwords = errorf stopwords = fatalf stopwords = infof stopwords = informf stopwords = msgs stopwords = noticef stopwords = passsed stopwords = tracef stopwords = tranformed stopwords = warnf stopwords = warningf [SurgicalPodWeaver] :version = 0.0021 config_plugin = @DAGOLDEN replacer = replace_with_comment post_code_replacer = replace_with_nothing [OnlyCorePrereqs] :version = 0.003 starting_version = 5.008001 skip = version Log-Any-1.038/lib/000755 000765 000024 00000000000 12656724173 014010 5ustar00davidstaff000000 000000 Log-Any-1.038/LICENSE000644 000765 000024 00000043751 12656724173 014261 0ustar00davidstaff000000 000000 This software is copyright (c) 2014 by Jonathan Swartz and David Golden. 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) 2014 by Jonathan Swartz and David Golden. 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) 2014 by Jonathan Swartz and David Golden. 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 Log-Any-1.038/Makefile.PL000644 000765 000024 00000003110 12656724173 015207 0ustar00davidstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.043. use strict; use warnings; use 5.008001; use ExtUtils::MakeMaker 6.17; my %WriteMakefileArgs = ( "ABSTRACT" => "Bringing loggers and listeners together", "AUTHOR" => "Jonathan Swartz , David Golden ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.17" }, "DISTNAME" => "Log-Any", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.008001", "NAME" => "Log::Any", "PREREQ_PM" => { "B" => 0, "Carp" => 0, "Data::Dumper" => 0, "Exporter" => 0, "Fcntl" => 0, "IO::File" => 0, "Test::Builder" => 0, "constant" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "File::Temp" => 0, "Test::More" => 0, "base" => 0 }, "VERSION" => "1.038", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "B" => 0, "Carp" => 0, "Data::Dumper" => 0, "Exporter" => 0, "ExtUtils::MakeMaker" => 0, "Fcntl" => 0, "File::Spec" => 0, "File::Temp" => 0, "IO::File" => 0, "Test::Builder" => 0, "Test::More" => 0, "base" => 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); Log-Any-1.038/MANIFEST000644 000765 000024 00000001766 12656724173 014405 0ustar00davidstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.043. CONTRIBUTING.mkdn Changes LICENSE MANIFEST META.json META.yml Makefile.PL README cpanfile dist.ini lib/Log/Any.pm lib/Log/Any/Adapter.pm lib/Log/Any/Adapter/Base.pm lib/Log/Any/Adapter/Development.pod lib/Log/Any/Adapter/File.pm lib/Log/Any/Adapter/Null.pm lib/Log/Any/Adapter/Stderr.pm lib/Log/Any/Adapter/Stdout.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/Test.pm lib/Log/Any/Test.pm perlcritic.rc t/00-report-prereqs.dd t/00-report-prereqs.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/proxy.t t/replace_log.t t/sprintf.t t/valid-methods.t tidyall.ini xt/author/00-compile.t xt/author/critic.t xt/author/pod-spell.t xt/author/pod-syntax.t xt/author/test-version.t xt/release/backcompat.t xt/release/distmeta.t xt/release/minimum-version.t xt/release/portability.t Log-Any-1.038/META.json000644 000765 000024 00000010553 12656724173 014667 0ustar00davidstaff000000 000000 { "abstract" : "Bringing loggers and listeners together", "author" : [ "Jonathan Swartz ", "David Golden " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.043, CPAN::Meta::Converter version 2.150001", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Log-Any", "no_index" : { "directory" : [ "corpus", "examples", "t", "xt" ], "package" : [ "DB", "Log::Any::Manager::_Guard" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.17", "perl" : "5.008001" } }, "develop" : { "requires" : { "Dist::Zilla" : "5", "Dist::Zilla::Plugin::OnlyCorePrereqs" : "0.003", "Dist::Zilla::Plugin::SurgicalPodWeaver" : "0.0021", "Dist::Zilla::PluginBundle::DAGOLDEN" : "0.072", "English" : "0", "File::Spec" : "0", "File::Temp" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Pod::Wordlist" : "0", "Software::License::Perl_5" : "0", "Test::CPAN::Meta" : "0", "Test::More" : "0", "Test::Pod" : "1.41", "Test::Spelling" : "0.12", "Test::Version" : "1", "blib" : "1.01" } }, "runtime" : { "requires" : { "B" : "0", "Carp" : "0", "Data::Dumper" : "0", "Exporter" : "0", "Fcntl" : "0", "IO::File" : "0", "Test::Builder" : "0", "constant" : "0", "perl" : "5.008001", "strict" : "0", "warnings" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "File::Temp" : "0", "Test::More" : "0", "base" : "0", "perl" : "5.008001" } } }, "provides" : { "Log::Any" : { "file" : "lib/Log/Any.pm", "version" : "1.038" }, "Log::Any::Adapter" : { "file" : "lib/Log/Any/Adapter.pm", "version" : "1.038" }, "Log::Any::Adapter::Base" : { "file" : "lib/Log/Any/Adapter/Base.pm", "version" : "1.038" }, "Log::Any::Adapter::File" : { "file" : "lib/Log/Any/Adapter/File.pm", "version" : "1.038" }, "Log::Any::Adapter::Null" : { "file" : "lib/Log/Any/Adapter/Null.pm", "version" : "1.038" }, "Log::Any::Adapter::Stderr" : { "file" : "lib/Log/Any/Adapter/Stderr.pm", "version" : "1.038" }, "Log::Any::Adapter::Stdout" : { "file" : "lib/Log/Any/Adapter/Stdout.pm", "version" : "1.038" }, "Log::Any::Adapter::Test" : { "file" : "lib/Log/Any/Adapter/Test.pm", "version" : "1.038" }, "Log::Any::Adapter::Util" : { "file" : "lib/Log/Any/Adapter/Util.pm", "version" : "1.038" }, "Log::Any::Manager" : { "file" : "lib/Log/Any/Manager.pm", "version" : "1.038" }, "Log::Any::Proxy" : { "file" : "lib/Log/Any/Proxy.pm", "version" : "1.038" }, "Log::Any::Proxy::Test" : { "file" : "lib/Log/Any/Proxy/Test.pm", "version" : "1.038" }, "Log::Any::Test" : { "file" : "lib/Log/Any/Test.pm", "version" : "1.038" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/dagolden/Log-Any/issues" }, "homepage" : "https://github.com/dagolden/Log-Any", "repository" : { "type" : "git", "url" : "https://github.com/dagolden/Log-Any.git", "web" : "https://github.com/dagolden/Log-Any" } }, "version" : "1.038", "x_authority" : "cpan:JSWARTZ", "x_contributors" : [ "cm-perl ", "David Golden ", "Maxim Vuets ", "Stephen Thirlwall " ] } Log-Any-1.038/META.yml000644 000765 000024 00000004377 12656724173 014526 0ustar00davidstaff000000 000000 --- abstract: 'Bringing loggers and listeners together' author: - 'Jonathan Swartz ' - 'David Golden ' build_requires: ExtUtils::MakeMaker: '0' File::Spec: '0' File::Temp: '0' Test::More: '0' base: '0' perl: '5.008001' configure_requires: ExtUtils::MakeMaker: '6.17' perl: '5.008001' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.043, CPAN::Meta::Converter version 2.150001' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Log-Any no_index: directory: - corpus - examples - t - xt package: - DB - Log::Any::Manager::_Guard provides: Log::Any: file: lib/Log/Any.pm version: '1.038' Log::Any::Adapter: file: lib/Log/Any/Adapter.pm version: '1.038' Log::Any::Adapter::Base: file: lib/Log/Any/Adapter/Base.pm version: '1.038' Log::Any::Adapter::File: file: lib/Log/Any/Adapter/File.pm version: '1.038' Log::Any::Adapter::Null: file: lib/Log/Any/Adapter/Null.pm version: '1.038' Log::Any::Adapter::Stderr: file: lib/Log/Any/Adapter/Stderr.pm version: '1.038' Log::Any::Adapter::Stdout: file: lib/Log/Any/Adapter/Stdout.pm version: '1.038' Log::Any::Adapter::Test: file: lib/Log/Any/Adapter/Test.pm version: '1.038' Log::Any::Adapter::Util: file: lib/Log/Any/Adapter/Util.pm version: '1.038' Log::Any::Manager: file: lib/Log/Any/Manager.pm version: '1.038' Log::Any::Proxy: file: lib/Log/Any/Proxy.pm version: '1.038' Log::Any::Proxy::Test: file: lib/Log/Any/Proxy/Test.pm version: '1.038' Log::Any::Test: file: lib/Log/Any/Test.pm version: '1.038' requires: B: '0' Carp: '0' Data::Dumper: '0' Exporter: '0' Fcntl: '0' IO::File: '0' Test::Builder: '0' constant: '0' perl: '5.008001' strict: '0' warnings: '0' resources: bugtracker: https://github.com/dagolden/Log-Any/issues homepage: https://github.com/dagolden/Log-Any repository: https://github.com/dagolden/Log-Any.git version: '1.038' x_authority: cpan:JSWARTZ x_contributors: - 'cm-perl ' - 'David Golden ' - 'Maxim Vuets ' - 'Stephen Thirlwall ' Log-Any-1.038/perlcritic.rc000644 000765 000024 00000001166 12656724173 015734 0ustar00davidstaff000000 000000 severity = 5 verbose = 8 [Variables::ProhibitPunctuationVars] allow = $@ $! [TestingAndDebugging::ProhibitNoStrict] allow = refs [Variables::ProhibitEvilVariables] variables = $DB::single # Turn these off [-BuiltinFunctions::ProhibitStringyEval] [-ControlStructures::ProhibitPostfixControls] [-ControlStructures::ProhibitUnlessBlocks] [-Documentation::RequirePodSections] [-InputOutput::ProhibitInteractiveTest] [-References::ProhibitDoubleSigils] [-RegularExpressions::RequireExtendedFormatting] [-InputOutput::ProhibitTwoArgOpen] [-Modules::ProhibitEvilModules] # Turn this on [Lax::ProhibitStringyEval::ExceptForRequire] Log-Any-1.038/README000644 000765 000024 00000026537 12656724173 014137 0ustar00davidstaff000000 000000 NAME Log::Any - Bringing loggers and listeners together VERSION version 1.038 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 data using a formatting filter $log->debugf("arguments are: %s", \@_); 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 DESCRIPTION "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. NAME Log::Any - Bringing loggers and listeners together VERSION version 1.038 LOG LEVELS "Log::Any" 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. 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. PRODUCING LOGS (FOR MODULES) 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 *$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 Log::Any::Proxy, which passes on messages to the Log::Any::Adapter handling its category. If the "proxy_class" argument is passed, an alternative to Log::Any::Proxy (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'); 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"); You should not include a newline in your message; that is the responsibility of the logging mechanism, which may or may not want the newline. There are also versions of each of these methods with an additional "f" suffix ("infof", "errorf", "debugf", etc.) that format a list of arguments. The specific formatting mechanism and meaning of the arguments is controlled by the Log::Any::Proxy object. $log->errorf("an error occurred: %s", $@); $log->debugf("called with %d params: %s", $param_count, \@params); By default it renders like "sprintf", with the following additional features: * Any complex references (like "\@params" above) are automatically converted to single-line strings with "Data::Dumper". * Any undefined values are automatically converted to the string "". 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 @_) if the log level is not active. The formatting methods ("infof", "errorf", 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. Setting an alternate default logger To choose something other than Null as the default, pass it as a parameter when loading "Log::Any" use Log::Any '$log', default_adapter => 'Stderr'; The name of the default class follows the same rules as used by Log::Any::Adapter. Configuring the proxy Any parameter passed on the import line or via the "get_logger" method are passed on the the Log::Any::Proxy constructor. use Log::Any '$log', filter => \&myfilter; Testing Log::Any::Test provides a mechanism to test code that uses "Log::Any". CONSUMING LOGS (FOR APPLICATIONS) Log::Any provides modules with a Log::Any::Proxy object, which is the log producer. To consume its output and direct it where you want (a file, the screen, syslog, etc.), you use Log::Any::Adapter along with a destination-specific subclass. For example, to send output to a file via Log::Any::Adapter::File, your application could do this: use Log::Any::Adapter ('File', '/path/to/file.log'); See the Log::Any::Adapter documentation for more details. Q & A Isn't Log::Any just yet another logging mechanism? No. "Log::Any" 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. 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 "Log::Dispatch" 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. Is it safe for my critical module to depend on Log::Any? Our intent is to keep "Log::Any" minimal, and change it only when absolutely necessary. Most of the "innovation", if any, is expected to occur in "Log::Any::Adapter", which your module should not have to depend on (unless it wants to direct logs somewhere specific). "Log::Any" has no non-core dependencies. Why doesn't Log::Any use *insert modern Perl technique*? To encourage CPAN module authors to adopt and use "Log::Any", we aim to have as few dependencies and chances of breakage as possible. Thus, no "Moose" or other niceties. SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at . You will be notified automatically of any progress on your issue. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. git clone https://github.com/dagolden/Log-Any.git AUTHORS * Jonathan Swartz * David Golden CONTRIBUTORS * cm-perl * David Golden * Maxim Vuets * Stephen Thirlwall COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at . You will be notified automatically of any progress on your issue. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. git clone https://github.com/dagolden/Log-Any.git AUTHORS * Jonathan Swartz * David Golden CONTRIBUTORS * cm-perl * David Golden * Maxim Vuets * Stephen Thirlwall COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Log-Any-1.038/t/000755 000765 000024 00000000000 12656724173 013505 5ustar00davidstaff000000 000000 Log-Any-1.038/tidyall.ini000644 000765 000024 00000000046 12656724173 015405 0ustar00davidstaff000000 000000 ; This space intentionally left blank Log-Any-1.038/xt/000755 000765 000024 00000000000 12656724173 013675 5ustar00davidstaff000000 000000 Log-Any-1.038/xt/author/000755 000765 000024 00000000000 12656724173 015177 5ustar00davidstaff000000 000000 Log-Any-1.038/xt/release/000755 000765 000024 00000000000 12656724173 015315 5ustar00davidstaff000000 000000 Log-Any-1.038/xt/release/backcompat.t000644 000765 000024 00000000475 12656724173 017614 0ustar00davidstaff000000 000000 #!perl # # Test old Log::Any->set_adapter API # use strict; use warnings; use Test::More tests => 2; use Log::Any qw($log), proxy_class => 'Test'; Log::Any->set_adapter('Test', dummy_param => 1); $log->error("bleah"); $log->contains_ok( qr/bleah/ ); is ( $log->adapter->{dummy_param}, 1, "adapter parameters set" ); Log-Any-1.038/xt/release/distmeta.t000644 000765 000024 00000000172 12656724173 017314 0ustar00davidstaff000000 000000 #!perl # This file was automatically generated by Dist::Zilla::Plugin::MetaTests. use Test::CPAN::Meta; meta_yaml_ok(); Log-Any-1.038/xt/release/minimum-version.t000644 000765 000024 00000000266 12656724173 020644 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::MinimumVersion"; plan skip_all => "Test::MinimumVersion required for testing minimum versions" if $@; all_minimum_version_ok( qq{5.010} ); Log-Any-1.038/xt/release/portability.t000644 000765 000024 00000000332 12656724173 020042 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; eval 'use Test::Portability::Files'; plan skip_all => 'Test::Portability::Files required for testing portability' if $@; options(test_one_dot => 0); run_tests(); Log-Any-1.038/xt/author/00-compile.t000644 000765 000024 00000003106 12656724173 017231 0ustar00davidstaff000000 000000 use 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.054 use Test::More; plan tests => 14; my @module_files = ( 'Log/Any.pm', 'Log/Any/Adapter.pm', 'Log/Any/Adapter/Base.pm', 'Log/Any/Adapter/File.pm', 'Log/Any/Adapter/Null.pm', 'Log/Any/Adapter/Stderr.pm', 'Log/Any/Adapter/Stdout.pm', 'Log/Any/Adapter/Test.pm', 'Log/Any/Adapter/Util.pm', 'Log/Any/Manager.pm', 'Log/Any/Proxy.pm', 'Log/Any/Proxy/Test.pm', 'Log/Any/Test.pm' ); # fake home for cpan-testers use File::Temp; local $ENV{HOME} = File::Temp::tempdir( CLEANUP => 1 ); my $inc_switch = -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; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-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) ); Log-Any-1.038/xt/author/critic.t000644 000765 000024 00000000435 12656724173 016643 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; use English qw(-no_match_vars); eval "use Test::Perl::Critic"; plan skip_all => 'Test::Perl::Critic required to criticise code' if $@; Test::Perl::Critic->import( -profile => "perlcritic.rc" ) if -e "perlcritic.rc"; all_critic_ok(); Log-Any-1.038/xt/author/pod-spell.t000644 000765 000024 00000001037 12656724173 017264 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.007000 use Test::Spelling 0.12; use Pod::Wordlist; add_stopwords(); all_pod_files_spelling_ok( qw( bin lib ) ); __DATA__ alertf crit critf criticalf debugf emergencyf errf errorf fatalf infof informf msgs noticef passsed tracef tranformed warnf warningf Jonathan Swartz swartz David Golden dagolden and cm xdg Maxim Vuets maxim Stephen Thirlwall sdt lib Log Any Adapter Base Development File Null Stderr Stdout Test Util Manager Proxy Log-Any-1.038/xt/author/pod-syntax.t000644 000765 000024 00000000252 12656724173 017471 0ustar00davidstaff000000 000000 #!perl # 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(); Log-Any-1.038/xt/author/test-version.t000644 000765 000024 00000000640 12656724173 020026 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::Version 1.05 use Test::Version; my @imports = qw( version_all_ok ); my $params = { is_strict => 0, has_version => 1, multiple => 0, }; push @imports, $params if version->parse( $Test::Version::VERSION ) >= version->parse('1.002'); Test::Version->import(@imports); version_all_ok; done_testing; Log-Any-1.038/t/00-report-prereqs.dd000644 000765 000024 00000005465 12656724173 017237 0ustar00davidstaff000000 000000 do { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '6.17', 'perl' => '5.008001' } }, 'develop' => { 'requires' => { 'Dist::Zilla' => '5', 'Dist::Zilla::Plugin::OnlyCorePrereqs' => '0.003', 'Dist::Zilla::Plugin::SurgicalPodWeaver' => '0.0021', 'Dist::Zilla::PluginBundle::DAGOLDEN' => '0.072', 'English' => '0', 'File::Spec' => '0', 'File::Temp' => '0', 'IO::Handle' => '0', 'IPC::Open3' => '0', 'Pod::Wordlist' => '0', 'Software::License::Perl_5' => '0', 'Test::CPAN::Meta' => '0', 'Test::More' => '0', 'Test::Pod' => '1.41', 'Test::Spelling' => '0.12', 'Test::Version' => '1', 'blib' => '1.01' } }, 'runtime' => { 'requires' => { 'B' => '0', 'Carp' => '0', 'Data::Dumper' => '0', 'Exporter' => '0', 'Fcntl' => '0', 'IO::File' => '0', 'Test::Builder' => '0', 'constant' => '0', 'perl' => '5.008001', 'strict' => '0', 'warnings' => '0' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'File::Temp' => '0', 'Test::More' => '0', 'base' => '0', 'perl' => '5.008001' } } }; $x; }Log-Any-1.038/t/00-report-prereqs.t000644 000765 000024 00000012731 12656724173 017105 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.021 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'; if ( $source && $HAS_CPAN_META ) { if ( my $meta = eval { CPAN::Meta->load_file($source) } ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } } else { $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 ( @dep_errors ) { diag join("\n", "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n", "The following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass; # vim: ts=4 sts=4 sw=4 et: Log-Any-1.038/t/default-adapter.t000644 000765 000024 00000001201 12656724173 016726 0ustar00davidstaff000000 000000 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(); Log-Any-1.038/t/default-vs-test.t000644 000765 000024 00000001176 12656724173 016726 0ustar00davidstaff000000 000000 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(); Log-Any-1.038/t/errors-adapter.t000644 000765 000024 00000000634 12656724173 016627 0ustar00davidstaff000000 000000 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 = ''" ); Log-Any-1.038/t/filescreen.t000644 000765 000024 00000004250 12656724173 016012 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; use File::Temp qw(tempdir); use Log::Any::Adapter::Util qw(cmp_deeply read_file); plan tests => 16; 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" ); } } { 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" ); } } { 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" ); } } Log-Any-1.038/t/import.t000644 000765 000024 00000000410 12656724173 015177 0ustar00davidstaff000000 000000 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" ); } Log-Any-1.038/t/inner-adapter.t000644 000765 000024 00000001212 12656724173 016417 0ustar00davidstaff000000 000000 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" ); Log-Any-1.038/t/log-any-test.t000644 000765 000024 00000001326 12656724173 016217 0ustar00davidstaff000000 000000 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"); } Log-Any-1.038/t/memory.t000644 000765 000024 00000006740 12656724173 015211 0ustar00davidstaff000000 000000 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' ); Log-Any-1.038/t/proxy.t000644 000765 000024 00000002364 12656724173 015060 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; use Log::Any::Test; use Log::Any::Adapter 'Test'; plan tests => 7; my $log; $log = Log::Any->get_logger( prefix => 'Foo: ' ); $log->info("test"); $log->contains_ok(qr/^Foo: test$/, 'prefix added'); $log->clear; $log = Log::Any->get_logger; $log->info(qw/one two three four/); $log->contains_ok(qr/^one two three four$/, 'arguments concatenated'); $log->clear; $log = Log::Any->get_logger; $log->infof(sub { "ran sub" } ); $log->contains_ok(qr/^ran sub$/, 'default formatter expands coderefs'); $log->clear; $log = Log::Any->get_logger; $log->infof("got %s %s", "coderef", sub { "expanded" } ); $log->contains_ok(qr/DUMMY/, 'default formatter does not expand coderefs as sprintf args'); $log->clear; $log = Log::Any->get_logger( filter => sub { "@_"} ); $log->emergency("test"); $log->contains_ok(qr/^main 0 test$/, 'filter has category and numeric level'); $log->clear; $log = Log::Any->get_logger( formatter => sub { "@_"} ); $log->tracef("test foo"); $log->contains_ok(qr/^main 8 test foo$/, 'formatter has category and numeric level'); $log->clear; $log = Log::Any->get_logger( category => 'Foo', filter => sub { "@_"} ); $log->info("test"); $log->contains_ok(qr/^Foo 6 test$/, 'category override'); $log->clear; Log-Any-1.038/t/replace_log.t000644 000765 000024 00000000430 12656724173 016143 0ustar00davidstaff000000 000000 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-1.038/t/sprintf.t000644 000765 000024 00000001231 12656724173 015354 0ustar00davidstaff000000 000000 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' ); Log-Any-1.038/t/valid-methods.t000644 000765 000024 00000001625 12656724173 016436 0ustar00davidstaff000000 000000 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" ); } Log-Any-1.038/lib/Log/000755 000765 000024 00000000000 12656724173 014531 5ustar00davidstaff000000 000000 Log-Any-1.038/lib/Log/Any/000755 000765 000024 00000000000 12656724173 015260 5ustar00davidstaff000000 000000 Log-Any-1.038/lib/Log/Any.pm000644 000765 000024 00000033622 12656724173 015624 0ustar00davidstaff000000 000000 use 5.008001; use strict; use warnings; package Log::Any; # ABSTRACT: Bringing loggers and listeners together our $VERSION = '1.038'; use Log::Any::Manager; 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 ( $param eq '$log' ) { $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 ($saw_log_param) { no strict 'refs'; my $proxy = $class->get_logger( category => $caller, @params ); my $varname = "$caller\::log"; *$varname = \$proxy; } } sub get_logger { my ( $class, %params ) = @_; no warnings 'once'; my $proxy_class = $class->_get_proxy_class( delete $params{proxy_class} ); my $category = defined $params{category} ? delete $params{'category'} : caller; if ( my $default = delete $params{'default_adapter'} ) { $class->_manager->set_default( $category, $default ); } my $adapter = $class->_manager->get_adapter( $category ); require_dynamic($proxy_class); return $proxy_class->new( %params, adapter => $adapter, category => $category, ); } sub _get_proxy_class { my ( $self, $proxy_name ) = @_; return $Log::Any::OverrideDefaultProxyClass if $Log::Any::OverrideDefaultProxyClass; return "Log::Any::Proxy" unless $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.038 =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 data using a formatting filter $log->debugf("arguments are: %s", \@_); 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 NAME Log::Any - Bringing loggers and listeners together =head1 VERSION version 1.038 =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"); 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. There are also versions of each of these 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 C, with the following additional features: =over =item * Any complex references (like C<\@params> above) are automatically converted to single-line strings with C. =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 Setting an alternate default logger To choose something other than Null as the default, 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. =head2 Configuring the proxy Any parameter passed on the import line or via the C method are passed on the 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 C 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 =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. L git clone https://github.com/dagolden/Log-Any.git =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 CONTRIBUTORS =for stopwords cm-perl David Golden Maxim Vuets Stephen Thirlwall =over 4 =item * cm-perl =item * David Golden =item * Maxim Vuets =item * Stephen Thirlwall =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. L git clone https://github.com/dagolden/Log-Any.git =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 CONTRIBUTORS =for stopwords cm-perl David Golden Maxim Vuets Stephen Thirlwall =over 4 =item * cm-perl =item * David Golden =item * Maxim Vuets =item * Stephen Thirlwall =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. 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 Log-Any-1.038/lib/Log/Any/Adapter/000755 000765 000024 00000000000 12656724173 016640 5ustar00davidstaff000000 000000 Log-Any-1.038/lib/Log/Any/Adapter.pm000644 000765 000024 00000015060 12656724173 017200 0ustar00davidstaff000000 000000 use 5.008001; use strict; use warnings; package Log::Any::Adapter; # ABSTRACT: Tell Log::Any where to send its logs our $VERSION = '1.038'; use Log::Any; 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(@_) } 1; __END__ =pod =encoding UTF-8 =head1 NAME Log::Any::Adapter - Tell Log::Any where to send its logs =head1 VERSION version 1.038 =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 NAME Log::Any::Adapter - Tell Log::Any where to send its logs =head1 VERSION version 1.038 =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, it calls C<< Log::Any::Adapter->set >> with those arguments. =item Log::Any::Adapter->remove (entry) Remove an I previously returned by C. =back =head1 USING MORE THAN ONE ADAPTER C maintains a stack of entries created via C. If you call C repeatedly, you will leak memory unless you do one of the following: =over 4 =item * call C on the adapter returned from C when you are done with it =item * use the C feature to set a guard variable that will clean it up when it goes out of scope =back When getting a logger for a particular category, C will work its way down the stack and use the first matching entry. Whenever the stack changes, any C loggers that have previously been created will automatically adjust to the new stack. For example: my $log = Log::Any->get_logger(); $log->error("aiggh!"); # this goes nowhere ... { Log::Any::Adapter->set({ lexically => \my $lex }, 'Log4perl'); $log->error("aiggh!"); # this goes to log4perl ... } $log->error("aiggh!"); # this goes nowhere again =head1 SEE ALSO L =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. 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 Log-Any-1.038/lib/Log/Any/Manager.pm000644 000765 000024 00000012410 12656724173 017166 0ustar00davidstaff000000 000000 use 5.008001; use strict; use warnings; package Log::Any::Manager; our $VERSION = '1.038'; sub new { my $class = shift; my $self = { entries => [], category_cache => {}, default_adapter => {}, }; bless $self, $class; return $self; } sub get_adapter { my ( $self, $category ) = @_; # Create a new adapter for this category if it is not already in cache # my $category_cache = $self->{category_cache}; if ( !defined( $category_cache->{$category} ) ) { my $entry = $self->_choose_entry_for_category($category); my $adapter = $self->_new_adapter_for_entry( $entry, $category ); $category_cache->{$category} = { entry => $entry, adapter => $adapter }; } return $category_cache->{$category}->{adapter}; } { no warnings 'once'; *get_logger = \&get_adapter; # backwards compatibility } sub _choose_entry_for_category { my ( $self, $category ) = @_; foreach my $entry ( @{ $self->{entries} } ) { if ( $category =~ $entry->{pattern} ) { return $entry; } } # nothing requested so fallback to default my $default = $self->{default_adapter}{$category} || [ $self->_get_adapter_class("Null"), [] ]; my ($adapter_class, $adapter_params) = @$default; _require_dynamic($adapter_class); return { adapter_class => $adapter_class, adapter_params => $adapter_params, }; } sub _new_adapter_for_entry { my ( $self, $entry, $category ) = @_; return $entry->{adapter_class} ->new( @{ $entry->{adapter_params} }, category => $category ); } sub set_default { my ( $self, $category, $adapter_name, @adapter_params ) = @_; my $adapter_class = $self->_get_adapter_class($adapter_name); $self->{default_adapter}{$category} = [$adapter_class, \@adapter_params]; } sub set { my $self = shift; my $options; if ( ref( $_[0] ) eq 'HASH' ) { $options = shift(@_); } my ( $adapter_name, @adapter_params ) = @_; unless ( defined($adapter_name) && $adapter_name =~ /\S/ ) { require Carp; Carp::croak("expected adapter name"); } my $pattern = $options->{category}; if ( !defined($pattern) ) { $pattern = qr/.*/; } elsif ( !ref($pattern) ) { $pattern = qr/^\Q$pattern\E$/; } my $adapter_class = $self->_get_adapter_class($adapter_name); _require_dynamic($adapter_class); my $entry = $self->_new_entry( $pattern, $adapter_class, \@adapter_params ); unshift( @{ $self->{entries} }, $entry ); $self->_reselect_matching_adapters($pattern); if ( my $lex_ref = $options->{lexically} ) { $$lex_ref = Log::Any::Manager::_Guard->new( sub { $self->remove($entry) unless _in_global_destruction() } ); } return $entry; } sub remove { my ( $self, $entry ) = @_; my $pattern = $entry->{pattern}; $self->{entries} = [ grep { $_ ne $entry } @{ $self->{entries} } ]; $self->_reselect_matching_adapters($pattern); } sub _new_entry { my ( $self, $pattern, $adapter_class, $adapter_params ) = @_; return { pattern => $pattern, adapter_class => $adapter_class, adapter_params => $adapter_params, }; } sub _reselect_matching_adapters { my ( $self, $pattern ) = @_; return if _in_global_destruction(); # Reselect adapter for each category matching $pattern # while ( my ( $category, $category_info ) = each( %{ $self->{category_cache} } ) ) { my $new_entry = $self->_choose_entry_for_category($category); if ( $new_entry ne $category_info->{entry} ) { my $new_adapter = $self->_new_adapter_for_entry( $new_entry, $category ); %{ $category_info->{adapter} } = %$new_adapter; bless( $category_info->{adapter}, ref($new_adapter) ); $category_info->{entry} = $new_entry; } } } sub _get_adapter_class { my ( $self, $adapter_name ) = @_; return $Log::Any::OverrideDefaultAdapterClass if $Log::Any::OverrideDefaultAdapterClass; $adapter_name =~ s/^Log:://; # Log::Dispatch -> Dispatch, etc. my $adapter_class = ( substr( $adapter_name, 0, 1 ) eq '+' ? substr( $adapter_name, 1 ) : "Log::Any::Adapter::$adapter_name" ); return $adapter_class; } # This is adapted from the pure perl parts of Devel::GlobalDestruction if ( defined ${^GLOBAL_PHASE} ) { eval 'sub _in_global_destruction () { ${^GLOBAL_PHASE} eq q[DESTRUCT] }; 1' ## no critic or die $@; } else { require B; my $started = !B::main_start()->isa(q[B::NULL]); unless ($started) { eval '0 && $started; CHECK { $started = 1 }; 1' ## no critic or die $@; } eval ## no critic '0 && $started; sub _in_global_destruction () { $started && B::main_start()->isa(q[B::NULL]) }; 1' or die $@; } # XXX not DRY and not a great way to do this, but oh, well. sub _require_dynamic { my ($class) = @_; return 1 if $class->can('new'); # duck-type that class is loaded unless ( defined( eval "require $class; 1" ) ) { ## no critic (ProhibitStringyEval) die $@; } } package # hide from PAUSE Log::Any::Manager::_Guard; sub new { bless $_[1], $_[0] } sub DESTROY { $_[0]->() } 1; Log-Any-1.038/lib/Log/Any/Proxy/000755 000765 000024 00000000000 12656724173 016401 5ustar00davidstaff000000 000000 Log-Any-1.038/lib/Log/Any/Proxy.pm000644 000765 000024 00000017216 12656724173 016746 0ustar00davidstaff000000 000000 use 5.008001; use strict; use warnings; package Log::Any::Proxy; # ABSTRACT: Log::Any generator proxy object our $VERSION = '1.038'; use Log::Any::Adapter::Util (); sub _default_formatter { my ( $cat, $lvl, $format, @params ) = @_; return $format->() if ref($format) eq 'CODE'; my @new_params = map { !defined($_) ? '' : ref($_) ? Log::Any::Adapter::Util::dump_one_line($_) : $_ } @params; 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 an 'category' parameter") } bless $self, $class; $self->init(@_); return $self; } sub init { } for my $attr (qw/adapter filter formatter prefix/) { 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 ) = @_; my $message = join(" ", grep { defined($_) && length($_) } @parts ); return unless length $message; $message = $self->{filter}->( $self->{category}, $numeric, $message ) if defined $self->{filter}; return unless defined $message and length $message; $message = "$self->{prefix}$message" if defined $self->{prefix} && length $self->{prefix}; return $self->{adapter}->$realname($message); }; *{$namef} = sub { my ( $self, @args ) = @_; return unless $self->{adapter}->$is_realname; 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.038 =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 ); }; =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 USAGE =head2 Simple logging Your library can do simple logging using logging methods corresponding to the log levels (or aliases): =over 4 =item * trace =item * debug =item * info (inform) =item * notice =item * warning (warn) =item * error (err) =item * critical (crit, fatal) =item * alert =item * emergency =back Pass a string to be logged. Do not include a newline. $log->info("Got some new for you."); The log string will be tranformed via the C attribute (if any) and the C (if any) will be prepended. 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: =over 4 =item * tracef =item * debugf =item * infof (informf) =item * noticef =item * warningf (warnf) =item * errorf (errf) =item * criticalf (critf, fatalf) =item * alertf =item * emergencyf =back 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. =head1 NAME Log::Any::Proxy - Log::Any generator proxy object =head1 VERSION version 1.038 =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. =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: =over 4 =item * if the first argument is a code reference, it is executed and the result returned =item * 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). =back Numeric levels range from 0 (emergency) to 8 (trace). Constant functions for these levels are available from L. =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 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. 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 Log-Any-1.038/lib/Log/Any/Test.pm000644 000765 000024 00000007364 12656724173 016547 0ustar00davidstaff000000 000000 use 5.008001; use strict; use warnings; package Log::Any::Test; # ABSTRACT: Test what you're logging with Log::Any our $VERSION = '1.038'; 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.038 =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 sends all subsequent Log::Any log messages to a single global in-memory buffer. It should be used before L. =head1 NAME Log::Any::Test - Test what you're logging with Log::Any =head1 VERSION version 1.038 =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 =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. 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 Log-Any-1.038/lib/Log/Any/Proxy/Test.pm000644 000765 000024 00000000724 12656724173 017661 0ustar00davidstaff000000 000000 use 5.008001; use strict; use warnings; package Log::Any::Proxy::Test; our $VERSION = '1.038'; use Log::Any::Proxy; our @ISA = qw/Log::Any::Proxy/; my @test_methods = qw( msgs clear contains_ok category_contains_ok does_not_contain_ok category_does_not_contain_ok empty_ok contains_only_ok ); foreach my $name (@test_methods) { no strict 'refs'; *{$name} = sub { my $self = shift; $self->{adapter}->$name(@_); }; } 1; Log-Any-1.038/lib/Log/Any/Adapter/Base.pm000644 000765 000024 00000001614 12656724173 020052 0ustar00davidstaff000000 000000 use 5.008001; use strict; use warnings; package Log::Any::Adapter::Base; our $VERSION = '1.038'; # we import these in case any legacy adapter uses them as class methods use Log::Any::Adapter::Util qw/make_method dump_one_line/; sub new { my $class = shift; my $self = {@_}; bless $self, $class; $self->init(@_); return $self; } sub init { } # Create stub logging methods for my $method ( Log::Any::Adapter::Util::logging_and_detection_methods() ) { no strict 'refs'; *$method = sub { my $class = ref( $_[0] ) || $_[0]; die "$class does not implement $method"; }; } # This methods installs a method that delegates to an object attribute sub delegate_method_to_slot { my ( $class, $slot, $method, $adapter_method ) = @_; make_method( $method, sub { my $self = shift; return $self->{$slot}->$adapter_method(@_) }, $class ); } 1; Log-Any-1.038/lib/Log/Any/Adapter/Development.pod000644 000765 000024 00000015754 12656724173 021642 0ustar00davidstaff000000 000000 # PODNAME: Log::Any::Adapter::Development # ABSTRACT: Manual for developing new Log::Any adapters # vim: ts=4 sts=4 sw=4 et tw=75: __END__ =pod =encoding UTF-8 =head1 NAME Log::Any::Adapter::Development - Manual for developing new Log::Any adapters =head1 VERSION version 1.038 =head1 SYNOPSIS The adapter module: package Log::Any::Adapter::YAL; use strict; use warnings; use Log::Any::Adapter::Util (); use base qw(Log::Any::Adapter::Base); # Optionally initialize object, e.g. for delegation # sub init { my ($self) = @_; $self->{attr} = ...; } # Create logging methods: debug, info, etc. # foreach my $method ( Log::Any::Adapter::Util::logging_methods() ) { no strict 'refs'; *$method = sub { ... }; } # Create detection methods: is_debug, is_info, etc. # foreach my $method ( Log::Any::Adapter::Util::detection_methods() ) { no strict 'refs'; *$method = sub { ... }; } and the application: Log::Any->set_adapter('YAL'); =head1 DESCRIPTION This document describes how to implement a new Log::Any adapter. The easiest way to start is to look at the source of existing adapters, such as L and L. =head1 NAME Log::Any::Adapter::Development - Manual for developing new Log::Any adapters =head1 VERSION version 1.038 =head1 NAMING If you are going to publicly release your adapter, call it 'Log::Any::Adapter::I' so that users can use it with Log::Any->set_adapter(I); If it's an internal driver, you can call it whatever you like and use it like Log::Any->set_adapter('+My::Log::Adapter'); =head1 BASE CLASS All adapters must directly or indirectly inherit from L. =head1 LOG LEVELS Log::Any supports the following log levels: =over 4 =item * trace =item * debug =item * info =item * notice =item * warning =item * error =item * critical =item * alert =item * emergency =back If the logging mechanism used by your adapter supports different levels, it's your responsibility to map them appropriately when you implement the logging and detection methods described below. For example, if your mechanism only supports "debug", "normal" and "fatal" levels, you might map the levels like this: =over 4 =item * debug: trace, debug =item * normal: info, notice, warning =item * fatal: error, critical, alert, emergency =back =head1 METHODS =head2 Constructor The constructor (C) is provided by L. It will: =over 4 =item * place any adapter arguments into a hash, along with the category =item * bless the hash into your subclass =item * call L which may be optionally provided by your subclass =back At this point, overriding the default constructor is not supported. Hopefully it will not be needed. The constructor is called whenever a log object is requested. e.g. If the application initializes Log::Any like so: Log::Any->set_adapter('Log::YAL', yal_object => $yal, depth => 3); and then a class requests a logger like so: package Foo; use Log::Any qw($log); Then C<$log> will be populated with the return value of: Log::Any::Adapter::Yal->new(yal_object => $yal, depth => 3, category => 'Foo'); This is memoized, so if the same category should be requested again (e.g. through a separate C call, the same object will be returned. Therefore, you should try to avoid anything non-deterministic in your L function. =head2 Logging methods (required) The following methods have no default implementation, and MUST be defined by your subclass: =over 4 =item * debug ($msg) =item * info ($msg) =item * notice ($msg) =item * warning ($msg) =item * error ($msg) =item * critical ($msg) =item * alert ($msg) =item * emergency ($msg) =back These methods must log a message at the specified level. To help generate these methods programmatically, you can get a list of the sub names with the L function. =head2 Log-level detection methods (required) The following methods have no default implementation, and MUST be defined by your subclass: =over 4 =item * is_debug () =item * is_info () =item * is_notice () =item * is_warning () =item * is_error () =item * is_critical () =item * is_alert () =item * is_emergency () =back These methods must return a boolean indicating whether the specified level is active, i.e. whether the adapter is listening for messages of that level. To help generate these methods programmatically, you can get a list of the sub names with the L function. =head2 Aliases Aliases (e.g. "err" for "error") are handled by L and will call the corresponding real name in your adapter class. You do not need to implement them in your adapter. =head2 Optional methods The following methods have no default implementation but MAY be provided by your subclass: =over =item init This is called after the adapter object is created and blessed into your class. Perform any necessary validation or initialization here. For example, you would use C to create a logging object for delegation, or open a file or socket, etc. =back =head2 Support methods The following L method may be useful for defining adapters via delegation: =over =item delegate_method_to_slot ($slot, $method, $adapter_method) Handle the specified C<$method> by calling C<$adapter_method> on the object contained in C<< $self->{$slot} >>. See L and L for examples of usage. =back The following L functions give you a list of methods that you need to implement. You can get logging methods, detection methods or both: =over 4 =item * L =item * L =item * L =back =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. 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 Log-Any-1.038/lib/Log/Any/Adapter/File.pm000644 000765 000024 00000007242 12656724173 020062 0ustar00davidstaff000000 000000 use 5.008001; use strict; use warnings; package Log::Any::Adapter::File; # ABSTRACT: Simple adapter for logging to files our $VERSION = '1.038'; use Config; use Fcntl qw/:flock/; use IO::File; use Log::Any::Adapter::Util (); use Log::Any::Adapter::Base; our @ISA = qw/Log::Any::Adapter::Base/; my $HAS_FLOCK = $Config{d_flock} || $Config{d_fcntl_can_lock} || $Config{d_lockf}; my $trace_level = Log::Any::Adapter::Util::numeric_level('trace'); sub new { my ( $class, $file, @args ) = @_; return $class->SUPER::new( file => $file, log_level => $trace_level, @args ); } sub init { my $self = shift; if ( exists $self->{log_level} ) { $self->{log_level} = Log::Any::Adapter::Util::numeric_level( $self->{log_level} ) unless $self->{log_level} =~ /^\d+$/; } else { $self->{log_level} = $trace_level; } my $file = $self->{file}; my $binmode ||= ':utf8'; $binmode = ":$binmode" unless substr($binmode,0,1) eq ':'; open( $self->{fh}, ">>$binmode", $file ) or die "cannot open '$file' for append: $!"; $self->{fh}->autoflush(1); } foreach my $method ( Log::Any::Adapter::Util::logging_methods() ) { no strict 'refs'; my $method_level = Log::Any::Adapter::Util::numeric_level( $method ); *{$method} = sub { my ( $self, $text ) = @_; return if $method_level > $self->{log_level}; my $msg = sprintf( "[%s] %s\n", scalar(localtime), $text ); flock($self->{fh}, LOCK_EX) if $HAS_FLOCK; $self->{fh}->print($msg); flock($self->{fh}, LOCK_UN) if $HAS_FLOCK; } } foreach my $method ( Log::Any::Adapter::Util::detection_methods() ) { no strict 'refs'; my $base = substr($method,3); my $method_level = Log::Any::Adapter::Util::numeric_level( $base ); *{$method} = sub { return !!( $method_level <= $_[0]->{log_level} ); }; } 1; __END__ =pod =encoding UTF-8 =head1 NAME Log::Any::Adapter::File - Simple adapter for logging to files =head1 VERSION version 1.038 =head1 SYNOPSIS use Log::Any::Adapter ('File', '/path/to/file.log'); # or use Log::Any::Adapter; ... Log::Any::Adapter->set('File', '/path/to/file.log'); # with minimum level 'warn' use Log::Any::Adapter ( 'File', '/path/to/file.log', log_level => 'warn', ); =head1 DESCRIPTION This simple built-in L adapter logs each message to the specified file, with a datestamp prefix and newline appended. The file is opened for append with autoflush on. If C is available, the handle will be locked when writing. The C attribute may be set to define a minimum level to log. The C attribute may be set to define a PerlIO layer string to use when opening the file. The default is C<:utf8>. Category is ignored. =head1 NAME Log::Any::Adapter::File - Simple adapter for logging to files =head1 VERSION version 1.038 =head1 SEE ALSO L, L =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. 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 Log-Any-1.038/lib/Log/Any/Adapter/Null.pm000644 000765 000024 00000003250 12656724173 020110 0ustar00davidstaff000000 000000 use 5.008001; use strict; use warnings; package Log::Any::Adapter::Null; # ABSTRACT: Discards all log messages our $VERSION = '1.038'; use Log::Any::Adapter::Base; our @ISA = qw/Log::Any::Adapter::Base/; use Log::Any::Adapter::Util (); # All methods are no-ops and return false foreach my $method (Log::Any::Adapter::Util::logging_and_detection_methods()) { no strict 'refs'; *{$method} = sub { return '' }; # false } 1; __END__ =pod =encoding UTF-8 =head1 NAME Log::Any::Adapter::Null - Discards all log messages =head1 VERSION version 1.038 =head1 SYNOPSIS Log::Any::Adapter->set('Null'); =head1 DESCRIPTION This Log::Any adapter discards all log messages and returns false for all detection methods (e.g. is_debug). This is the default adapter when Log::Any is loaded. =head1 NAME Log::Any::Adapter::Null - Discards all log messages =head1 VERSION version 1.038 =head1 SEE ALSO L, L =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. 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 Log-Any-1.038/lib/Log/Any/Adapter/Stderr.pm000644 000765 000024 00000005247 12656724173 020451 0ustar00davidstaff000000 000000 use 5.008001; use strict; use warnings; package Log::Any::Adapter::Stderr; # ABSTRACT: Simple adapter for logging to STDERR our $VERSION = '1.038'; use Log::Any::Adapter::Util (); use Log::Any::Adapter::Base; our @ISA = qw/Log::Any::Adapter::Base/; my $trace_level = Log::Any::Adapter::Util::numeric_level('trace'); sub init { my ($self) = @_; if ( exists $self->{log_level} ) { $self->{log_level} = Log::Any::Adapter::Util::numeric_level( $self->{log_level} ) unless $self->{log_level} =~ /^\d+$/; } else { $self->{log_level} = $trace_level; } } foreach my $method ( Log::Any::Adapter::Util::logging_methods() ) { no strict 'refs'; my $method_level = Log::Any::Adapter::Util::numeric_level($method); *{$method} = sub { my ( $self, $text ) = @_; return if $method_level > $self->{log_level}; print STDERR "$text\n"; }; } foreach my $method ( Log::Any::Adapter::Util::detection_methods() ) { no strict 'refs'; my $base = substr( $method, 3 ); my $method_level = Log::Any::Adapter::Util::numeric_level($base); *{$method} = sub { return !!( $method_level <= $_[0]->{log_level} ); }; } 1; __END__ =pod =encoding UTF-8 =head1 NAME Log::Any::Adapter::Stderr - Simple adapter for logging to STDERR =head1 VERSION version 1.038 =head1 SYNOPSIS use Log::Any::Adapter ('Stderr'); # or use Log::Any::Adapter; ... Log::Any::Adapter->set('Stderr'); # with minimum level 'warn' use Log::Any::Adapter ('Stderr', log_level => 'warn' ); =head1 DESCRIPTION This simple built-in L adapter logs each message to STDERR with a newline appended. Category is ignored. The C attribute may be set to define a minimum level to log. =head1 NAME Log::Any::Adapter::Stderr - Simple adapter for logging to STDERR =head1 VERSION version 1.038 =head1 SEE ALSO L, L =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. 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 Log-Any-1.038/lib/Log/Any/Adapter/Stdout.pm000644 000765 000024 00000005247 12656724173 020470 0ustar00davidstaff000000 000000 use 5.008001; use strict; use warnings; package Log::Any::Adapter::Stdout; # ABSTRACT: Simple adapter for logging to STDOUT our $VERSION = '1.038'; use Log::Any::Adapter::Util (); use Log::Any::Adapter::Base; our @ISA = qw/Log::Any::Adapter::Base/; my $trace_level = Log::Any::Adapter::Util::numeric_level('trace'); sub init { my ($self) = @_; if ( exists $self->{log_level} ) { $self->{log_level} = Log::Any::Adapter::Util::numeric_level( $self->{log_level} ) unless $self->{log_level} =~ /^\d+$/; } else { $self->{log_level} = $trace_level; } } foreach my $method ( Log::Any::Adapter::Util::logging_methods() ) { no strict 'refs'; my $method_level = Log::Any::Adapter::Util::numeric_level($method); *{$method} = sub { my ( $self, $text ) = @_; return if $method_level > $self->{log_level}; print STDOUT "$text\n"; }; } foreach my $method ( Log::Any::Adapter::Util::detection_methods() ) { no strict 'refs'; my $base = substr( $method, 3 ); my $method_level = Log::Any::Adapter::Util::numeric_level($base); *{$method} = sub { return !!( $method_level <= $_[0]->{log_level} ); }; } 1; __END__ =pod =encoding UTF-8 =head1 NAME Log::Any::Adapter::Stdout - Simple adapter for logging to STDOUT =head1 VERSION version 1.038 =head1 SYNOPSIS use Log::Any::Adapter ('Stdout'); # or use Log::Any::Adapter; ... Log::Any::Adapter->set('Stdout'); # with minimum level 'warn' use Log::Any::Adapter ('Stdout', log_level => 'warn' ); =head1 DESCRIPTION This simple built-in L adapter logs each message to STDOUT with a newline appended. Category is ignored. The C attribute may be set to define a minimum level to log. =head1 NAME Log::Any::Adapter::Stdout - Simple adapter for logging to STDOUT =head1 VERSION version 1.038 =head1 SEE ALSO L, L =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. 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 Log-Any-1.038/lib/Log/Any/Adapter/Test.pm000644 000765 000024 00000011474 12656724173 020124 0ustar00davidstaff000000 000000 use 5.008001; use strict; use warnings; package Log::Any::Adapter::Test; our $VERSION = '1.038'; use Log::Any::Adapter::Util qw/dump_one_line/; use Test::Builder; use Log::Any::Adapter::Base; our @ISA = qw/Log::Any::Adapter::Base/; my $tb = Test::Builder->new(); my @msgs; # Ignore arguments for the original adapter if we're overriding, but recover # category from argument list; this depends on category => $category being put # at the end of the list in Log::Any::Manager. If not overriding, allow # arguments as usual. sub new { my $class = shift; if ( defined $Log::Any::OverrideDefaultAdapterClass && $Log::Any::OverrideDefaultAdapterClass eq __PACKAGE__ ) { my $category = pop @_; return $class->SUPER::new( category => $category ); } else { return $class->SUPER::new(@_); } } # All detection methods return true # foreach my $method ( Log::Any::Adapter::Util::detection_methods() ) { no strict 'refs'; *{$method} = sub { 1 }; } # All logging methods push onto msgs array # foreach my $method ( Log::Any::Adapter::Util::logging_methods() ) { no strict 'refs'; *{$method} = sub { my ( $self, $msg ) = @_; push( @msgs, { message => $msg, level => $method, category => $self->{category} } ); }; } # Testing methods below # sub msgs { my $self = shift; return \@msgs; } sub clear { my ($self) = @_; @msgs = (); } sub contains_ok { my ( $self, $regex, $test_name ) = @_; local $Test::Builder::Level = $Test::Builder::Level + 1; $test_name ||= "log contains '$regex'"; my $found = _first_index( sub { $_->{message} =~ /$regex/ }, @{ $self->msgs } ); if ( $found != -1 ) { splice( @{ $self->msgs }, $found, 1 ); $tb->ok( 1, $test_name ); } else { $tb->ok( 0, $test_name ); $tb->diag( "could not find message matching $regex" ); _diag_msgs(); } } sub category_contains_ok { my ( $self, $category, $regex, $test_name ) = @_; local $Test::Builder::Level = $Test::Builder::Level + 1; $test_name ||= "log for $category contains '$regex'"; my $found = _first_index( sub { $_->{category} eq $category && $_->{message} =~ /$regex/ }, @{ $self->msgs } ); if ( $found != -1 ) { splice( @{ $self->msgs }, $found, 1 ); $tb->ok( 1, $test_name ); } else { $tb->ok( 0, $test_name ); $tb->diag( "could not find $category message matching $regex" ); _diag_msgs(); } } sub does_not_contain_ok { my ( $self, $regex, $test_name ) = @_; local $Test::Builder::Level = $Test::Builder::Level + 1; $test_name ||= "log does not contain '$regex'"; my $found = _first_index( sub { $_->{message} =~ /$regex/ }, @{ $self->msgs } ); if ( $found != -1 ) { $tb->ok( 0, $test_name ); $tb->diag( "found message matching $regex: " . $self->msgs->[$found]->{message} ); } else { $tb->ok( 1, $test_name ); } } sub category_does_not_contain_ok { my ( $self, $category, $regex, $test_name ) = @_; local $Test::Builder::Level = $Test::Builder::Level + 1; $test_name ||= "log for $category contains '$regex'"; my $found = _first_index( sub { $_->{category} eq $category && $_->{message} =~ /$regex/ }, @{ $self->msgs } ); if ( $found != -1 ) { $tb->ok( 0, $test_name ); $tb->diag( "found $category message matching $regex: " . $self->msgs->[$found] ); } else { $tb->ok( 1, $test_name ); } } sub empty_ok { my ( $self, $test_name ) = @_; local $Test::Builder::Level = $Test::Builder::Level + 1; $test_name ||= "log is empty"; if ( !@{ $self->msgs } ) { $tb->ok( 1, $test_name ); } else { $tb->ok( 0, $test_name ); $tb->diag( "log is not empty" ); _diag_msgs(); $self->clear(); } } sub contains_only_ok { my ( $self, $regex, $test_name ) = @_; local $Test::Builder::Level = $Test::Builder::Level + 1; $test_name ||= "log contains only '$regex'"; my $count = scalar( @{ $self->msgs } ); if ( $count == 1 ) { local $Test::Builder::Level = $Test::Builder::Level + 1; $self->contains_ok( $regex, $test_name ); } else { $tb->ok( 0, $test_name ); _diag_msgs(); } } sub _diag_msgs { my $count = @msgs; if ( ! $count ) { $tb->diag("log contains no messages"); } else { $tb->diag("log contains $count message" . ( $count > 1 ? "s:" : ":")); $tb->diag(dump_one_line($_)) for @msgs; } } sub _first_index { my $f = shift; for my $i ( 0 .. $#_ ) { local *_ = \$_[$i]; return $i if $f->(); } return -1; } 1; Log-Any-1.038/lib/Log/Any/Adapter/Util.pm000644 000765 000024 00000020562 12656724173 020120 0ustar00davidstaff000000 000000 use 5.008001; use strict; use warnings; package Log::Any::Adapter::Util; # ABSTRACT: Common utility functions for Log::Any our $VERSION = '1.038'; use Exporter; our @ISA = qw/Exporter/; my %LOG_LEVELS; BEGIN { %LOG_LEVELS = ( EMERGENCY => 0, ALERT => 1, CRITICAL => 2, ERROR => 3, WARNING => 4, NOTICE => 5, INFO => 6, DEBUG => 7, TRACE => 8, ); } use constant \%LOG_LEVELS; our @EXPORT_OK = qw( cmp_deeply detection_aliases detection_methods dump_one_line log_level_aliases logging_aliases logging_and_detection_methods logging_methods make_method numeric_level read_file require_dynamic ); push @EXPORT_OK, keys %LOG_LEVELS; our %EXPORT_TAGS = ( 'levels' => [ keys %LOG_LEVELS ] ); my ( %LOG_LEVEL_ALIASES, @logging_methods, @logging_aliases, @detection_methods, @detection_aliases, @logging_and_detection_methods ); BEGIN { %LOG_LEVEL_ALIASES = ( inform => 'info', warn => 'warning', err => 'error', crit => 'critical', fatal => 'critical' ); @logging_methods = qw(trace debug info notice warning error critical alert emergency); @logging_aliases = keys(%LOG_LEVEL_ALIASES); @detection_methods = map { "is_$_" } @logging_methods; @detection_aliases = map { "is_$_" } @logging_aliases; @logging_and_detection_methods = ( @logging_methods, @detection_methods ); } #pod =func logging_methods #pod #pod Returns a list of all logging method. E.g. "trace", "info", etc. #pod #pod =cut sub logging_methods { @logging_methods } #pod =func detection_methods #pod #pod Returns a list of detection methods. E.g. "is_trace", "is_info", etc. #pod #pod =cut sub detection_methods { @detection_methods } #pod =func logging_and_detection_methods #pod #pod Returns a list of logging and detection methods (but not aliases). #pod #pod =cut sub logging_and_detection_methods { @logging_and_detection_methods } #pod =func log_level_aliases #pod #pod Returns key/value pairs mapping aliases to "official" names. E.g. "err" maps #pod to "error". #pod #pod =cut sub log_level_aliases { %LOG_LEVEL_ALIASES } #pod =func logging_aliases #pod #pod Returns a list of logging alias names. These are the keys from #pod L. #pod #pod =cut sub logging_aliases { @logging_aliases } #pod =func detection_aliases #pod #pod Returns a list of detection aliases. E.g. "is_err", "is_fatal", etc. #pod #pod =cut sub detection_aliases { @detection_aliases } #pod =func numeric_level #pod #pod Given a level name (or alias), returns the numeric value described above under #pod log level constants. E.g. "err" would return 3. #pod #pod =cut sub numeric_level { my ($level) = @_; my $canonical = exists $LOG_LEVEL_ALIASES{$level} ? $LOG_LEVEL_ALIASES{$level} : $level; return $LOG_LEVELS{ uc($canonical) }; } #pod =func dump_one_line #pod #pod Given a reference, returns a one-line L dump with keys sorted. #pod #pod =cut # lazy trampoline to load Data::Dumper only on demand but then not try to # require it pointlessly each time *dump_one_line = sub { require Data::Dumper; my $dumper = sub { my ($value) = @_; return Data::Dumper->new( [$value] )->Indent(0)->Sortkeys(1)->Quotekeys(0) ->Terse(1)->Useqq(1)->Dump(); }; my $string = $dumper->(@_); no warnings 'redefine'; *dump_one_line = $dumper; return $string; }; #pod =func make_method #pod #pod Given a method name, a code reference and a package name, installs the code #pod reference as a method in the package. #pod #pod =cut sub make_method { my ( $method, $code, $pkg ) = @_; $pkg ||= caller(); no strict 'refs'; *{ $pkg . "::$method" } = $code; } #pod =func require_dynamic (DEPRECATED) #pod #pod Given a class name, attempts to load it via require unless the class #pod already has a constructor available. Throws an error on failure. Used #pod internally and may become private in the future. #pod #pod =cut sub require_dynamic { my ($class) = @_; return 1 if $class->can('new'); # duck-type that class is loaded unless ( defined( eval "require $class; 1" ) ) { ## no critic (ProhibitStringyEval) die $@; } } #pod =func read_file (DEPRECATED) #pod #pod Slurp a file. Does *not* apply any layers. Used for testing and may #pod become private in the future. #pod #pod =cut sub read_file { my ($file) = @_; local $/ = undef; open( my $fh, '<:utf8', $file ) ## no critic or die "cannot open '$file': $!"; my $contents = <$fh>; return $contents; } #pod =func cmp_deeply (DEPRECATED) #pod #pod Compares L results for two references. Also takes a test #pod label as a third argument. Used for testing and may become private in the #pod future. #pod #pod =cut sub cmp_deeply { my ( $ref1, $ref2, $name ) = @_; my $tb = Test::Builder->new(); $tb->is_eq( dump_one_line($ref1), dump_one_line($ref2), $name ); } # 0.XX version loaded Log::Any and some adapters relied on this happening # behind the scenes. Since Log::Any now uses this module, we load Log::Any # via require after compilation to mitigate circularity. require Log::Any; 1; # vim: ts=4 sts=4 sw=4 et tw=75: __END__ =pod =encoding UTF-8 =head1 NAME Log::Any::Adapter::Util - Common utility functions for Log::Any =head1 VERSION version 1.038 =head1 DESCRIPTION This module has utility functions to help develop L subclasses or L formatters/filters. It also has some functions used in internal testing. =head1 USAGE Nothing is exported by default. =head2 Log level constants If the C<:levels> tag is included in the import list, the following numeric constants will be imported: EMERGENCY => 0 ALERT => 1 CRITICAL => 2 ERROR => 3 WARNING => 4 NOTICE => 5 INFO => 6 DEBUG => 7 TRACE => 8 =head1 NAME Log::Any::Adapter::Util - Common utility functions for Log::Any =head1 VERSION version 1.038 =head1 FUNCTIONS =head2 logging_methods Returns a list of all logging method. E.g. "trace", "info", etc. =head2 detection_methods Returns a list of detection methods. E.g. "is_trace", "is_info", etc. =head2 logging_and_detection_methods Returns a list of logging and detection methods (but not aliases). =head2 log_level_aliases Returns key/value pairs mapping aliases to "official" names. E.g. "err" maps to "error". =head2 logging_aliases Returns a list of logging alias names. These are the keys from L. =head2 detection_aliases Returns a list of detection aliases. E.g. "is_err", "is_fatal", etc. =head2 numeric_level Given a level name (or alias), returns the numeric value described above under log level constants. E.g. "err" would return 3. =head2 dump_one_line Given a reference, returns a one-line L dump with keys sorted. =head2 make_method Given a method name, a code reference and a package name, installs the code reference as a method in the package. =head2 require_dynamic (DEPRECATED) Given a class name, attempts to load it via require unless the class already has a constructor available. Throws an error on failure. Used internally and may become private in the future. =head2 read_file (DEPRECATED) Slurp a file. Does *not* apply any layers. Used for testing and may become private in the future. =head2 cmp_deeply (DEPRECATED) Compares L results for two references. Also takes a test label as a third argument. Used for testing and may become private in the future. =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 AUTHORS =over 4 =item * Jonathan Swartz =item * David Golden =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Jonathan Swartz and David Golden. 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