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