pax_global_header00006660000000000000000000000064143031520070014505gustar00rootroot0000000000000052 comment=f76c0045051411c1e7202624c5410749bdb95852 lwt_log-1.1.2/000077500000000000000000000000001430315200700131555ustar00rootroot00000000000000lwt_log-1.1.2/.gitignore000066400000000000000000000000521430315200700151420ustar00rootroot00000000000000_build/ .merlin *.install _opam/ scratch/ lwt_log-1.1.2/.travis.yml000066400000000000000000000015221430315200700152660ustar00rootroot00000000000000sudo: required language: generic env: - COMPILER=4.10.0 - COMPILER=4.09.0 - COMPILER=4.08.1 - COMPILER=4.07.1 - COMPILER=4.06.1 - COMPILER=4.05.0 - COMPILER=4.04.2 - COMPILER=4.03.0 - COMPILER=4.02.3 before_install: - '[ "$TRAVIS_EVENT_TYPE" != cron ] || rm -rf ~/.opam' install: - wget https://github.com/ocaml/opam/releases/download/2.0.6/opam-2.0.6-x86_64-linux - sudo mv opam-2.0.6-x86_64-linux /usr/local/bin/opam - sudo chmod a+x /usr/local/bin/opam - opam init -ya --compiler=$COMPILER --disable-sandboxing --disable-shell-hook - eval `opam config env` - opam --version - ocaml -version - opam install --yes --deps-only . script: - dune build - opam lint before_cache: - opam clean cache: directories: - $HOME/.opam notifications: email: on_success: always on_failure: always lwt_log-1.1.2/CHANGES000066400000000000000000000043301430315200700141500ustar00rootroot00000000000000===== 1.1.1 (2019-07-30) ===== * Upgrade from Jbuilder to Dune (#3, Rudi Grinberg). * Update license headers (#2, Ben Rosser). ===== 1.1.0 (2018-03-30) ===== * Initial release packaged separately from Lwt. ===== Lwt 3.2.0 (2017-12-19) ===== ====== Planned to break in Lwt 4.0.0 ====== See #453 for details and instructions about planned breakage in Lwt 4.0.0. * Modules Lwt_log, Lwt_log_core, Lwt_log_rules, and Lwt_daemon are being deprecated and factored out into opam package lwt_log, also installable from opam now. Use the logs library for logging, in particular module Logs_lwt. Direct daemonization is deprecated on most platforms (#484, Hannes Mehnert). ===== Lwt 3.1.0 (2017-07-19) ===== ====== Fixes ====== * Make Lwt_log functions tail-recursive (#348, Jan Doms). ===== Lwt 2.7.0 (2017-01-03) ===== ====== Additions ====== * ?fail_on_error argument for Lwt_log.load_rules (#306, Daniil Baturin). * Lwt_log.level_of_string (#306, Daniil Baturin). ===== Lwt 2.6.0 (2016-10-27) ===== ====== Bugfixes ====== * Update log sections after Lwt_log.load_rules (#188, reported @rand00). * Print three digits for milliseconds in Lwt_log (#264, Fabian Hemmer). ===== Lwt 2.5.1 (2015-12-07) ===== * Lwt_log: add OSX syslog path ===== Lwt 2.4.8 (2015-03-11) ===== * Add Lwt_log_core.reset_rules (#123) ===== Lwt 2.4.5 (2014-04-21) ===== * Lwt_log: get backtrace early to overcome exns in Printexc.to_string * do not raise an exception in Lwt_log if argv[0] is blank ===== Lwt 2.4.4 (2013-10-22) ===== * add Lwt.log containing Lwt_log_core, the Unix-free part of Lwt_log * fix stdout/stderr redirections in Lwt_daemon.daemonize ===== Lwt 2.3.2 (2011-11-04) ===== * Add location informations in logs: ** allow loggers to get the current location through local storage ** pass current location to logging functions ** pass the current location with the syntax extension ===== Lwt 2.3.0 (2011-04-12) ===== * Allow to configure logging rules at runtime in Lwt_log ===== Lwt 2.1.1 (2010-06-13) ===== * Use {{{set_close_on_exec}}} for fds created by {{{Lwt_log}}} ===== Lwt 2.1.0 (2010-04-19) ===== * Adding module {{{Lwt_log}}} for logging * Adding module {{{Lwt_daemon}}} lwt_log-1.1.2/COPYING000066400000000000000000000706241430315200700142210ustar00rootroot00000000000000This program is released under the LGPL version 2.1 (see the text below) with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. As a special exception to the GNU Library General Public License, you may also link, statically or dynamically, a "work that uses the Library" with a publicly distributed version of the Library to produce an executable file containing portions of the Library, and distribute that executable file under terms of your choice, without any of the additional requirements listed in clause 6 of the GNU Library General Public License. By "a publicly distributed version of the Library", we mean either the unmodified Library, or a modified version of the Library that is distributed under the conditions defined in clause 3 of the GNU Library General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU Library General Public License. Some parts, when stated (as licenced under BSD3) are licenced under 3-clauses or Modified BSD License. GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 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. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete 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 License and to the absence of any warranty; and distribute a copy of this License along with the Library. 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. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser 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 Library specifies a version number of this 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 Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, 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 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "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 LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. 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 LIBRARY 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 LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. 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) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! ====== BSD3 or Modified BSD License ====== Copyright (c) , All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. lwt_log-1.1.2/Makefile000066400000000000000000000001071430315200700146130ustar00rootroot00000000000000.PHONY : build build : dune build .PHONY : clean clean : dune clean lwt_log-1.1.2/README.md000066400000000000000000000013201430315200700144300ustar00rootroot00000000000000# Lwt_log: Lwt-friendly logging library (deprecated) This library is deprecated in favor of the [`Logs_lwt`][logs_lwt] module of [logs][logs]. See [`lwt_log_core.mli`][mli] for documentation. To install, `opam install lwt_log`. The library is split into two ocamlfind packages. The "basic" `lwt_log` includes Unix log destination support, such as files and syslog, and `Lwt_daemon`. `lwt_log.core` is the pure-OCaml part of `lwt_log`, suitable for targeting JavaScript in the browser, or elsewhere where Unix is not available. [logs_lwt]: http://erratique.ch/software/logs/doc/Logs_lwt.html [logs]: http://erratique.ch/software/logs [mli]: https://github.com/aantron/lwt_log/blob/master/src/core/lwt_log_core.mli lwt_log-1.1.2/dune-project000066400000000000000000000000371430315200700154770ustar00rootroot00000000000000(lang dune 1.0) (name lwt_log) lwt_log-1.1.2/lwt_log.opam000066400000000000000000000010701430315200700155000ustar00rootroot00000000000000opam-version: "2.0" synopsis: "Lwt logging library (deprecated)" version: "dev" license: "LGPL" homepage: "https://github.com/ocsigen/lwt_log" doc: "https://github.com/ocsigen/lwt_log/blob/master/src/core/lwt_log_core.mli" bug-reports: "https://github.com/ocsigen/lwt_log/issues" authors: [ "Shawn Wagner" "Jérémie Dimino" ] maintainer: "Anton Bachin " dev-repo: "git+https://github.com/ocsigen/lwt_log.git" depends: [ "dune" {>= "1.0"} "lwt" {>= "4.0.0"} "ocaml" {>= "4.03"} ] build: [ ["dune" "build" "-p" name "-j" jobs] ] lwt_log-1.1.2/src/000077500000000000000000000000001430315200700137445ustar00rootroot00000000000000lwt_log-1.1.2/src/core/000077500000000000000000000000001430315200700146745ustar00rootroot00000000000000lwt_log-1.1.2/src/core/dune000066400000000000000000000003131430315200700155470ustar00rootroot00000000000000(ocamllex lwt_log_rules) (library (name lwt_log_core) (public_name lwt_log.core) (synopsis "Logger for Lwt (deprecated; pure-OCaml core)") (wrapped false) (libraries lwt) (flags :standard -w +A)) lwt_log-1.1.2/src/core/lwt_log_core.ml000066400000000000000000000311351430315200700177100ustar00rootroot00000000000000(* OCaml promise library * http://www.ocsigen.org/lwt * Copyright (C) 2002 Shawn Wagner * 2009 Jérémie Dimino * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, with linking exceptions; * either version 2.1 of the License, or (at your option) any later * version. See COPYING file for details. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. *) (* This code is an adaptation of [syslog-ocaml] *) (* Errors happening in this module are always logged to [stderr]: *) let log_intern fmt = Printf.eprintf ("Lwt_log: " ^^ fmt ^^ "\n%!") (* +-----------------------------------------------------------------+ | Log levels | +-----------------------------------------------------------------+ *) type level = | Debug | Info | Notice | Warning | Error | Fatal let string_of_level = function | Debug -> "debug" | Info -> "info" | Notice -> "notice" | Warning -> "warning" | Error -> "error" | Fatal -> "fatal" let level_of_string str = let str = String.lowercase_ascii str in match str with | "debug" -> Some Debug | "info" -> Some Info | "notice" -> Some Notice | "warning" -> Some Warning | "error" -> Some Error | "fatal" -> Some Fatal | _ -> None (* +-----------------------------------------------------------------+ | Patterns and rules | +-----------------------------------------------------------------+ *) (* A pattern is represented by a list of literals: For example ["foo*bar*"] is represented by ["foo"; "bar"; ""]. *) let sub_equal str ofs patt = let str_len = String.length str and patt_len = String.length patt in let rec loop ofs ofs_patt = ofs_patt = patt_len || (str.[ofs] = patt.[ofs_patt] && loop (ofs + 1) (ofs_patt + 1)) in ofs + patt_len <= str_len && loop ofs 0 let pattern_match pattern string = let length = String.length string in let rec loop offset pattern = if offset = length then pattern = [] || pattern = [""] else match pattern with | [] -> false | literal :: pattern -> let literal_length = String.length literal in let max_offset = length - literal_length in let rec search offset = offset <= max_offset && ((sub_equal string offset literal && loop (offset + literal_length) pattern) || search (offset + 1)) in search offset in match pattern with | [] -> string = "" | literal :: pattern -> sub_equal string 0 literal && loop (String.length literal) pattern let split pattern = let len = String.length pattern in let rec loop ofs = if ofs = len then [""] else match try Some(String.index_from pattern ofs '*') with Not_found -> None with | Some ofs' -> String.sub pattern ofs (ofs' - ofs) :: loop (ofs' + 1) | None -> [String.sub pattern ofs (len - ofs)] in loop 0 let rules = ref [] let load_rules' str fail_on_error = let rec loop = function | [] -> [] | (pattern, level_str) :: rest -> let pattern = split pattern in let level = level_of_string level_str in match level with | Some level -> (pattern, level) :: loop rest | None -> if fail_on_error then raise (Failure "Invalid log rules") else log_intern "invalid log level (%s)" level_str; loop rest in match Lwt_log_rules.rules (Lexing.from_string str) with | None -> if fail_on_error then raise (Failure "Invalid log rules") else Printf.eprintf "Invalid log rules\n%!" | Some l -> rules := loop l let _ = match try Some(Sys.getenv "LWT_LOG") with Not_found -> None with | Some str -> load_rules' str false | None -> () (* +-----------------------------------------------------------------+ | Sections | +-----------------------------------------------------------------+ *) module Section = struct type t = { name : string; mutable level : level; mutable modified : bool; } type section = t module Sections = Weak.Make(struct type t = section let equal a b = a.name = b.name let hash s = Hashtbl.hash s.name end) let sections = Sections.create 32 let find_level name = let rec loop = function | [] -> Notice | (pattern, level) :: rest -> if pattern_match pattern name then level else loop rest in loop !rules let recompute_levels () = Sections.iter (fun section -> if not section.modified then section.level <- find_level section.name) sections let make name = let section = { name = name; level = Notice; modified = false } in try Sections.find sections section with Not_found -> section.level <- find_level name; Sections.add sections section; section let name section = section.name let main = make "main" let level section = section.level let set_level section level = section.level <- level; section.modified <- true let reset_level section = if section.modified then begin section.modified <- false; section.level <- find_level section.name end end type section = Section.t let load_rules ?(fail_on_error=false) str = load_rules' str fail_on_error; Section.recompute_levels () let add_rule pattern level = rules := (split pattern, level) :: !rules; Section.recompute_levels () let append_rule pattern level = rules := !rules @ [(split pattern, level)]; Section.recompute_levels () let reset_rules () = rules := []; Section.recompute_levels () (* +-----------------------------------------------------------------+ | Loggers | +-----------------------------------------------------------------+ *) exception Logger_closed type logger = { mutable lg_closed : bool; lg_output : section -> level -> string list -> unit Lwt.t; lg_close : unit Lwt.t Lazy.t; } let close logger = logger.lg_closed <- true; Lazy.force logger.lg_close let make ~output ~close = { lg_closed = false; lg_output = output; lg_close = Lazy.from_fun close; } let broadcast loggers = make ~output:(fun section level lines -> Lwt_list.iter_p (fun logger -> logger.lg_output section level lines) loggers) ~close:Lwt.return let dispatch f = make ~output:(fun section level lines -> (f section level).lg_output section level lines) ~close:Lwt.return (* +-----------------------------------------------------------------+ | Templates | +-----------------------------------------------------------------+ *) type template = string let location_key = Lwt.new_key () let render ~buffer ~template ~section ~level ~message = let file, line, column = match Lwt.get location_key with | Some loc -> loc | None -> ("", -1, -1) in Buffer.add_substitute buffer (function | "message" -> message | "level" -> string_of_level level | "section" -> Section.name section | "loc-file" -> file | "loc-line" -> string_of_int line | "loc-column" -> string_of_int column | var -> Printf.ksprintf invalid_arg "Lwt_log_core.render: unknown variable %S" var) template (* +-----------------------------------------------------------------+ | Predefined loggers | +-----------------------------------------------------------------+ *) let null = make ~output:(fun _section _level _lines -> Lwt.return_unit) ~close:Lwt.return let default = ref null (* +-----------------------------------------------------------------+ | Logging functions | +-----------------------------------------------------------------+ *) (* knicked from stdlib/string.ml; available since 4.04.0 *) let split_on_char sep s = let r = ref [] in let j = ref (String.length s) in for i = String.length s - 1 downto 0 do if String.unsafe_get s i = sep then begin r := String.sub s (i + 1) (!j - i - 1) :: !r; j := i end done; String.sub s 0 !j :: !r let split str = split_on_char '\n' str let log ?exn ?(section=Section.main) ?location ?logger ~level message = let logger = match logger with | None -> !default | Some logger -> logger in if logger.lg_closed then Lwt.fail Logger_closed else if level >= section.Section.level then match exn with | None -> Lwt.with_value location_key location (fun () -> logger.lg_output section level (split message)) | Some exn -> let bt = if Printexc.backtrace_status () then Printexc.get_backtrace () else "" in let message = message ^ ": " ^ Printexc.to_string exn in let message = if String.length bt = 0 then message else message ^ "\nbacktrace:\n" ^ bt in Lwt.with_value location_key location (fun () -> logger.lg_output section level (split message)) else Lwt.return_unit let log_f ?exn ?section ?location ?logger ~level format = Printf.ksprintf (log ?exn ?section ?location ?logger ~level) format let ign_log ?exn ?section ?location ?logger ~level message = try ignore (log ?exn ?section ?location ?logger ~level message) with _ -> () let ign_log_f ?exn ?section ?location ?logger ~level format = Printf.ksprintf (ign_log ?exn ?section ?location ?logger ~level) format let debug ?exn ?section ?location ?logger msg = log ?exn ?section ?location ?logger ~level:Debug msg let debug_f ?exn ?section ?location ?logger fmt = Printf.ksprintf (debug ?exn ?section ?location ?logger) fmt let info ?exn ?section ?location ?logger msg = log ?exn ?section ?location ?logger ~level:Info msg let info_f ?exn ?section ?location ?logger fmt = Printf.ksprintf (info ?exn ?section ?location ?logger) fmt let notice ?exn ?section ?location ?logger msg = log ?exn ?section ?location ?logger ~level:Notice msg let notice_f ?exn ?section ?location ?logger fmt = Printf.ksprintf (notice ?exn ?section ?location ?logger) fmt let warning ?exn ?section ?location ?logger msg = log ?exn ?section ?location ?logger ~level:Warning msg let warning_f ?exn ?section ?location ?logger fmt = Printf.ksprintf (warning ?exn ?section ?location ?logger) fmt let error ?exn ?section ?location ?logger msg = log ?exn ?section ?location ?logger ~level:Error msg let error_f ?exn ?section ?location ?logger fmt = Printf.ksprintf (error ?exn ?section ?location ?logger) fmt let fatal ?exn ?section ?location ?logger msg = log ?exn ?section ?location ?logger ~level:Fatal msg let fatal_f ?exn ?section ?location ?logger fmt = Printf.ksprintf (fatal ?exn ?section ?location ?logger) fmt let ign_debug ?exn ?section ?location ?logger msg = ign_log ?exn ?section ?location ?logger ~level:Debug msg let ign_debug_f ?exn ?section ?location ?logger fmt = Printf.ksprintf (ign_debug ?exn ?section ?location ?logger) fmt let ign_info ?exn ?section ?location ?logger msg = ign_log ?exn ?section ?location ?logger ~level:Info msg let ign_info_f ?exn ?section ?location ?logger fmt = Printf.ksprintf (ign_info ?exn ?section ?location ?logger) fmt let ign_notice ?exn ?section ?location ?logger msg = ign_log ?exn ?section ?location ?logger ~level:Notice msg let ign_notice_f ?exn ?section ?location ?logger fmt = Printf.ksprintf (ign_notice ?exn ?section ?location ?logger) fmt let ign_warning ?exn ?section ?location ?logger msg = ign_log ?exn ?section ?location ?logger ~level:Warning msg let ign_warning_f ?exn ?section ?location ?logger fmt = Printf.ksprintf (ign_warning ?exn ?section ?location ?logger) fmt let ign_error ?exn ?section ?location ?logger msg = ign_log ?exn ?section ?location ?logger ~level:Error msg let ign_error_f ?exn ?section ?location ?logger fmt = Printf.ksprintf (ign_error ?exn ?section ?location ?logger) fmt let ign_fatal ?exn ?section ?location ?logger msg = ign_log ?exn ?section ?location ?logger ~level:Fatal msg let ign_fatal_f ?exn ?section ?location ?logger fmt = Printf.ksprintf (ign_fatal ?exn ?section ?location ?logger) fmt lwt_log-1.1.2/src/core/lwt_log_core.mli000066400000000000000000000324441430315200700200650ustar00rootroot00000000000000(* OCaml promise library * http://www.ocsigen.org/lwt * Copyright (C) 2002 Shawn Wagner * 2009 Jérémie Dimino * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, with linking exceptions; * either version 2.1 of the License, or (at your option) any later * version. See COPYING file for details. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser 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. *) (** Logging facility *) (** This module provides functions to deal with logging. It support: - logging to multiple destination at the same time - filtering logs per destination *) (** {2 Types} *) (** Type of log levels. A level determines the importance of a message *) type level = | Debug (** Debugging message. They can be automatically removed by the syntax extension. *) | Info (** Informational message. Suitable to be displayed when the program is in verbose mode. *) | Notice (** Same as {!Info}, but is displayed by default. *) | Warning (** Something strange happend *) | Error (** An error message, which should not means the end of the program. *) | Fatal (** A fatal error happened, in most cases the program will end after a fatal error. *) type logger (** Type of a logger. A logger is responsible for dispatching messages and storing them somewhere. *) type section (** Each logging message has a section. Sections can be used to structure your logs. For example you can choose different loggers according to the section. Each section carries a level, and messages with a lower log level than than the section level will be dropped. Section levels are initialised using the contents of the [LWT_LOG] environment variable, which must contain one or more rules of the form [pattern -> level] separated by ";". Where [pattern] is a string that may contain [*]. For example, if [LWT_LOG] contains: {[ access -> warning; foo[*] -> error ]} then the level of the section ["access"] is {!Warning} and the level of any section matching ["foo[*]"] is {!Error}. If the pattern is omited in a rule then the pattern ["*"] is used instead, so [LWT_LOG] may just contain ["debug"] for instance. By default, the following rule apply : ["* -> notice"] *) val string_of_level : level -> string val level_of_string : string -> level option val load_rules : ?fail_on_error:bool -> string -> unit (** Reset the rules set when parsing the [LWT_LOG] environment variable using this string. @param fail_on_error defines if the function will raise Failure if it encounters a malformed rule @raise Failure if an invalid rule is found and [fail_on_error] is true [load_rules] parses the rules string and validates the rules before loading them. If [fail_on_error] is [true], invalid rules will cause this function to raise [Failure] and leave existing rules unchanged. If [fail_on_error] is [false] (this is the default), it tries to load as many rules as possible and ignore invalid ones. If the rules string itself cannot be parsed, existing rules are always left unchanged. Example: {[ Lwt_log_core.load_rules ~fail_on_error:true "* -> nosuchlevel" (* Raises Failure *) Lwt_log_core.load_rules "* -> info" ]} *) val add_rule : string -> level -> unit (** [add_rule pattern level] adds a rule for sections logging levels. The rule is added before all other rules. It takes effect immediately and affects all sections for which the level has not been set explicitly with {!Section.set_level}. [pattern] may contains [*]. For example: {[ Lwt_log_core.add_rule "lwt*" Lwt_log_core.Info ]} *) val append_rule : string -> level -> unit (** [append_rule pattern level] adds the given rule after all other rules. For example to set the default fallback rule: {[ Lwt_log_core.append_rule "*" Lwt_log_core.Info ]} *) val reset_rules : unit -> unit (** removes all rules. *) (** {2 Logging functions} *) val log : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> level : level -> string -> unit Lwt.t (** [log ?section ?logger ~level message] logs a message. [section] defaults to {!Section.main}. If [logger] is not specified, then the default one is used instead (see {!default}). If [exn] is provided, then its string representation (= [Printexc.to_string exn]) will be append to the message, and if possible the backtrace will also be logged. [location] contains the location of the logging directive, it is of the form [(file_name, line, column)]. *) val log_f : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> level : level -> ('a, unit, string, unit Lwt.t) format4 -> 'a (** [log_f] is the same as [log] except that it takes a format string *) val ign_log : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> level : level -> string -> unit (** Same as {!log} but ignore the resulting thread. *) val ign_log_f : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> level : level -> ('a, unit, string, unit) format4 -> 'a (** Same as {!log_f} but ignore the resulting thread. *) (** The following functions are the same as {!log} except that their name determines which level is used. For example {!info}[ msg] is the same as {!log}[ ~level:Info msg]. *) val debug : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit Lwt.t val debug_f : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit Lwt.t) format4 -> 'a val ign_debug : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit val ign_debug_f : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit) format4 -> 'a val info : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit Lwt.t val info_f : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit Lwt.t) format4 -> 'a val ign_info : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit val ign_info_f : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit) format4 -> 'a val notice : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit Lwt.t val notice_f : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit Lwt.t) format4 -> 'a val ign_notice : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit val ign_notice_f : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit) format4 -> 'a val warning : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit Lwt.t val warning_f : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit Lwt.t) format4 -> 'a val ign_warning : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit val ign_warning_f : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit) format4 -> 'a val error : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit Lwt.t val error_f : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit Lwt.t) format4 -> 'a val ign_error : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit val ign_error_f : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit) format4 -> 'a val fatal : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit Lwt.t val fatal_f : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit Lwt.t) format4 -> 'a val ign_fatal : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit val ign_fatal_f : ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit) format4 -> 'a (** Sections *) module Section : sig type t = section val make : string -> section (** [make name] creates a section with the given name. Two calls to {!make} with the same name will return the same section object. *) val name : section -> string (** [name section] returns the name of [section]. *) val main : section (** The main section. It is the section used by default when no one is provided. *) val level : section -> level (** [level section] returns the logging level of [section]. *) val set_level : section -> level -> unit (** [set_level section] sets the logging level of the given section. Modifications of rules using {!add_rule} won't affect the level of this section after this operation. *) val reset_level : section -> unit (** [reset_level section] resets the level of [section] to its default value, i.e. to the value obtained by applying rules. *) end (** {2 Log templates} *) type template = string (** A template is for generating log messages. It is a string which may contains variables of the form [$(var)], where [var] is one of: - [message] which will be replaced by the message emited - [level] which will be replaced by a string representation of the level - [section] which will be replaced by the name of the message's section - [loc-file] which will be replaced by the file name of the calling logging function - [loc-line] which will be replaced by the line number of the calling logging function - [loc-column] which will be replaced by the column number of the calling logging function For example: - ["$(name): $(message)"] - ["$(name): $(loc-file): $(loc-line): $(loc-column): $(message)"] *) val render : buffer : Buffer.t -> template : template -> section : section -> level : level -> message : string -> unit (** [render ~buffer ~template ~section ~level ~message] instantiate all variables of [template], and store the result in [buffer]. The location is obtained from threads local storage. *) val location_key : (string * int * int) Lwt.key (** The key for storing current location. *) (** {2 Loggers} *) exception Logger_closed (** Exception raised when trying to use a closed logger *) val make : output : (section -> level -> string list -> unit Lwt.t) -> close : (unit -> unit Lwt.t) -> logger (** [make ~output ~close] creates a new logger. @param output is used to write logs. It is a function which receive a section, a level and a list lines that must be logged together. @param close is used to close the logger. *) val close : logger -> unit Lwt.t (** Close the given logger *) val default : logger ref (** The default logger. It is used as default when no one is specified. If {!Lwt_core} is linked (in the package [lwt.unix]) the default logger sends all messages to standard error. Otherwise the default logger is {!null}. *) val broadcast : logger list -> logger (** [broadcast loggers] is a logger which send messages to all the given loggers. Note: closing a broadcast logger does not close its components. *) val dispatch : (section -> level -> logger) -> logger (** [dispatch f] is a logger which dispatch logging instructions to different logger according to their level and/or section. Here is an example: {[ let access_logger = Lwt_log.file "access.log" and error_logger = Lwt_log.file "error.log" in Lwt_log_core.dispatch (fun section level -> match Lwt_log_core.Section.name section, level with | "access", _ -> access_logger | _, Lwt_log_core.Error -> error_logger) ]} *) (** {2 Predefined loggers} *) val null : logger (** Logger which drops everything *) lwt_log-1.1.2/src/core/lwt_log_rules.mli000066400000000000000000000021411430315200700202560ustar00rootroot00000000000000(* OCaml promise library * http://www.ocsigen.org/lwt * Copyright (C) 2010 Jérémie Dimino * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, with linking exceptions; * either version 2.1 of the License, or (at your option) any later * version. See COPYING file for details. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser 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. *) (** Logging rules parsing *) val rules : Lexing.lexbuf -> (string * string) list option (** [parse lexbuf] returns the list of rules contained in [lexbuf] or None in case of parsing error *) lwt_log-1.1.2/src/core/lwt_log_rules.mll000066400000000000000000000027741430315200700202750ustar00rootroot00000000000000(* OCaml promise library * http://www.ocsigen.org/lwt * Copyright (C) 2010 Jérémie Dimino * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, with linking exceptions; * either version 2.1 of the License, or (at your option) any later * version. See COPYING file for details. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. *) {exception Parse_error} let space = [' ' '\t' '\n'] let pattern = [^ ' ' '\t' '\n']+ let level = ['a'-'z' 'A'-'Z']+ rule rules = parse | space* (pattern as pattern) space* "->" space* (level as level) { (pattern, level) :: semi_colon_and_rules lexbuf } | space* (level as level) { ("*", level) :: semi_colon_and_rules lexbuf } | space* eof { [] } | "" { raise Parse_error } and semi_colon_and_rules = parse | space* ";" { rules lexbuf } | space* eof { [] } | "" { raise Parse_error } { let rules buf = try Some (rules buf) with Parse_error -> None } lwt_log-1.1.2/src/unix/000077500000000000000000000000001430315200700147275ustar00rootroot00000000000000lwt_log-1.1.2/src/unix/dune000066400000000000000000000003171430315200700156060ustar00rootroot00000000000000(library (name lwt_log) (public_name lwt_log) (synopsis "Logger for Lwt (deprecated; use logs library)") (optional) (wrapped false) (libraries unix lwt lwt.unix lwt_log.core) (flags :standard -w +A)) lwt_log-1.1.2/src/unix/lwt_daemon.ml000066400000000000000000000055751430315200700174260ustar00rootroot00000000000000(* OCaml promise library * http://www.ocsigen.org/lwt * Copyright (C) 2009 Jérémie Dimino * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, with linking exceptions; * either version 2.1 of the License, or (at your option) any later * version. See COPYING file for details. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. *) (* [Lwt_sequence] is deprecated – we don't want users outside Lwt using it. However, it is still used internally by Lwt. So, briefly disable warning 3 ("deprecated"), and create a local, non-deprecated alias for [Lwt_sequence] that can be referred to by the rest of the code in this module without triggering any more warnings. *) [@@@ocaml.warning "-3"] module Lwt_sequence = Lwt_sequence [@@@ocaml.warning "+3"] open Lwt.Infix let rec copy ic logger = Lwt_io.read_line ic >>= fun line -> Lwt_log.log ?logger ~level:Lwt_log.Notice line >>= fun () -> copy ic logger let redirect fd logger = let fd_r, fd_w = Unix.pipe () in Unix.set_close_on_exec fd_r; Unix.dup2 fd_w fd; Unix.close fd_w; let ic = Lwt_io.of_unix_fd ~mode:Lwt_io.input fd_r in Lwt.ignore_result (copy ic logger) let redirect_output dev_null fd mode = match mode with | `Dev_null -> Unix.dup2 dev_null fd | `Close -> Unix.close fd | `Keep -> () | `Log_default -> redirect fd None | `Log logger -> redirect fd (Some logger) let daemonize ?(syslog=true) ?(stdin=`Dev_null) ?(stdout=`Log_default) ?(stderr=`Log_default) ?(directory="/") ?(umask=`Set 0o022) () = Unix.chdir directory; (* Exit the parent, and continue in the child: *) if Lwt_unix.fork () > 0 then begin (* Do not run exit hooks in the parent. *) Lwt_sequence.iter_node_l Lwt_sequence.remove Lwt_main.exit_hooks [@ocaml.warning "-3"]; exit 0 end; if syslog then Lwt_log.default := Lwt_log.syslog ~facility:`Daemon (); (* Redirection of standard IOs *) let dev_null = Unix.openfile "/dev/null" [Unix.O_RDWR] 0o666 in begin match stdin with | `Dev_null -> Unix.dup2 dev_null Unix.stdin | `Close -> Unix.close Unix.stdin | `Keep -> () end; redirect_output dev_null Unix.stdout stdout; redirect_output dev_null Unix.stderr stderr; Unix.close dev_null; begin match umask with | `Keep -> () | `Set n -> ignore (Unix.umask n); end; ignore (Unix.setsid ()) lwt_log-1.1.2/src/unix/lwt_daemon.mli000066400000000000000000000060611430315200700175660ustar00rootroot00000000000000(* OCaml promise library * http://www.ocsigen.org/lwt * Copyright (C) 2009 Jérémie Dimino * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, with linking exceptions; * either version 2.1 of the License, or (at your option) any later * version. See COPYING file for details. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser 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. *) (** Daemon helpers *) val daemonize : ?syslog : bool -> ?stdin : [ `Dev_null | `Close | `Keep ] -> ?stdout : [ `Dev_null | `Close | `Keep | `Log_default | `Log of Lwt_log.logger ] -> ?stderr : [ `Dev_null | `Close | `Keep | `Log_default | `Log of Lwt_log.logger ] -> ?directory : string -> ?umask : [ `Keep | `Set of int ] -> unit -> unit (** Put the current running process into daemon mode. I.e. it forks and exit the parent, detach it from its controlling terminal, and redict standard intputs/outputs.. Notes: - you must be sure that there is no pending threads when calling this function, otherwise they may be canceled. If [syslog] is [true] (the default), then {!Lwt_log.default} is set to [Lwt_log.syslog ~facility:`Daemon ()], otherwise it is kept unchanged. [stdin] is one of: - [`Dev_null] which means that [Unix.stdin] is reopened as [/dev/null], this is the default behavior - [`Close] means that [Unix.stdin] is simply closed - [`Keep] means that [Unix.stdin] is left unchanged [stdout] and [stderr] control how the two associated file descriptors are redirected: - [`Dev_null] means that the output is redirected to [/dev/null] - [`Close] means that the file descriptor is closed - [`Keep] means that it is left unchanged - [`Log logger] means that the output is redirected to this logger - [`Log_default] means that the output is redirected to the default logger Both [stdout] and [stderr] default to [`Log_default]. Warning: do not redirect an output to a logger logging into this output. For example, this code will create an infinite loop: {[ let logger = Lwt_log.channel ~close_mode:`Keep ~channel:Lwt_io.stderr () in Lwt_daemon.daemonize ~syslog:false ~stderr:(`Log logger) (); prerr_endline "foo" ]} The current working directory is set to [directory], which defaults to ["/"]. [umask] may be one of: - [`Keep] which means that the umask is left unchanged - [`Set n] which means that the umask is set to [n] It defaults to [`Set 0o022]. *) lwt_log-1.1.2/src/unix/lwt_log.ml000066400000000000000000000240741430315200700167370ustar00rootroot00000000000000(* OCaml promise library * http://www.ocsigen.org/lwt * Copyright (C) 2002 Shawn Wagner * 2009 Jérémie Dimino * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, with linking exceptions; * either version 2.1 of the License, or (at your option) any later * version. See COPYING file for details. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. *) (* This code is an adaptation of [syslog-ocaml] *) include Lwt_log_core open Lwt.Infix let program_name = Filename.basename Sys.executable_name (* Errors happening in this module are always logged to [stderr]: *) let log_intern fmt = Printf.eprintf ("%s: Lwt_log: " ^^ fmt ^^ "\n%!") program_name (* +-----------------------------------------------------------------+ | Templates | +-----------------------------------------------------------------+ *) let date_string time = let tm = Unix.localtime time in let month_string = match tm.Unix.tm_mon with | 0 -> "Jan" | 1 -> "Feb" | 2 -> "Mar" | 3 -> "Apr" | 4 -> "May" | 5 -> "Jun" | 6 -> "Jul" | 7 -> "Aug" | 8 -> "Sep" | 9 -> "Oct" | 10 -> "Nov" | 11 -> "Dec" | _ -> Printf.ksprintf failwith "Lwt_log.date_string: invalid month, %d" tm.Unix.tm_mon in Printf.sprintf "%s %2d %02d:%02d:%02d" month_string tm.Unix.tm_mday tm.Unix.tm_hour tm.Unix.tm_min tm.Unix.tm_sec let render ~buffer ~template ~section ~level ~message = let time = lazy(Unix.gettimeofday ()) in let file, line, column = match Lwt.get location_key with | Some loc -> loc | None -> ("", -1, -1) in Buffer.add_substitute buffer (function | "date" -> date_string (Lazy.force time) | "milliseconds" -> Printf.sprintf "%03.0f" (mod_float (Lazy.force time *. 1000.) 1000.) | "name" -> program_name | "pid" -> string_of_int (Unix.getpid ()) | "message" -> message | "level" -> Lwt_log_core.string_of_level level | "section" -> Section.name section | "loc-file" -> file | "loc-line" -> string_of_int line | "loc-column" -> string_of_int column | var -> Printf.ksprintf invalid_arg "Lwt_log.render: unknown variable %S" var) template (* +-----------------------------------------------------------------+ | Predefined loggers | +-----------------------------------------------------------------+ *) let channel ?(template="$(name): $(section): $(message)") ~close_mode ~channel () = make ~output:(fun section level lines -> Lwt_io.atomic begin fun oc -> let buf = Buffer.create 42 in Lwt_list.iter_s (fun line -> Buffer.clear buf; render ~buffer:buf ~template ~section ~level ~message:line; Buffer.add_char buf '\n'; Lwt_io.write oc (Buffer.contents buf)) lines >>= fun () -> Lwt_io.flush oc end channel) ~close:(match close_mode with | `Keep -> Lwt.return | `Close -> (fun () -> Lwt_io.close channel)) let _ = Lwt_log_core.default := channel ~close_mode:`Keep ~channel:Lwt_io.stderr () let file ?(template="$(date): $(section): $(message)") ?(mode=`Append) ?(perm=0o640) ~file_name () = let flags = match mode with | `Append -> [Unix.O_WRONLY; Unix.O_CREAT; Unix.O_APPEND; Unix.O_NONBLOCK] | `Truncate -> [Unix.O_WRONLY; Unix.O_CREAT; Unix.O_TRUNC; Unix.O_NONBLOCK] in Lwt_unix.openfile file_name flags perm >>= fun fd -> Lwt_unix.set_close_on_exec fd; let oc = Lwt_io.of_fd ~mode:Lwt_io.output fd in Lwt.return (channel ~template ~close_mode:`Close ~channel:oc ()) let level_code = function | Fatal -> 0 | Error -> 3 | Warning -> 4 | Notice -> 5 | Info -> 6 | Debug -> 7 type syslog_facility = [ `Auth | `Authpriv | `Cron | `Daemon | `FTP | `Kernel | `Local0 | `Local1 | `Local2 | `Local3 | `Local4 | `Local5 | `Local6 | `Local7 | `LPR | `Mail | `News | `Syslog | `User | `UUCP | `NTP | `Security | `Console ] let facility_code = function | `Kernel -> 0 | `User -> 1 | `Mail -> 2 | `Daemon -> 3 | `Auth -> 4 | `Syslog -> 5 | `LPR -> 6 | `News -> 7 | `UUCP -> 8 | `Cron -> 9 | `Authpriv -> 10 | `FTP -> 11 | `NTP -> 12 | `Security -> 13 | `Console -> 14 | `Local0 -> 16 | `Local1 -> 17 | `Local2 -> 18 | `Local3 -> 19 | `Local4 -> 20 | `Local5 -> 21 | `Local6 -> 22 | `Local7 -> 23 type syslog_connection_type = STREAM | DGRAM let shutdown fd = Lwt_unix.shutdown fd Unix.SHUTDOWN_ALL; Lwt_unix.close fd (* Try to find a socket in [paths]. For each path it check that the file is a socket and try to establish connection in DGRAM mode then in STREAM mode. *) let syslog_connect paths = let rec loop = function | [] -> (* No working socket found *) log_intern "no working socket found in {%s}; is syslogd running?" (String.concat ", " (List.map (Printf.sprintf "\"%s\"") paths)); Lwt.fail (Sys_error(Unix.error_message Unix.ENOENT)) | path :: paths -> begin try Lwt.return (Some (Unix.stat path).Unix.st_kind) with | Unix.Unix_error(Unix.ENOENT, _, _) -> Lwt.return_none | Unix.Unix_error(error, _, _) -> log_intern "can not stat \"%s\": %s" path (Unix.error_message error); Lwt.return_none end >>= (function | None -> loop paths | Some Unix.S_SOCK -> begin (* First, we try with a dgram socket : *) let fd = Lwt_unix.socket Unix.PF_UNIX Unix.SOCK_DGRAM 0 in Lwt.catch (fun () -> Lwt_unix.connect fd (Unix.ADDR_UNIX path) >>= fun () -> Lwt_unix.set_close_on_exec fd; Lwt.return (DGRAM, fd)) (function | Unix.Unix_error(Unix.EPROTOTYPE, _, _) -> begin Lwt_unix.close fd >>= fun () -> (* Then try with a stream socket: *) let fd = Lwt_unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in Lwt.catch (fun () -> Lwt_unix.connect fd (Unix.ADDR_UNIX path) >>= fun () -> Lwt_unix.set_close_on_exec fd; Lwt.return (STREAM, fd)) (function | Unix.Unix_error(error, _, _) -> Lwt_unix.close fd >>= fun () -> log_intern "can not connect to \"%s\": %s" path (Unix.error_message error); loop paths | exn -> Lwt.fail exn) end | Unix.Unix_error(error, _, _) -> Lwt_unix.close fd >>= fun () -> log_intern "can not connect to \"%s\": %s" path (Unix.error_message error); loop paths | exn -> Lwt.fail exn) [@ocaml.warning "-4"] end | Some _ -> log_intern "\"%s\" is not a socket" path; loop paths) [@ocaml.warning "-4"] in loop paths (* Write the whole contents of a string on the given file descriptor: *) let write_string fd str = let len = String.length str in let rec aux start_ofs = if start_ofs = len then Lwt.return_unit else Lwt_unix.write_string fd str start_ofs (len - start_ofs) >>= fun n -> if n <> 0 then aux (start_ofs + n) else Lwt.return_unit in aux 0 let truncate buf max = if Buffer.length buf > max then begin let suffix = "" in let len_suffix = String.length suffix in Buffer.sub buf 0 (max - len_suffix) ^ suffix end else Buffer.contents buf let syslog ?(template="$(date) $(name)[$(pid)]: $(section): $(message)") ?(paths=["/dev/log"; "/var/run/log"; "/var/run/syslog"]) ~facility () = let syslog_socket = ref None and mutex = Lwt_mutex.create () in let get_syslog () = match !syslog_socket with | Some x -> Lwt.return x | None -> syslog_connect paths >>= fun x -> syslog_socket := Some x; Lwt.return x in make ~output:(fun section level lines -> Lwt_mutex.with_lock mutex (fun () -> let buf = Buffer.create 42 in let make_line socket_type msg = Buffer.clear buf; Printf.bprintf buf "<%d>" ((facility_code facility lsl 3) lor level_code level); render ~buffer:buf ~template ~section ~level ~message:msg; if socket_type = STREAM then Buffer.add_char buf '\x00'; truncate buf 1024 in let rec print socket_type fd = function | [] -> Lwt.return_unit | line :: lines -> Lwt.catch (fun () -> write_string fd (make_line socket_type line) >>= fun () -> print socket_type fd lines) (function | Unix.Unix_error(_, _, _) -> (* Try to reconnect *) shutdown fd >>= fun () -> syslog_socket := None; get_syslog () >>= fun (socket_type, fd) -> write_string fd (make_line socket_type line) >>= fun () -> print socket_type fd lines | exn -> Lwt.fail exn) in get_syslog () >>= fun (socket_type, fd) -> print socket_type fd lines)) ~close:(fun () -> match !syslog_socket with | None -> Lwt.return_unit | Some(_socket_type, fd) -> shutdown fd) lwt_log-1.1.2/src/unix/lwt_log.mli000066400000000000000000000112111430315200700170750ustar00rootroot00000000000000(* OCaml promise library * http://www.ocsigen.org/lwt * Copyright (C) 2002 Shawn Wagner * 2009 Jérémie Dimino * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, with linking exceptions; * either version 2.1 of the License, or (at your option) any later * version. See COPYING file for details. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser 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. *) (** Logging functions This module provides logging functions. It is actually a thin extension of {!Lwt_log_core}, adding logging destinations that are only available on Unix and Windows (such as files, standard output, and the system log). Being a thin extension, most of the functions in this module are actually the ones in {!Lwt_log_core}. They are not repeated on this page, however, so please read both {!Lwt_log_core} {e and} this page for a complete understanding. Here is a simple, self-contained usage example: {[ let () = Lwt_log.default := Lwt_log.channel ~template:"$(date).$(milliseconds) [$(level)] $(message)" ~close_mode:`Keep ~channel:Lwt_io.stdout (); Lwt_log.add_rule "*" Lwt_log.Info; Lwt_main.run begin Lwt_log.info "Hello world!" end (* ocamlfind opt -linkpkg -package lwt.unix log_example.ml && ./a.out *) ]} As an alternative to this module, we suggest trying {{: http://erratique.ch/software/logs/doc/Logs_lwt.html}[Logs_lwt]} from the {{: http://erratique.ch/software/logs} [logs]} library. *) include module type of Lwt_log_core with type level = Lwt_log_core.level and type logger = Lwt_log_core.logger and type section = Lwt_log_core.section and type template = Lwt_log_core.template and module Section = Lwt_log_core.Section val render : buffer : Buffer.t -> template : template -> section : section -> level : level -> message : string -> unit (** Same as {!Lwt_log_core.render}, except that the template may also contain the following variables: - [date], which will be replaced with the current local date and time, - [milliseconds], which will be replaced by the fractional part of the current Unix time, to millisecond accuracy. For example: - ["$(date) $(name)[$(pid)]: $(message)"] - ["$(date).$(milliseconds) $(name)[$(pid)]: $(message)"] - ["$(date): $(loc-file): $(loc-line): $(loc-column): $(message)"] *) (** Syslog facility. Look at the SYSLOG(3) man page for a description of syslog facilities *) type syslog_facility = [ `Auth | `Authpriv | `Cron | `Daemon | `FTP | `Kernel | `Local0 | `Local1 | `Local2 | `Local3 | `Local4 | `Local5 | `Local6 | `Local7 | `LPR | `Mail | `News | `Syslog | `User | `UUCP | `NTP | `Security | `Console ] val syslog : ?template : template -> ?paths : string list -> facility : syslog_facility -> unit -> logger (** [syslog ?template ?paths ~facility ()] creates an logger which send message to the system logger. @param paths is a list of path to try for the syslogd socket. It default to [["/dev/log"; "/var/run/log"]]. @param template defaults to ["$(date) $(name)[$(pid)]: $(section): $(message)"] *) val file : ?template : template -> ?mode : [ `Truncate | `Append ] -> ?perm : Unix.file_perm -> file_name : string -> unit -> logger Lwt.t (** [desf_file ?template ?mode ?perm ~file_name ()] creates an logger which will write messages to [file_name]. - if [mode = `Truncate] then the file is truncated and previous contents will be lost. - if [mode = `Append], new messages will be appended at the end of the file @param mode defaults to [`Append] @param template defaults to ["$(date): $(section): $(message)"] *) val channel :?template : template -> close_mode : [ `Close | `Keep ] -> channel : Lwt_io.output_channel -> unit -> logger (** [channel ?template ~close_mode ~channel ()] creates a logger from a channel. If [close_mode = `Close] then [channel] is closed when the logger is closed, otherwise it is left open. @param template defaults to ["$(name): $(section): $(message)"] *)