pax_global_header00006660000000000000000000000064146504777270014535gustar00rootroot0000000000000052 comment=b763796c440b9e238441d0f57e0a96b54f2275fb mixlib-log-3.1.2/000077500000000000000000000000001465047772700136035ustar00rootroot00000000000000mixlib-log-3.1.2/.expeditor/000077500000000000000000000000001465047772700156645ustar00rootroot00000000000000mixlib-log-3.1.2/.expeditor/config.yml000066400000000000000000000031541465047772700176570ustar00rootroot00000000000000# Documentation available at https://expeditor.chef.io/docs/getting-started/ --- # Slack channel in Chef Software slack to send notifications about build failures, etc slack: notify_channel: chef-found-notify # This publish is triggered by the `built_in:publish_rubygems` artifact_action. rubygems: - mixlib-log github: # This deletes the GitHub PR branch after successfully merged into the release branch delete_branch_on_merge: true # The tag format to use (e.g. v1.0.0) version_tag_format: "v{{version}}" # allow bumping the minor release via label minor_bump_labels: - "Expeditor: Bump Version Minor" # allow bumping the major release via label major_bump_labels: - "Expeditor: Bump Version Major" changelog: rollup_header: Changes not yet released to rubygems.org subscriptions: # These actions are taken, in order they are specified, anytime a Pull Request is merged. - workload: pull_request_merged:{{github_repo}}:{{release_branch}}:* actions: - built_in:bump_version: ignore_labels: - "Expeditor: Skip Version Bump" - "Expeditor: Skip All" - bash:.expeditor/update_version.sh: only_if: built_in:bump_version - built_in:update_changelog: ignore_labels: - "Expeditor: Skip Changelog" - "Expeditor: Skip All" - built_in:build_gem: only_if: built_in:bump_version - workload: project_promoted:{{agent_id}}:* actions: - built_in:rollover_changelog - built_in:publish_rubygems pipelines: - verify: description: Pull Request validation tests public: true mixlib-log-3.1.2/.expeditor/run_linux_tests.sh000077500000000000000000000004761465047772700214770ustar00rootroot00000000000000#!/bin/bash # # This script runs a passed in command, but first setups up the bundler caching on the repo set -ue export USER="root" export LANG=C.UTF-8 LANGUAGE=C.UTF-8 echo "--- bundle install" bundle config --local path vendor/bundle bundle install --jobs=7 --retry=3 echo "+++ bundle exec task" bundle exec $@ mixlib-log-3.1.2/.expeditor/run_windows_tests.ps1000066400000000000000000000007001465047772700221060ustar00rootroot00000000000000# Stop script execution when a non-terminating error occurs $ErrorActionPreference = "Stop" # This will run ruby test on windows platform Write-Output "--- Bundle install" bundle config --local path vendor/bundle If ($lastexitcode -ne 0) { Exit $lastexitcode } bundle install --jobs=7 --retry=3 If ($lastexitcode -ne 0) { Exit $lastexitcode } Write-Output "--- Bundle Execute" bundle exec rake If ($lastexitcode -ne 0) { Exit $lastexitcode } mixlib-log-3.1.2/.expeditor/update_version.sh000077500000000000000000000007041465047772700212530ustar00rootroot00000000000000#!/bin/sh # # After a PR merge, Chef Expeditor will bump the PATCH version in the VERSION file. # It then executes this file to update any other files/components with that new version. # set -evx sed -i -r "s/^(\s*)VERSION = \".+\"/\1VERSION = \"$(cat VERSION)\"/" lib/mixlib/log/version.rb # Once Expeditor finshes executing this script, it will commit the changes and push # the commit as a new tag corresponding to the value in the VERSION file. mixlib-log-3.1.2/.expeditor/verify.pipeline.yml000066400000000000000000000021451465047772700215210ustar00rootroot00000000000000--- expeditor: cached_folders: - vendor defaults: buildkite: timeout_in_minutes: 30 steps: - label: run-lint-and-specs-ruby-2.7 command: - .expeditor/run_linux_tests.sh rake expeditor: executor: docker: image: ruby:2.7 - label: run-lint-and-specs-ruby-3.0 command: - .expeditor/run_linux_tests.sh rake expeditor: executor: docker: image: ruby:3.0 - label: run-lint-and-specs-ruby-3.1 command: - .expeditor/run_linux_tests.sh rake expeditor: executor: docker: image: ruby:3.1 - label: run-specs-ruby-3.0-windows command: - .expeditor/run_windows_tests.ps1 expeditor: executor: docker: host_os: windows shell: ["powershell", "-Command"] image: rubydistros/windows-2019:3.0 user: 'NT AUTHORITY\SYSTEM' - label: run-specs-ruby-3.1-windows command: - .expeditor/run_windows_tests.ps1 expeditor: executor: docker: host_os: windows shell: ["powershell", "-Command"] image: rubydistros/windows-2019:3.1 user: 'NT AUTHORITY\SYSTEM' mixlib-log-3.1.2/.gemtest000066400000000000000000000000001465047772700152420ustar00rootroot00000000000000mixlib-log-3.1.2/.github/000077500000000000000000000000001465047772700151435ustar00rootroot00000000000000mixlib-log-3.1.2/.github/CODEOWNERS000066400000000000000000000003621465047772700165370ustar00rootroot00000000000000# Order is important. The last matching pattern has the most precedence. * @chef/chef-infra-reviewers @chef/chef-infra-approvers @chef/chef-infra-owners .expeditor/ @chef/infra-packages *.md @chef/docs-team mixlib-log-3.1.2/.github/ISSUE_TEMPLATE/000077500000000000000000000000001465047772700173265ustar00rootroot00000000000000mixlib-log-3.1.2/.github/ISSUE_TEMPLATE/BUG_TEMPLATE.md000066400000000000000000000011651465047772700215630ustar00rootroot00000000000000--- name: � Bug Report about: If something isn't working as expected �. labels: "Status: Untriaged, Type: Bug" --- # Version: [Version of the project installed] # Environment: [Details about the environment such as the Operating System, cookbook details, etc...] # Scenario: [What you are trying to achieve and you can't?] # Steps to Reproduce: [If you are filing an issue what are the things we need to do in order to repro your problem?] # Expected Result: [What are you expecting to happen as the consequence of above reproduction steps?] # Actual Result: [What actually happens after the reproduction steps?] mixlib-log-3.1.2/.github/ISSUE_TEMPLATE/DESIGN_PROPOSAL.md000066400000000000000000000023721465047772700221440ustar00rootroot00000000000000--- name: Design Proposal about: I have a significant change I would like to propose and discuss before starting labels: "Status: Untriaged, Type: Design Proposal" --- ### When a Change Needs a Design Proposal A design proposal should be opened any time a change meets one of the following qualifications: - Significantly changes the user experience of a project in a way that impacts users. - Significantly changes the underlying architecture of the project in a way that impacts other developers. - Changes the development or testing process of the project such as a change of CI systems or test frameworks. ### Why We Use This Process - Allows all interested parties (including any community member) to discuss large impact changes to a project. - Serves as a durable paper trail for discussions regarding project architecture. - Forces design discussions to occur before PRs are created. - Reduces PR refactoring and rejected PRs. --- ## Motivation ## Specification ## Downstream Impact mixlib-log-3.1.2/.github/ISSUE_TEMPLATE/ENHANCEMENT_REQUEST_TEMPLATE.md000066400000000000000000000014071465047772700241020ustar00rootroot00000000000000--- name: 🚀 Enhancement Request about: I have a suggestion (and may want to implement it 🙂)! labels: "Status: Untriaged" --- ### Describe the Enhancement: ### Describe the Need: ### Current Alternative ### Can We Help You Implement This?: mixlib-log-3.1.2/.github/ISSUE_TEMPLATE/SUPPORT_QUESTION.md000066400000000000000000000006611465047772700223560ustar00rootroot00000000000000--- name: 🤗 Support Question about: If you have a question 💬, please check out our Slack! --- We use GitHub issues to track bugs and feature requests. If you need help please post to our Mailing List or join the Chef Community Slack. * Chef Community Slack at https://community-slack.chef.io/. * Chef Mailing List https://discourse.chef.io/ Support issues opened here will be closed and redirected to Slack or Discourse. mixlib-log-3.1.2/.github/dependabot.yml000066400000000000000000000002651465047772700177760ustar00rootroot00000000000000version: 2 updates: - package-ecosystem: bundler directory: "/" schedule: interval: daily time: "06:00" timezone: America/Los_Angeles open-pull-requests-limit: 10 mixlib-log-3.1.2/.gitignore000066400000000000000000000001131465047772700155660ustar00rootroot00000000000000*.sw? .DS_Store coverage rdoc pkg .rake_tasks~ .bundle Gemfile.lock vendor mixlib-log-3.1.2/.rspec000066400000000000000000000000401465047772700147120ustar00rootroot00000000000000--colour --format documentation mixlib-log-3.1.2/.rubocop.yml000066400000000000000000000001131465047772700160500ustar00rootroot00000000000000Style/PreferredHashMethods: Exclude: - 'lib/mixlib/log/formatter.rb' mixlib-log-3.1.2/CHANGELOG.md000066400000000000000000000230611465047772700154160ustar00rootroot00000000000000# Change Log ## [v3.1.2](https://github.com/chef/mixlib-log/tree/v3.1.2) (2024-07-25) #### Merged Pull Requests - Fix formatter regression from Ruby 3.3 Logger fix [#78](https://github.com/chef/mixlib-log/pull/78) ([stanhu](https://github.com/stanhu)) ### Changes not yet released to rubygems.org #### Merged Pull Requests - Fix formatter regression from Ruby 3.3 Logger fix [#78](https://github.com/chef/mixlib-log/pull/78) ([stanhu](https://github.com/stanhu)) ## [v3.1.1](https://github.com/chef/mixlib-log/tree/v3.1.1) (2024-07-12) #### Merged Pull Requests - Replace __FILE__ with __dir__ and other minor chefstyle fixes [#61](https://github.com/chef/mixlib-log/pull/61) ([tas50](https://github.com/tas50)) - Add Ruby 3.0 testing [#62](https://github.com/chef/mixlib-log/pull/62) ([tas50](https://github.com/tas50)) - Upgrade to GitHub-native Dependabot [#63](https://github.com/chef/mixlib-log/pull/63) ([dependabot-preview[bot]](https://github.com/dependabot-preview[bot])) - Remove Ruby 2.4 support and Test Ruby 3.0/3.1 [#66](https://github.com/chef/mixlib-log/pull/66) ([poorndm](https://github.com/poorndm)) - Bump minimum to 2.7 [#75](https://github.com/chef/mixlib-log/pull/75) ([tpowell-progress](https://github.com/tpowell-progress)) - Support ruby3.3 Logger by properly initialize super class [#74](https://github.com/chef/mixlib-log/pull/74) ([mtasaka](https://github.com/mtasaka)) - ffi less than 1.17.0 because of ruby 3.0 [#77](https://github.com/chef/mixlib-log/pull/77) ([tpowell-progress](https://github.com/tpowell-progress)) ## [v3.0.9](https://github.com/chef/mixlib-log/tree/v3.0.9) (2020-08-21) #### Merged Pull Requests - Optimize our requires [#60](https://github.com/chef/mixlib-log/pull/60) ([tas50](https://github.com/tas50)) ## [v3.0.8](https://github.com/chef/mixlib-log/tree/v3.0.8) (2019-12-30) #### Merged Pull Requests - Expand testing / Update GitHub templates [#51](https://github.com/chef/mixlib-log/pull/51) ([tas50](https://github.com/tas50)) - Add Build Kite PR Testing [#52](https://github.com/chef/mixlib-log/pull/52) ([tas50](https://github.com/tas50)) - Remove Travis PR Testing [#53](https://github.com/chef/mixlib-log/pull/53) ([tas50](https://github.com/tas50)) - Resolve all warnings emitted during testing [#54](https://github.com/chef/mixlib-log/pull/54) ([zenspider](https://github.com/zenspider)) - Add windows testing in Buildkite [#56](https://github.com/chef/mixlib-log/pull/56) ([tas50](https://github.com/tas50)) - Test on Ruby 2.7 + random testing improvements [#58](https://github.com/chef/mixlib-log/pull/58) ([tas50](https://github.com/tas50)) - Substitute require for require_relative [#59](https://github.com/chef/mixlib-log/pull/59) ([tas50](https://github.com/tas50)) ## [v3.0.1](https://github.com/chef/mixlib-log/tree/v3.0.1) (2019-01-05) #### Merged Pull Requests - reverting back to ruby 2.3 support [#48](https://github.com/chef/mixlib-log/pull/48) ([lamont-granquist](https://github.com/lamont-granquist)) ## [v3.0.0](https://github.com/chef/mixlib-log/tree/v3.0.0) (2019-01-04) #### Merged Pull Requests - update travis, drop ruby < 2.5, major version bump [#47](https://github.com/chef/mixlib-log/pull/47) ([lamont-granquist](https://github.com/lamont-granquist)) ## [v2.0.9](https://github.com/chef/mixlib-log/tree/v2.0.9) (2018-12-18) #### Merged Pull Requests - remove hashrocket syntax [#41](https://github.com/chef/mixlib-log/pull/41) ([lamont-granquist](https://github.com/lamont-granquist)) - Remove the changelog generator gem [#42](https://github.com/chef/mixlib-log/pull/42) ([tas50](https://github.com/tas50)) - Test on all the Ruby versions we support [#43](https://github.com/chef/mixlib-log/pull/43) ([tas50](https://github.com/tas50)) - Test on Ruby 2.6 in Travis + test on Xenial [#46](https://github.com/chef/mixlib-log/pull/46) ([tas50](https://github.com/tas50)) - Only ship the required library files in the gem artifact [#45](https://github.com/chef/mixlib-log/pull/45) ([tas50](https://github.com/tas50)) ## [v2.0.4](https://github.com/chef/mixlib-log/tree/v2.0.4) (2018-04-12) #### Merged Pull Requests - fix labelling [#37](https://github.com/chef/mixlib-log/pull/37) ([thommay](https://github.com/thommay)) ## [2.0.1](https://github.com/chef/mixlib-log/tree/2.0.1) (2018-02-28) [Full Changelog](https://github.com/chef/mixlib-log/compare/v2.0.0...2.0.1) **Merged pull requests:** - enable metadata to be got and set [\#32](https://github.com/chef/mixlib-log/pull/32) ([thommay](https://github.com/thommay)) - Logging methods \(debug, info, warn, error, fatal\) all return nil [\#27](https://github.com/chef/mixlib-log/pull/27) ([olleolleolle](https://github.com/olleolleolle)) ## [v2.0.0](https://github.com/chef/mixlib-log/tree/v2.0.0) (2018-02-27) [Full Changelog](https://github.com/chef/mixlib-log/compare/v1.7.1...v2.0.0) **Merged pull requests:** - Structured Logging [\#30](https://github.com/chef/mixlib-log/pull/30) ([thommay](https://github.com/thommay)) - RSpec: use 3.7, disable monkey patching mode [\#28](https://github.com/chef/mixlib-log/pull/28) ([olleolleolle](https://github.com/olleolleolle)) - README: Format a line of code using Markdown, not RDoc [\#24](https://github.com/chef/mixlib-log/pull/24) ([olleolleolle](https://github.com/olleolleolle)) - Travis: update Ruby versions, pass lint [\#22](https://github.com/chef/mixlib-log/pull/22) ([olleolleolle](https://github.com/olleolleolle)) - Require Ruby 2.2+ [\#20](https://github.com/chef/mixlib-log/pull/20) ([tas50](https://github.com/tas50)) ## [v1.7.1](https://github.com/chef/mixlib-log/tree/v1.7.1) (2016-08-12) [Full Changelog](https://github.com/chef/mixlib-log/compare/v1.7.0...v1.7.1) **Merged pull requests:** - Release 1.7.1 [\#19](https://github.com/chef/mixlib-log/pull/19) ([mwrock](https://github.com/mwrock)) - Allow applications to query if they've got loggers [\#18](https://github.com/chef/mixlib-log/pull/18) ([thommay](https://github.com/thommay)) ## [v1.7.0](https://github.com/chef/mixlib-log/tree/v1.7.0) (2016-08-04) [Full Changelog](https://github.com/chef/mixlib-log/compare/1.4.1...v1.7.0) **Merged pull requests:** - test with updated ruby versions and run cucumber [\#16](https://github.com/chef/mixlib-log/pull/16) ([thommay](https://github.com/thommay)) - Add dev dependency on chefstyle [\#15](https://github.com/chef/mixlib-log/pull/15) ([tas50](https://github.com/tas50)) - Misc cleanup + add Travis [\#14](https://github.com/chef/mixlib-log/pull/14) ([tas50](https://github.com/tas50)) - File log devices opened by mixlib-log should be closed. [\#13](https://github.com/chef/mixlib-log/pull/13) ([mhorbul](https://github.com/mhorbul)) - Include the license type in the .gemspec [\#9](https://github.com/chef/mixlib-log/pull/9) ([benders](https://github.com/benders)) - MIXLIB-10: don't be so pessimistic about development libraries [\#8](https://github.com/chef/mixlib-log/pull/8) ([jkeiser](https://github.com/jkeiser)) - Ensure that arguments to Mixlib::Log\#add are passed as is to all loggers [\#7](https://github.com/chef/mixlib-log/pull/7) ([ketan](https://github.com/ketan)) - Fixing RDoc formatting of README.rdoc. [\#4](https://github.com/chef/mixlib-log/pull/4) ([ampledata](https://github.com/ampledata)) ## [1.4.1](https://github.com/chef/mixlib-log/tree/1.4.1) (2012-06-08) [Full Changelog](https://github.com/chef/mixlib-log/compare/1.4.0...1.4.1) ## [1.4.0](https://github.com/chef/mixlib-log/tree/1.4.0) (2012-06-08) [Full Changelog](https://github.com/chef/mixlib-log/compare/1.3.0...1.4.0) **Merged pull requests:** - Inconsistent documentation about default base log level [\#5](https://github.com/chef/mixlib-log/pull/5) ([bjoernalbers](https://github.com/bjoernalbers)) ## [1.3.0](https://github.com/chef/mixlib-log/tree/1.3.0) (2011-03-17) [Full Changelog](https://github.com/chef/mixlib-log/compare/1.2.0...1.3.0) ## [1.2.0](https://github.com/chef/mixlib-log/tree/1.2.0) (2010-10-15) [Full Changelog](https://github.com/chef/mixlib-log/compare/alpha_deploy_2...1.2.0) ## [alpha_deploy_2](https://github.com/chef/mixlib-log/tree/alpha_deploy_2) (2010-02-28) [Full Changelog](https://github.com/chef/mixlib-log/compare/alpha_deploy_3...alpha_deploy_2) ## [alpha_deploy_3](https://github.com/chef/mixlib-log/tree/alpha_deploy_3) (2010-02-28) [Full Changelog](https://github.com/chef/mixlib-log/compare/alpha_deploy_4...alpha_deploy_3) ## [alpha_deploy_4](https://github.com/chef/mixlib-log/tree/alpha_deploy_4) (2010-02-28) [Full Changelog](https://github.com/chef/mixlib-log/compare/beta-1...alpha_deploy_4) ## [beta-1](https://github.com/chef/mixlib-log/tree/beta-1) (2010-02-28) [Full Changelog](https://github.com/chef/mixlib-log/compare/1.1.0...beta-1) ## [1.1.0](https://github.com/chef/mixlib-log/tree/1.1.0) (2010-02-28) [Full Changelog](https://github.com/chef/mixlib-log/compare/v1.1.0...1.1.0) ## [v1.1.0](https://github.com/chef/mixlib-log/tree/v1.1.0) (2010-01-05) [Full Changelog](https://github.com/chef/mixlib-log/compare/alpha_deploy_1...v1.1.0) ## [alpha_deploy_1](https://github.com/chef/mixlib-log/tree/alpha_deploy_1) (2009-05-12) [Full Changelog](https://github.com/chef/mixlib-log/compare/v1.0.3...alpha_deploy_1) ## [v1.0.3](https://github.com/chef/mixlib-log/tree/v1.0.3) (2009-05-12) [Full Changelog](https://github.com/chef/mixlib-log/compare/v1.0.2...v1.0.3) ## [v1.0.2](https://github.com/chef/mixlib-log/tree/v1.0.2) (2009-05-12) \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*mixlib-log-3.1.2/CODE_OF_CONDUCT.md000066400000000000000000000001331465047772700163770ustar00rootroot00000000000000Please refer to the Chef Community Code of Conduct at https://www.chef.io/code-of-conduct/ mixlib-log-3.1.2/CONTRIBUTING.md000066400000000000000000000001111465047772700160250ustar00rootroot00000000000000Please refer to https://github.com/chef/chef/blob/master/CONTRIBUTING.md mixlib-log-3.1.2/Gemfile000077500000000000000000000004021465047772700150750ustar00rootroot00000000000000 source "https://rubygems.org" gemspec group :test do gem "activesupport" gem "chefstyle" gem "cucumber", "~> 9.1.0" gem "rake" gem "rspec", "~> 3.7" gem "rubocop-ast" end group :debug do gem "pry" gem "pry-byebug" gem "rb-readline" end mixlib-log-3.1.2/LICENSE000066400000000000000000000251421465047772700146140ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. mixlib-log-3.1.2/NOTICE000066400000000000000000000015201465047772700145050ustar00rootroot00000000000000============ Mixin::Log Notices ============ Developed at Chef (http://www.chef.io). * Copyright 2009-2016, Chef Software, Inc. Mixin::Log incorporates code from Chef. The Chef notice file follows: ============ Chef Notices ============ Developed at Chef (http://www.chef.io). Contributors and Copyright holders: * Copyright 2008, Adam Jacob * Copyright 2008, Arjuna Christensen * Copyright 2008, Bryan McLellan * Copyright 2008, Ezra Zygmuntowicz * Copyright 2009, Sean Cribbs * Copyright 2009, Christopher Brown * Copyright 2009, Thom May Chef incorporates code modified from Open4 (http://www.codeforpeople.com/lib/ruby/open4/), which was written by Ara T. Howard. mixlib-log-3.1.2/README.md000066400000000000000000000044341465047772700150670ustar00rootroot00000000000000# Mixlib::Log [![Gem Version](https://badge.fury.io/rb/mixlib-log.svg)](https://badge.fury.io/rb/mixlib-log) [![Build status](https://badge.buildkite.com/cb1e5b6f3cc77071f4b2315f6b605fe60d86e2862a490873d4.svg?branch=master)](https://buildkite.com/chef-oss/chef-mixlib-log-master-verify) **Umbrella Project**: [Chef Foundation](https://github.com/chef/chef-oss-practices/blob/master/projects/chef-foundation.md) **Project State**: [Active](https://github.com/chef/chef-oss-practices/blob/master/repo-management/repo-states.md#active) **Issues [Response Time Maximum](https://github.com/chef/chef-oss-practices/blob/master/repo-management/repo-states.md)**: 14 days **Pull Request [Response Time Maximum](https://github.com/chef/chef-oss-practices/blob/master/repo-management/repo-states.md)**: 14 days Mixlib::Log provides a mixin for enabling a class based logger object, a-la Merb, Chef, and Nanite. To use it: ```ruby require 'mixlib/log' class Log extend Mixlib::Log end ``` You can then do: ```ruby Log.debug('foo') Log.info('bar') Log.warn('baz') Log.error('baz') Log.fatal('wewt') ``` By default, `Mixlib::Logger` logs to STDOUT. To alter this, you should call `Log.init`, passing any arguments to the standard Ruby Logger. For example: ```ruby Log.init('/tmp/logfile') # log to /tmp/logfile Log.init('/tmp/logfile', 7) # log to /tmp/logfile, rotate every day ``` Enjoy! ## Documentation All documentation is written using YARD. You can generate a by running: ``` rake docs ``` ## Contributing For information on contributing to this project please see our [Contributing Documentation](https://github.com/chef/chef/blob/master/CONTRIBUTING.md) ## License & Copyright - Copyright:: Copyright (c) 2008-2019 Chef Software, Inc. - License:: Apache License, Version 2.0 ```text Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` mixlib-log-3.1.2/Rakefile000066400000000000000000000022201465047772700152440ustar00rootroot00000000000000require "bundler" begin require "cucumber/rake/task" Cucumber::Rake::Task.new(:features) do |t| t.cucumber_opts = "--format pretty" t.bundler = false end rescue LoadError desc "cucumber is not installed, this task is disabled" task :spec do abort "cucumber is not installed. bundle install first to make sure all dependencies are installed." end end begin require "rspec/core/rake_task" RSpec::Core::RakeTask.new do |t| t.pattern = "spec/**/*_spec.rb" end rescue LoadError desc "rspec is not installed, this task is disabled" task :spec do abort "rspec is not installed. bundle install first to make sure all dependencies are installed." end end begin require "chefstyle" require "rubocop/rake_task" desc "Run Chefstyle tests" RuboCop::RakeTask.new(:style) do |task| task.options += ["--display-cop-names", "--no-color"] end rescue LoadError puts "chefstyle gem is not installed. bundle install first to make sure all dependencies are installed." end task :console do require "irb" require "irb/completion" require "mixlib/log" ARGV.clear IRB.start end task default: %i{style spec features} mixlib-log-3.1.2/VERSION000066400000000000000000000000051465047772700146460ustar00rootroot000000000000003.1.2mixlib-log-3.1.2/features/000077500000000000000000000000001465047772700154215ustar00rootroot00000000000000mixlib-log-3.1.2/features/log.feature000066400000000000000000000031751465047772700175650ustar00rootroot00000000000000Feature: Log output In order to keep a record of application specific information As a developer I want to publish information through a configurable log interface Scenario: Log a message at the debug level Given a base log level of 'debug' When the message 'this goes out' is sent at the 'debug' level Then the regex '\[.+\] DEBUG: this goes out' should be logged Scenario: Log a message at the info level Given a base log level of 'info' When the message 'this goes out' is sent at the 'info' level Then the regex '\[.+\] INFO: this goes out' should be logged Scenario: Log a message at the warn level Given a base log level of 'warn' When the message 'this goes out' is sent at the 'warn' level Then the regex '\[.+\] WARN: this goes out' should be logged Scenario: Log a message at the error level Given a base log level of 'error' When the message 'this goes out' is sent at the 'error' level Then the regex '\[.+\] ERROR: this goes out' should be logged Scenario: Log a message at the fatal level Given a base log level of 'fatal' When the message 'this goes out' is sent at the 'fatal' level Then the regex '\[.+\] FATAL: this goes out' should be logged Scenario: Log messages below the current threshold should not appear Given a base log level of 'fatal' When the message 'this goes out' is sent at the 'error' level And the message 'this goes out' is sent at the 'warn' level And the message 'this goes out' is sent at the 'info' level And the message 'this goes out' is sent at the 'debug' level Then nothing should be logged mixlib-log-3.1.2/features/steps/000077500000000000000000000000001465047772700165575ustar00rootroot00000000000000mixlib-log-3.1.2/features/steps/log.rb000066400000000000000000000025621465047772700176720ustar00rootroot00000000000000# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Given(/^a base log level of '(.+)'$/) do |level| Logit.level = level.to_sym end When(/^the message '(.+)' is sent at the '(.+)' level$/) do |message, level| case level.to_sym when :debug Logit.debug(message) when :info Logit.info(message) when :warn Logit.warn(message) when :error Logit.error(message) when :fatal Logit.fatal(message) else raise ArgumentError, "Level is not one of debug, info, warn, error, or fatal" end end Then(/^the regex '(.+)' should be logged$/) do |regex_string| regex = Regexp.new(regex_string, Regexp::MULTILINE) expect(regex.match(@output)).not_to be_nil end Then(/^nothing should be logged$/) do expect(@output).to eq "" end mixlib-log-3.1.2/features/support/000077500000000000000000000000001465047772700171355ustar00rootroot00000000000000mixlib-log-3.1.2/features/support/env.rb000066400000000000000000000021501465047772700202500ustar00rootroot00000000000000# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # $: << File.join(File.dirname(__FILE__), "..", "..", "lib") require "rspec/expectations" require "mixlib/log" require "tmpdir" require "stringio" class MyWorld def initialize @tmpdir = File.join(Dir.tmpdir, "mixlib_log") @output = "" @output_io = StringIO.new(@output) Logit.init(@output_io) end end World do MyWorld.new end Before do system("mkdir -p #{@tmpdir}") end After do system("rm -rf #{@tmpdir}") end mixlib-log-3.1.2/features/support/logit.rb000066400000000000000000000013251465047772700206010ustar00rootroot00000000000000# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # class Logit extend Mixlib::Log end mixlib-log-3.1.2/lib/000077500000000000000000000000001465047772700143515ustar00rootroot00000000000000mixlib-log-3.1.2/lib/mixlib/000077500000000000000000000000001465047772700156355ustar00rootroot00000000000000mixlib-log-3.1.2/lib/mixlib/log.rb000066400000000000000000000144141465047772700167470ustar00rootroot00000000000000# # Author:: Adam Jacob () # Author:: Christopher Brown () # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require "logger" require_relative "log/version" require_relative "log/formatter" require_relative "log/child" require_relative "log/logging" require_relative "log/logger" module Mixlib module Log include Logging def reset! @logger ||= nil @loggers ||= [] close! @logger = @loggers = nil @metadata = {} end # An Array of log devices that will be logged to. Defaults to just the default # \@logger log device, but you can push to this array to add more devices. def loggers @loggers ||= [logger] end ## # init always returns a configured logger # and creates a new one if it doesn't yet exist ## def logger @logger ||= init end # Sets the log device to +new_log_device+. Any additional loggers # that had been added to the +loggers+ array will be cleared. def logger=(new_log_device) reset! @logger = new_log_device end def use_log_devices(other) if other.respond_to?(:loggers) && other.respond_to?(:logger) @loggers = other.loggers @logger = other.logger elsif other.is_a?(Array) @loggers = other @logger = other.first else msg = "#use_log_devices takes a Mixlib::Log object or array of log devices. " << "You gave: #{other.inspect}" raise ArgumentError, msg end @configured = true end # Use Mixlib::Log.init when you want to set up the logger manually. Arguments to this method # get passed directly to Logger.new, so check out the documentation for the standard Logger class # to understand what to do here. # # If this method is called with no arguments, it will log to STDOUT at the :warn level. # # It also configures the Logger instance it creates to use the custom Mixlib::Log::Formatter class. def init(*opts) reset! @logger = logger_for(*opts) @logger.formatter = Mixlib::Log::Formatter.new if @logger.respond_to?(:formatter=) @logger.level = Logger::WARN @configured = true @parent = nil @metadata = {} @logger end # Let the application query if logging objects have been set up def configured? @configured end attr_accessor :metadata # Sets the level for the Logger object by symbol. Valid arguments are: # # :trace # :debug # :info # :warn # :error # :fatal # # Throws an ArgumentError if you feed it a bogus log level. def level=(new_level) level_int = LEVEL_NAMES.key?(new_level) ? new_level : LEVELS[new_level] raise ArgumentError, "Log level must be one of :trace, :debug, :info, :warn, :error, or :fatal" if level_int.nil? loggers.each { |l| l.level = level_int } end def level(new_level = nil) if new_level.nil? LEVEL_NAMES[logger.level] else self.level = new_level end end # Define the methods to interrogate the logger for the current log level. # Note that we *only* query the default logger (@logger) and not any other # loggers that may have been added, even though it is possible to configure # two (or more) loggers at different log levels. %i{trace? debug? info? warn? error? fatal?}.each do |method_name| define_method(method_name) do logger.send(method_name) end end def <<(msg) loggers.each { |l| l << msg } end def add(severity, message = nil, progname = nil, data: {}, &block) message, progname, data = yield if block_given? data = metadata.merge(data) if metadata.is_a?(Hash) && data.is_a?(Hash) loggers.each do |l| # if we don't have any metadata, let's not do the potentially expensive # merging and managing that this call requires if l.respond_to?(:add_data) && !data.nil? && !data.empty? l.add_data(severity, message, progname, data: data) else l.add(severity, message, progname) end end end alias :log :add def with_child(metadata = {}) child = Child.new(self, metadata) if block_given? yield child else child end end # Passes any other method calls on directly to the underlying Logger object created with init. If # this method gets hit before a call to Mixlib::Logger.init has been made, it will call # Mixlib::Logger.init() with no arguments. def method_missing(method_symbol, *args, &block) loggers.each { |l| l.send(method_symbol, *args, &block) } end private def logger_for(*opts) if opts.empty? Mixlib::Log::Logger.new($stdout) elsif LEVELS.keys.inject(true) { |quacks, level| quacks && opts.first.respond_to?(level) } opts.first else Mixlib::Log::Logger.new(*opts) end end def all_loggers [@logger, *@loggers].uniq end # select all loggers with File log devices def loggers_to_close loggers_to_close = [] all_loggers.each do |logger| # unfortunately Logger does not provide access to the logdev # via public API. In order to reduce amount of impact and # handle only File type log devices I had to use this method # to get access to it. next unless logger.instance_variable_defined?(:"@logdev") next unless (logdev = logger.instance_variable_get(:"@logdev")) loggers_to_close << logger if logdev.filename end loggers_to_close end def close! # try to close all file loggers loggers_to_close.each do |l| l.close rescue nil end end end end mixlib-log-3.1.2/lib/mixlib/log/000077500000000000000000000000001465047772700164165ustar00rootroot00000000000000mixlib-log-3.1.2/lib/mixlib/log/child.rb000066400000000000000000000034561465047772700200360ustar00rootroot00000000000000# # Copyright:: Copyright (c) 2018 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require_relative "logging" module Mixlib module Log class Child include Mixlib::Log::Logging attr_reader :parent attr_accessor :metadata def initialize(parent, metadata = {}) @parent = parent @metadata = metadata end def level parent.level end # Define the methods to interrogate the logger for the current log level. # Note that we *only* query the default logger (@logger) and not any other # loggers that may have been added, even though it is possible to configure # two (or more) loggers at different log levels. %i{trace? debug? info? warn? error? fatal?}.each do |method_name| define_method(method_name) do parent.send(method_name) end end def add(severity, message = nil, progname = nil, data: {}, &block) data = metadata.merge(data) if data.is_a?(Hash) parent.send(:pass, severity, message, progname, data: data, &block) end def with_child(metadata = {}) child = Child.new(self, metadata) if block_given? yield child else child end end end end end mixlib-log-3.1.2/lib/mixlib/log/formatter.rb000066400000000000000000000037551465047772700207600ustar00rootroot00000000000000# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require "logger" require "time" unless defined?(Time.zone_offset) module Mixlib module Log class Formatter < Logger::Formatter @@show_time = true def self.show_time=(show = false) @@show_time = show end # Prints a log message as '[time] severity: message' if Chef::Log::Formatter.show_time == true. # Otherwise, doesn't print the time. def call(severity, time, progname, msg) if @@show_time sprintf("[%s] %s: %s\n", time.iso8601, severity, msg2str(msg)) else sprintf("%s: %s\n", severity, msg2str(msg)) end end # Converts some argument to a Logger.severity() call to a string. Regular strings pass through like # normal, Exceptions get formatted as "message (class)\nbacktrace", and other random stuff gets # put through "object.inspect" def msg2str(msg) case msg when ::Hash if msg.has_key?(:err) format_exception(msg[:err]) else msg[:msg] end when ::String msg when ::Exception format_exception(msg) else msg.inspect end end def format_exception(msg) "#{msg.message} (#{msg.class})\n" << (msg.backtrace || []).join("\n") end end end end mixlib-log-3.1.2/lib/mixlib/log/logger.rb000066400000000000000000000052131465047772700202230ustar00rootroot00000000000000require "logger" require_relative "logging" # A subclass of Ruby's stdlib Logger with all the mutex and logrotation stuff # ripped out, and metadata added in. module Mixlib module Log class Logger < ::Logger include Logging def trace?; @level <= TRACE; end # # === Synopsis # # Logger.new(name, shift_age = 7, shift_size = 1048576) # Logger.new(name, shift_age = 'weekly') # # === Args # # +logdev+:: # The log device. This is a filename (String) or IO object (typically # +$stdout+, +$stderr+, or an open file). # +shift_age+:: # Number of old log files to keep, *or* frequency of rotation (+daily+, # +weekly+ or +monthly+). # +shift_size+:: # Maximum logfile size (only applies when +shift_age+ is a number). # # === Description # # Create an instance. # def initialize(logdev) super(nil, formatter: ::Mixlib::Log::Formatter.new) if logdev @logdev = LocklessLogDevice.new(logdev) end end def add_data(severity, message, progname, data: {}) return true if @logdev.nil? || severity < @level data ||= {} if message.is_a?(::Exception) data[:err] = message else data[:msg] = message end @logdev.write( format_message(to_label(severity), Time.now, progname, data) ) true end alias_method :add, :add_data class LocklessLogDevice < LogDevice def initialize(log = nil) @dev = @filename = @shift_age = @shift_size = nil if log.respond_to?(:write) && log.respond_to?(:close) @dev = log else @dev = open_logfile(log) @filename = log end @dev.sync = true end def write(message) @dev.write(message) rescue Exception => ignored warn("log writing failed. #{ignored}") end def close @dev.close rescue nil end private def open_logfile(filename) if FileTest.exist?(filename) open(filename, (File::WRONLY | File::APPEND)) else create_logfile(filename) end end def create_logfile(filename) logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT)) add_log_header(logdev) logdev end def add_log_header(file) file.write( "# Logfile created on %s by %s\n" % [Time.now.to_s, Logger::ProgName] ) end end end end end mixlib-log-3.1.2/lib/mixlib/log/logging.rb000066400000000000000000000032251465047772700203730ustar00rootroot00000000000000# # Copyright:: Copyright (c) 2018 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require "logger" module Mixlib module Log module Logging include ::Logger::Severity TRACE = -1 SEV_LABEL = %w{TRACE DEBUG INFO WARN ERROR FATAL ANY}.each(&:freeze).freeze def to_label(sev) SEV_LABEL[sev + 1] || -"ANY" end LEVELS = { trace: TRACE, debug: DEBUG, info: INFO, warn: WARN, error: ERROR, fatal: FATAL }.freeze LEVEL_NAMES = LEVELS.invert.freeze attr_accessor :metadata def pass(severity, args, progname = nil, data: {}, &block) args, progname, data = yield if block_given? add(severity, args, progname, data: data) end # Define the standard logger methods on this class programmatically. # No need to incur method_missing overhead on every log call. %i{trace debug info warn error fatal}.each do |method_name| level = LEVELS[method_name] define_method(method_name) do |msg = nil, data: {}, &block| pass(level, msg, data: data, &block) nil end end end end end mixlib-log-3.1.2/lib/mixlib/log/version.rb000066400000000000000000000001021465047772700204210ustar00rootroot00000000000000module Mixlib module Log VERSION = "3.1.2".freeze end end mixlib-log-3.1.2/mixlib-log.gemspec000066400000000000000000000011441465047772700172130ustar00rootroot00000000000000$:.unshift File.expand_path("lib", __dir__) require "mixlib/log/version" Gem::Specification.new do |gem| gem.name = "mixlib-log" gem.version = Mixlib::Log::VERSION gem.summary = "A gem that provides a simple mixin for log functionality" gem.email = "info@chef.io" gem.homepage = "https://github.com/chef/mixlib-log" gem.license = "Apache-2.0" gem.authors = ["Chef Software, Inc."] gem.files = %w{LICENSE} + Dir.glob("lib/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) } gem.require_paths = ["lib"] gem.required_ruby_version = ">= 2.7" gem.add_dependency "ffi", "< 1.17.0" end mixlib-log-3.1.2/spec/000077500000000000000000000000001465047772700145355ustar00rootroot00000000000000mixlib-log-3.1.2/spec/mixlib/000077500000000000000000000000001465047772700160215ustar00rootroot00000000000000mixlib-log-3.1.2/spec/mixlib/log/000077500000000000000000000000001465047772700166025ustar00rootroot00000000000000mixlib-log-3.1.2/spec/mixlib/log/child_spec.rb000066400000000000000000000067161465047772700212360ustar00rootroot00000000000000# # Copyright:: Copyright (c) 2018 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require "tempfile" unless defined?(Tempfile) require "stringio" unless defined?(StringIO) require "spec_helper" RSpec.describe Mixlib::Log::Child do before do Logit.reset! Logit.init(io) Logit.level = :warn end let(:io) { StringIO.new } let(:child) { Logit.with_child } it "has a parent" do expect(child.parent).to be(Logit) end it "accepts a message" do Logit.with_child { |l| l.add(Logger::WARN, "a message") } expect(io.string).to match(/a message$/) end context "with structured data" do it "can be created with metadata" do expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true" }) Logit.with_child({ child: "true" }) { |l| l.warn("a message") } end it "a message can be logged" do expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true" }) Logit.with_child { |l| l.warn("a message", data: { child: "true" }) } end context "merges properly" do it "in the simple case" do expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true", meta: "data" }) Logit.with_child(meta: "data") { |l| l.warn("a message", data: { child: "true" }) } end it "when overwriting" do expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true", meta: "overwritten" }) Logit.with_child(meta: "data") { |l| l.warn("a message", data: { child: "true", meta: "overwritten" }) } end end context "when receiving a message from a child" do it "passes data on" do expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true", parent: "first" }) child.metadata = { parent: "first" } child.with_child { |l| l.warn("a message", data: { child: "true" }) } end it "merges its own data" do expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true", parent: "second" }) child.metadata = { parent: "first" } child.with_child { |l| l.warn("a message", data: { child: "true", parent: "second" }) } end end end context "sends a message to the parent" do %i{ debug info warn error fatal }.each do |level| it "at #{level}" do expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[level], "a #{level} message", nil, data: {}) Logit.level = level child.send(level, "a #{level} message") end end end context "can query the parent's level" do %i{ debug info warn error fatal }.each do |level| it "at #{level}" do query = "#{level}?".to_sym Logit.level = level expect(child.send(query)).to be(true) end end end end mixlib-log-3.1.2/spec/mixlib/log/formatter_spec.rb000066400000000000000000000042351465047772700221500ustar00rootroot00000000000000# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require "time" unless defined?(Time.zone_offset) require "spec_helper" RSpec.describe Mixlib::Log::Formatter do before(:each) do @formatter = Mixlib::Log::Formatter.new end it "should print raw strings with msg2str(string)" do expect(@formatter.msg2str("nuthin new")).to eq("nuthin new") end it "should format exceptions properly with msg2str(e)" do e = IOError.new("legendary roots crew") expect(@formatter.msg2str(e)).to eq("legendary roots crew (IOError)\n") end it "should format random objects via inspect with msg2str(Object)" do expect(@formatter.msg2str([ "black thought", "?uestlove" ])).to eq('["black thought", "?uestlove"]') end it "should return a formatted string with call" do time = Time.new Mixlib::Log::Formatter.show_time = true expect(@formatter.call("monkey", time, "test", "mos def")).to eq("[#{time.iso8601}] monkey: mos def\n") end it "should allow you to turn the time on and off in the output" do Mixlib::Log::Formatter.show_time = false expect(@formatter.call("monkey", Time.new, "test", "mos def")).to eq("monkey: mos def\n") end context "with structured data" do let(:data) { {} } it "should format a message" do data[:msg] = "nuthin new" expect(@formatter.msg2str(data)).to eq("nuthin new") end it "should format an exception" do data[:err] = IOError.new("legendary roots crew") expect(@formatter.msg2str(data)).to eq("legendary roots crew (IOError)\n") end end end mixlib-log-3.1.2/spec/mixlib/log/logger_spec.rb000066400000000000000000000016211465047772700214200ustar00rootroot00000000000000# Copyright:: Copyright (c) 2024 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require "spec_helper" RSpec.describe Mixlib::Log::Logger do let(:io) { StringIO.new } subject { described_class.new(io) } it "logs a info message in text format" do subject.info("test message") expect(io.string).to match(/INFO: test message/) end end mixlib-log-3.1.2/spec/mixlib/log_spec.rb000066400000000000000000000164271465047772700201530ustar00rootroot00000000000000# # Author:: Adam Jacob () # Author:: Christopher Brown () # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require "tempfile" unless defined?(Tempfile) require "stringio" unless defined?(StringIO) require "spec_helper" class LoggerLike attr_accessor :level attr_reader :messages, :data def initialize @messages = "" @data = [] end def add_data(severity, message = nil, progname = nil, data: {}) @messages << message @data << data end def add(severity, message = nil, progname = nil, data: {}) @messages << message end %i{trace debug info warn error fatal}.each do |method_name| class_eval(<<-E) def #{method_name}(message) @messages << message end E end end RSpec.describe Mixlib::Log do # Since we are testing class behaviour for an instance variable # that gets set once, we need to reset it prior to each example [cb] before(:each) do Logit.reset! end it "creates a logger using an IO object" do io = StringIO.new Logit.init(io) Logit << "foo" expect(io.string).to match(/foo/) end it "creates a logger with a file name" do Tempfile.open("chef-test-log") do |tempfile| Logit.init(tempfile.path) Logit << "bar" tempfile.rewind expect(tempfile.read).to match(/bar/) end end it "uses the logger provided when initialized with a logger like object" do logger = LoggerLike.new Logit.init(logger) Logit.level = :debug Logit.debug "qux" expect(logger.messages).to match(/qux/) end it "should re-initialize the logger if init is called again" do first_logdev, second_logdev = StringIO.new, StringIO.new Logit.init(first_logdev) Logit.fatal "FIRST" expect(first_logdev.string).to match(/FIRST/) Logit.init(second_logdev) Logit.fatal "SECOND" expect(first_logdev.string).to_not match(/SECOND/) expect(second_logdev.string).to match(/SECOND/) end it "knows that it's been configured" do Logit.init expect(Logit.configured?).to be true end it "should set the log level using the binding form, with :trace, :debug, :info, :warn, :error, or :fatal" do levels = { trace: Mixlib::Log::TRACE, debug: Mixlib::Log::DEBUG, info: Mixlib::Log::INFO, warn: Mixlib::Log::WARN, error: Mixlib::Log::ERROR, fatal: Mixlib::Log::FATAL, } levels.each do |symbol, constant| Logit.level = symbol expect(Logit.logger.level).to eq(constant) expect(Logit.level).to eq(symbol) end end it "passes blocks to the underlying logger object" do logdev = StringIO.new Logit.init(logdev) Logit.fatal { "the_message" } expect(logdev.string).to match(/the_message/) end it "should set the log level using the method form, with :trace, :debug, :info, :warn, :error, or :fatal" do levels = { trace: Mixlib::Log::TRACE, debug: Mixlib::Log::DEBUG, info: Mixlib::Log::INFO, warn: Mixlib::Log::WARN, error: Mixlib::Log::ERROR, fatal: Mixlib::Log::FATAL, } levels.each do |symbol, constant| Logit.level(symbol) expect(Logit.logger.level).to eq(constant) end end it "should raise an ArgumentError if you try and set the level to something strange using the binding form" do expect { Logit.level = :the_roots }.to raise_error(ArgumentError) end it "should raise an ArgumentError if you try and set the level to something strange using the method form" do expect { Logit.level(:the_roots) }.to raise_error(ArgumentError) end it "should pass other method calls directly to logger" do expect do # this needs to be inside of the block because the level setting # is causing the init, which grabs $stderr before rspec replaces # it for output testing. Logit.level = :debug expect(Logit).to be_debug Logit.debug("Gimme some sugar!") end.to output(/DEBUG: Gimme some sugar!/).to_stdout end it "should pass add method calls directly to logger" do logdev = StringIO.new Logit.init(logdev) Logit.level = :debug expect(Logit).to be_debug expect { Logit.add(Logger::DEBUG, "Gimme some sugar!") }.to_not raise_error expect(logdev.string).to match(/Gimme some sugar/) end it "should default to STDOUT if init is called with no arguments" do logger_mock = Struct.new(:formatter, :level).new # intentionally STDOUT to avoid unfailable test expect(Logger).to receive(:new).with(STDOUT).and_return(logger_mock) Logit.init end it "should have by default a base log level of warn" do logger_mock = Struct.new(:formatter, :level).new expect(Logger).to receive(:new).and_return(logger_mock) Logit.init expect(Logit.level).to eq(:warn) end it "should close File logger" do opened_files_count_before = 0 ObjectSpace.each_object(File) do |f| opened_files_count_before += 1 unless f.closed? end name = File.join(Dir.tmpdir, "logger.log") Logit.init(name) Logit.init(name) Logit.init(name) opened_files_count_after = 0 ObjectSpace.each_object(File) do |f| opened_files_count_after += 1 unless f.closed? end expect(opened_files_count_after).to eq(opened_files_count_before + 1) end it "should not close IO logger" do opened_files_count_before = 0 ObjectSpace.each_object(File) do |f| opened_files_count_before += 1 unless f.closed? end Tempfile.open("chef-test-log") do |file| Logit.init(file) Logit.init(file) Logit.init(file) opened_files_count_after = 0 ObjectSpace.each_object(File) do |f| opened_files_count_after += 1 unless f.closed? end expect(opened_files_count_after).to eq(opened_files_count_before + 1) end end it "should return nil from its logging methods" do # intentionally STDOUT to avoid unfailable test expect(Logger).to receive(:new).with(STDOUT) { double("a-quiet-logger").as_null_object } Logit.init aggregate_failures "returns nil from logging method" do expect(Logit.trace("hello")).to be_nil expect(Logit.debug("hello")).to be_nil expect(Logit.info("hello")).to be_nil expect(Logit.warn("hello")).to be_nil expect(Logit.error("hello")).to be_nil expect(Logit.fatal("hello")).to be_nil end end it "should set metadata correctly" do Logit.metadata = { test: "data" } expect(Logit.metadata).to eql({ test: "data" }) end it "should format :trace level messages with TRACE: label" do logdev = StringIO.new Logit.init(logdev) Logit.level = :trace Logit.trace("this is a log message") aggregate_failures do expect(logdev.string).to_not match(/ANY:/) expect(logdev.string).to match(/TRACE:/) end end end mixlib-log-3.1.2/spec/spec_helper.rb000066400000000000000000000016041465047772700173540ustar00rootroot00000000000000# # Author:: Adam Jacob () # Author:: Christopher Brown () # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # $TESTING = true require "rspec" require "mixlib/log" require "mixlib/log/formatter" RSpec.configure(&:disable_monkey_patching!) class Logit extend Mixlib::Log end