├── .gemtest ├── VERSION ├── .rspec ├── CONTRIBUTING.md ├── .rubocop.yml ├── lib └── mixlib │ ├── log │ ├── version.rb │ ├── logging.rb │ ├── child.rb │ ├── formatter.rb │ └── logger.rb │ └── log.rb ├── .gitignore ├── CODE_OF_CONDUCT.md ├── .vscode └── mcp.json ├── .github ├── dependabot.yml ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── SUPPORT_QUESTION.md │ ├── BUG_TEMPLATE.md │ ├── ENHANCEMENT_REQUEST_TEMPLATE.md │ └── DESIGN_PROPOSAL.md ├── workflows │ └── ci-main-pull-request-checks.yml └── copilot-instructions.md ├── Gemfile ├── .expeditor ├── run_linux_tests.sh ├── update_version.sh ├── run_windows_tests.ps1 ├── verify.pipeline.yml └── config.yml ├── mixlib-log.gemspec ├── features ├── support │ ├── logit.rb │ └── env.rb ├── steps │ └── log.rb └── log.feature ├── NOTICE ├── spec ├── spec_helper.rb └── mixlib │ ├── log │ ├── logger_spec.rb │ ├── formatter_spec.rb │ └── child_spec.rb │ └── log_spec.rb ├── Rakefile ├── README.md ├── LICENSE └── CHANGELOG.md /.gemtest: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 3.2.9 -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --colour 2 | --format documentation 3 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Please refer to https://github.com/chef/chef/blob/master/CONTRIBUTING.md 2 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | Style/PreferredHashMethods: 2 | Exclude: 3 | - 'lib/mixlib/log/formatter.rb' 4 | -------------------------------------------------------------------------------- /lib/mixlib/log/version.rb: -------------------------------------------------------------------------------- 1 | module Mixlib 2 | module Log 3 | VERSION = "3.2.9".freeze 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.sw? 2 | .DS_Store 3 | coverage 4 | rdoc 5 | pkg 6 | .rake_tasks~ 7 | .bundle 8 | Gemfile.lock 9 | vendor 10 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Chef Code of Conduct 2 | 3 | Participants in this project must adhere to the [Chef Code of Conduct](https://chef.github.io/chef-oss-practices/policies/code-of-conduct/). -------------------------------------------------------------------------------- /.vscode/mcp.json: -------------------------------------------------------------------------------- 1 | { 2 | "servers": { 3 | "atlassian-mcp-server": { 4 | "url": "https://mcp.atlassian.com/v1/sse", 5 | "type": "http" 6 | }, 7 | }, 8 | "inputs": [] 9 | } 10 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: bundler 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "06:00" 8 | timezone: America/Los_Angeles 9 | open-pull-requests-limit: 10 10 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Order is important. The last matching pattern has the most precedence. 2 | 3 | * @chef/chef-infra-reviewers @chef/chef-infra-approvers @chef/chef-infra-owners @jaymzh 4 | .expeditor/ @chef/infra-packages 5 | *.md @chef/docs-team 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | 2 | source "https://rubygems.org" 3 | 4 | gemspec 5 | 6 | group :test do 7 | gem "activesupport" 8 | gem "cookstyle", ">= 7.32.8" 9 | gem "cucumber", "~> 10.1.0" 10 | gem "rake" 11 | gem "rspec", "~> 3.7" 12 | end 13 | 14 | group :debug do 15 | gem "pry" 16 | gem "pry-byebug" 17 | gem "rb-readline" 18 | end 19 | -------------------------------------------------------------------------------- /.expeditor/run_linux_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This script runs a passed in command, but first setups up the bundler caching on the repo 4 | 5 | set -ue 6 | 7 | export USER="root" 8 | export LANG=C.UTF-8 LANGUAGE=C.UTF-8 9 | 10 | echo "--- bundle install" 11 | bundle config --local path vendor/bundle 12 | bundle install --jobs=7 --retry=3 13 | 14 | echo "+++ bundle exec task" 15 | bundle exec $@ 16 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/SUPPORT_QUESTION.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🤗 Support Question 3 | about: If you have a question 💬, please check out our Slack! 4 | --- 5 | 6 | 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. 7 | 8 | * Chef Community Slack at https://community-slack.chef.io/. 9 | * Chef Mailing List https://discourse.chef.io/ 10 | 11 | Support issues opened here will be closed and redirected to Slack or Discourse. 12 | -------------------------------------------------------------------------------- /.expeditor/update_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # After a PR merge, Chef Expeditor will bump the PATCH version in the VERSION file. 4 | # It then executes this file to update any other files/components with that new version. 5 | # 6 | 7 | set -evx 8 | 9 | sed -i -r "s/^(\s*)VERSION = \".+\"/\1VERSION = \"$(cat VERSION)\"/" lib/mixlib/log/version.rb 10 | 11 | # Once Expeditor finshes executing this script, it will commit the changes and push 12 | # the commit as a new tag corresponding to the value in the VERSION file. 13 | -------------------------------------------------------------------------------- /.expeditor/run_windows_tests.ps1: -------------------------------------------------------------------------------- 1 | # Stop script execution when a non-terminating error occurs 2 | $ErrorActionPreference = "Stop" 3 | # This will run ruby test on windows platform 4 | 5 | Write-Output "--- Bundle install" 6 | 7 | bundle config --local path vendor/bundle 8 | If ($lastexitcode -ne 0) { Exit $lastexitcode } 9 | 10 | bundle install --jobs=7 --retry=3 11 | If ($lastexitcode -ne 0) { Exit $lastexitcode } 12 | 13 | Write-Output "--- Bundle Execute" 14 | 15 | bundle exec rake 16 | If ($lastexitcode -ne 0) { Exit $lastexitcode } 17 | -------------------------------------------------------------------------------- /mixlib-log.gemspec: -------------------------------------------------------------------------------- 1 | $:.unshift File.expand_path("lib", __dir__) 2 | require "mixlib/log/version" 3 | 4 | Gem::Specification.new do |gem| 5 | gem.name = "mixlib-log" 6 | gem.version = Mixlib::Log::VERSION 7 | gem.summary = "A gem that provides a simple mixin for log functionality" 8 | gem.email = "info@chef.io" 9 | gem.homepage = "https://github.com/chef/mixlib-log" 10 | gem.license = "Apache-2.0" 11 | gem.authors = ["Chef Software, Inc."] 12 | gem.files = %w{LICENSE} + Dir.glob("lib/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) } 13 | gem.require_paths = ["lib"] 14 | gem.required_ruby_version = ">= 3.1" 15 | 16 | gem.add_dependency "ffi", ">= 1.15.5" 17 | end 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/BUG_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: � Bug Report 3 | about: If something isn't working as expected �. 4 | labels: "Status: Untriaged, Type: Bug" 5 | --- 6 | 7 | # Version: 8 | 9 | [Version of the project installed] 10 | 11 | # Environment: 12 | 13 | [Details about the environment such as the Operating System, cookbook details, etc...] 14 | 15 | # Scenario: 16 | 17 | [What you are trying to achieve and you can't?] 18 | 19 | # Steps to Reproduce: 20 | 21 | [If you are filing an issue what are the things we need to do in order to repro your problem?] 22 | 23 | # Expected Result: 24 | 25 | [What are you expecting to happen as the consequence of above reproduction steps?] 26 | 27 | # Actual Result: 28 | 29 | [What actually happens after the reproduction steps?] 30 | -------------------------------------------------------------------------------- /features/support/logit.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Adam Jacob () 3 | # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. 4 | # License:: Apache License, Version 2.0 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | class Logit 20 | extend Mixlib::Log 21 | end 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/ENHANCEMENT_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🚀 Enhancement Request 3 | about: I have a suggestion (and may want to implement it 🙂)! 4 | labels: "Status: Untriaged" 5 | --- 6 | 7 | ### Describe the Enhancement: 8 | 9 | 10 | ### Describe the Need: 11 | 12 | 13 | ### Current Alternative 14 | 15 | 16 | ### Can We Help You Implement This?: 17 | 18 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | ============ 2 | Mixin::Log Notices 3 | ============ 4 | 5 | Developed at Chef (http://www.chef.io). 6 | 7 | 8 | * Copyright 2009-2016, Chef Software, Inc. 9 | 10 | Mixin::Log incorporates code from Chef. The Chef notice file follows: 11 | 12 | ============ 13 | Chef Notices 14 | ============ 15 | 16 | Developed at Chef (http://www.chef.io). 17 | 18 | Contributors and Copyright holders: 19 | 20 | * Copyright 2008, Adam Jacob 21 | * Copyright 2008, Arjuna Christensen 22 | * Copyright 2008, Bryan McLellan 23 | * Copyright 2008, Ezra Zygmuntowicz 24 | * Copyright 2009, Sean Cribbs 25 | * Copyright 2009, Christopher Brown 26 | * Copyright 2009, Thom May 27 | 28 | Chef incorporates code modified from Open4 (http://www.codeforpeople.com/lib/ruby/open4/), which was written by Ara T. Howard. 29 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Adam Jacob () 3 | # Author:: Christopher Brown () 4 | # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. 5 | # License:: Apache License, Version 2.0 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | $TESTING = true 21 | 22 | require "rspec" 23 | require "mixlib/log" 24 | require "mixlib/log/formatter" 25 | 26 | RSpec.configure(&:disable_monkey_patching!) 27 | 28 | class Logit 29 | extend Mixlib::Log 30 | end 31 | -------------------------------------------------------------------------------- /spec/mixlib/log/logger_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright:: Copyright (c) 2024 Chef Software, Inc. 2 | # License:: Apache License, Version 2.0 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | require "spec_helper" 18 | 19 | RSpec.describe Mixlib::Log::Logger do 20 | let(:io) { StringIO.new } 21 | 22 | subject { described_class.new(io) } 23 | 24 | it "logs a info message in text format" do 25 | subject.info("test message") 26 | 27 | expect(io.string).to match(/INFO: test message/) 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /.expeditor/verify.pipeline.yml: -------------------------------------------------------------------------------- 1 | --- 2 | expeditor: 3 | cached_folders: 4 | - vendor 5 | defaults: 6 | buildkite: 7 | timeout_in_minutes: 60 8 | 9 | steps: 10 | 11 | - label: run-lint-and-specs-ruby-3.1 12 | command: 13 | - .expeditor/run_linux_tests.sh rake 14 | expeditor: 15 | executor: 16 | docker: 17 | image: ruby:3.1 18 | 19 | - label: run-lint-and-specs-ruby-3.4 20 | command: 21 | - .expeditor/run_linux_tests.sh rake 22 | expeditor: 23 | executor: 24 | docker: 25 | image: ruby:3.4 26 | 27 | - label: run-specs-ruby-3.1-windows 28 | command: 29 | - .expeditor/run_windows_tests.ps1 30 | expeditor: 31 | executor: 32 | docker: 33 | host_os: windows 34 | shell: ["powershell", "-Command"] 35 | image: rubydistros/windows-2019:3.1 36 | user: 'NT AUTHORITY\SYSTEM' 37 | 38 | - label: run-specs-ruby-3.4-windows 39 | command: 40 | - .expeditor/run_windows_tests.ps1 41 | expeditor: 42 | executor: 43 | docker: 44 | host_os: windows 45 | shell: ["powershell", "-Command"] 46 | image: rubydistros/windows-2019:3.4 47 | user: 'NT AUTHORITY\SYSTEM' 48 | -------------------------------------------------------------------------------- /features/support/env.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Adam Jacob () 3 | # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. 4 | # License:: Apache License, Version 2.0 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | $: << File.join(File.dirname(__FILE__), "..", "..", "lib") 20 | 21 | require "rspec/expectations" 22 | require "mixlib/log" 23 | require "tmpdir" 24 | require "stringio" 25 | 26 | class MyWorld 27 | def initialize 28 | @tmpdir = File.join(Dir.tmpdir, "mixlib_log") 29 | @output = "" 30 | @output_io = StringIO.new(@output) 31 | Logit.init(@output_io) 32 | end 33 | end 34 | 35 | World do 36 | MyWorld.new 37 | end 38 | 39 | Before do 40 | system("mkdir -p #{@tmpdir}") 41 | end 42 | 43 | After do 44 | system("rm -rf #{@tmpdir}") 45 | end 46 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler" 2 | 3 | begin 4 | require "cucumber/rake/task" 5 | 6 | Cucumber::Rake::Task.new(:features) do |t| 7 | t.cucumber_opts = "--format pretty" 8 | t.bundler = false 9 | end 10 | rescue LoadError 11 | desc "cucumber is not installed, this task is disabled" 12 | task :spec do 13 | abort "cucumber is not installed. bundle install first to make sure all dependencies are installed." 14 | end 15 | end 16 | 17 | begin 18 | require "rspec/core/rake_task" 19 | 20 | RSpec::Core::RakeTask.new do |t| 21 | t.pattern = "spec/**/*_spec.rb" 22 | end 23 | rescue LoadError 24 | desc "rspec is not installed, this task is disabled" 25 | task :spec do 26 | abort "rspec is not installed. bundle install first to make sure all dependencies are installed." 27 | end 28 | end 29 | 30 | begin 31 | require "cookstyle/chefstyle" 32 | require "rubocop/rake_task" 33 | desc "Run Chefstyle tests" 34 | RuboCop::RakeTask.new(:style) do |task| 35 | task.options += ["--display-cop-names", "--no-color"] 36 | end 37 | rescue LoadError 38 | puts "cookstyle gem is not installed. bundle install first to make sure all dependencies are installed." 39 | end 40 | 41 | task :console do 42 | require "irb" 43 | require "irb/completion" 44 | require "mixlib/log" 45 | ARGV.clear 46 | IRB.start 47 | end 48 | 49 | task default: %i{style spec features} 50 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/DESIGN_PROPOSAL.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Design Proposal 3 | about: I have a significant change I would like to propose and discuss before starting 4 | labels: "Status: Untriaged, Type: Design Proposal" 5 | --- 6 | 7 | ### When a Change Needs a Design Proposal 8 | 9 | A design proposal should be opened any time a change meets one of the following qualifications: 10 | 11 | - Significantly changes the user experience of a project in a way that impacts users. 12 | - Significantly changes the underlying architecture of the project in a way that impacts other developers. 13 | - Changes the development or testing process of the project such as a change of CI systems or test frameworks. 14 | 15 | ### Why We Use This Process 16 | 17 | - Allows all interested parties (including any community member) to discuss large impact changes to a project. 18 | - Serves as a durable paper trail for discussions regarding project architecture. 19 | - Forces design discussions to occur before PRs are created. 20 | - Reduces PR refactoring and rejected PRs. 21 | 22 | --- 23 | 24 | 25 | 26 | ## Motivation 27 | 28 | 33 | 34 | ## Specification 35 | 36 | 37 | 38 | ## Downstream Impact 39 | 40 | 41 | -------------------------------------------------------------------------------- /features/steps/log.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Adam Jacob () 3 | # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. 4 | # License:: Apache License, Version 2.0 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | Given(/^a base log level of '(.+)'$/) do |level| 20 | Logit.level = level.to_sym 21 | end 22 | 23 | When(/^the message '(.+)' is sent at the '(.+)' level$/) do |message, level| 24 | case level.to_sym 25 | when :debug 26 | Logit.debug(message) 27 | when :info 28 | Logit.info(message) 29 | when :warn 30 | Logit.warn(message) 31 | when :error 32 | Logit.error(message) 33 | when :fatal 34 | Logit.fatal(message) 35 | else 36 | raise ArgumentError, "Level is not one of debug, info, warn, error, or fatal" 37 | end 38 | end 39 | 40 | Then(/^the regex '(.+)' should be logged$/) do |regex_string| 41 | regex = Regexp.new(regex_string, Regexp::MULTILINE) 42 | expect(regex.match(@output)).not_to be_nil 43 | end 44 | 45 | Then(/^nothing should be logged$/) do 46 | expect(@output).to eq "" 47 | end 48 | -------------------------------------------------------------------------------- /features/log.feature: -------------------------------------------------------------------------------- 1 | Feature: Log output 2 | In order to keep a record of application specific information 3 | As a developer 4 | I want to publish information through a configurable log interface 5 | 6 | Scenario: Log a message at the debug level 7 | Given a base log level of 'debug' 8 | When the message 'this goes out' is sent at the 'debug' level 9 | Then the regex '\[.+\] DEBUG: this goes out' should be logged 10 | 11 | Scenario: Log a message at the info level 12 | Given a base log level of 'info' 13 | When the message 'this goes out' is sent at the 'info' level 14 | Then the regex '\[.+\] INFO: this goes out' should be logged 15 | 16 | Scenario: Log a message at the warn level 17 | Given a base log level of 'warn' 18 | When the message 'this goes out' is sent at the 'warn' level 19 | Then the regex '\[.+\] WARN: this goes out' should be logged 20 | 21 | Scenario: Log a message at the error level 22 | Given a base log level of 'error' 23 | When the message 'this goes out' is sent at the 'error' level 24 | Then the regex '\[.+\] ERROR: this goes out' should be logged 25 | 26 | Scenario: Log a message at the fatal level 27 | Given a base log level of 'fatal' 28 | When the message 'this goes out' is sent at the 'fatal' level 29 | Then the regex '\[.+\] FATAL: this goes out' should be logged 30 | 31 | Scenario: Log messages below the current threshold should not appear 32 | Given a base log level of 'fatal' 33 | When the message 'this goes out' is sent at the 'error' level 34 | And the message 'this goes out' is sent at the 'warn' level 35 | And the message 'this goes out' is sent at the 'info' level 36 | And the message 'this goes out' is sent at the 'debug' level 37 | Then nothing should be logged 38 | -------------------------------------------------------------------------------- /.expeditor/config.yml: -------------------------------------------------------------------------------- 1 | # Documentation available at https://expeditor.chef.io/docs/getting-started/ 2 | --- 3 | 4 | # Slack channel in Chef Software slack to send notifications about build failures, etc 5 | slack: 6 | notify_channel: chef-found-notify 7 | 8 | # This publish is triggered by the `built_in:publish_rubygems` artifact_action. 9 | rubygems: 10 | - mixlib-log 11 | 12 | github: 13 | # This deletes the GitHub PR branch after successfully merged into the release branch 14 | delete_branch_on_merge: true 15 | # The tag format to use (e.g. v1.0.0) 16 | version_tag_format: "v{{version}}" 17 | # allow bumping the minor release via label 18 | minor_bump_labels: 19 | - "Expeditor: Bump Version Minor" 20 | # allow bumping the major release via label 21 | major_bump_labels: 22 | - "Expeditor: Bump Version Major" 23 | 24 | changelog: 25 | rollup_header: Changes not yet released to rubygems.org 26 | 27 | subscriptions: 28 | # These actions are taken, in order they are specified, anytime a Pull Request is merged. 29 | - workload: pull_request_merged:{{github_repo}}:{{release_branch}}:* 30 | actions: 31 | - built_in:bump_version: 32 | ignore_labels: 33 | - "Expeditor: Skip Version Bump" 34 | - "Expeditor: Skip All" 35 | - bash:.expeditor/update_version.sh: 36 | only_if: built_in:bump_version 37 | - built_in:update_changelog: 38 | ignore_labels: 39 | - "Expeditor: Skip Changelog" 40 | - "Expeditor: Skip All" 41 | - built_in:build_gem: 42 | only_if: built_in:bump_version 43 | - workload: project_promoted:{{agent_id}}:* 44 | actions: 45 | - built_in:rollover_changelog 46 | - built_in:publish_rubygems 47 | 48 | pipelines: 49 | - verify: 50 | description: Pull Request validation tests 51 | public: true 52 | -------------------------------------------------------------------------------- /lib/mixlib/log/logging.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: Copyright (c) 2018 Chef Software, Inc. 3 | # License:: Apache License, Version 2.0 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | require "logger" 18 | 19 | module Mixlib 20 | module Log 21 | module Logging 22 | include ::Logger::Severity 23 | 24 | TRACE = -1 25 | 26 | SEV_LABEL = %w{TRACE DEBUG INFO WARN ERROR FATAL ANY}.each(&:freeze).freeze 27 | 28 | def to_label(sev) 29 | SEV_LABEL[sev + 1] || -"ANY" 30 | end 31 | 32 | LEVELS = { trace: TRACE, debug: DEBUG, info: INFO, warn: WARN, error: ERROR, fatal: FATAL }.freeze 33 | LEVEL_NAMES = LEVELS.invert.freeze 34 | 35 | attr_accessor :metadata 36 | 37 | def pass(severity, args, progname = nil, data: {}, &block) 38 | args, progname, data = yield if block_given? 39 | add(severity, args, progname, data: data) 40 | end 41 | 42 | # Define the standard logger methods on this class programmatically. 43 | # No need to incur method_missing overhead on every log call. 44 | %i{trace debug info warn error fatal}.each do |method_name| 45 | level = LEVELS[method_name] 46 | define_method(method_name) do |msg = nil, data: {}, &block| 47 | pass(level, msg, data: data, &block) 48 | nil 49 | end 50 | end 51 | 52 | end 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mixlib::Log 2 | 3 | [![Gem Version](https://badge.fury.io/rb/mixlib-log.svg)](https://badge.fury.io/rb/mixlib-log) 4 | [![Build status](https://badge.buildkite.com/cb1e5b6f3cc77071f4b2315f6b605fe60d86e2862a490873d4.svg?branch=master)](https://buildkite.com/chef-oss/chef-mixlib-log-master-verify) 5 | 6 | Mixlib::Log provides a mixin for enabling a class based logger object, a-la Merb, Chef, and Nanite. To use it: 7 | 8 | ```ruby 9 | require 'mixlib/log' 10 | 11 | class Log 12 | extend Mixlib::Log 13 | end 14 | ``` 15 | 16 | You can then do: 17 | 18 | ```ruby 19 | Log.debug('foo') 20 | Log.info('bar') 21 | Log.warn('baz') 22 | Log.error('baz') 23 | Log.fatal('wewt') 24 | ``` 25 | 26 | 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: 27 | 28 | ```ruby 29 | Log.init('/tmp/logfile') # log to /tmp/logfile 30 | Log.init('/tmp/logfile', 7) # log to /tmp/logfile, rotate every day 31 | ``` 32 | 33 | Enjoy! 34 | 35 | ## Documentation 36 | 37 | All documentation is written using YARD. You can generate a by running: 38 | 39 | ``` 40 | rake docs 41 | ``` 42 | 43 | ## Contributing 44 | 45 | For information on contributing to this project please see our [Contributing Documentation](https://github.com/chef/chef/blob/master/CONTRIBUTING.md) 46 | 47 | ## License & Copyright 48 | 49 | - Copyright:: Copyright (c) 2008-2019 Chef Software, Inc. 50 | - License:: Apache License, Version 2.0 51 | 52 | ```text 53 | Licensed under the Apache License, Version 2.0 (the "License"); 54 | you may not use this file except in compliance with the License. 55 | You may obtain a copy of the License at 56 | 57 | http://www.apache.org/licenses/LICENSE-2.0 58 | 59 | Unless required by applicable law or agreed to in writing, software 60 | distributed under the License is distributed on an "AS IS" BASIS, 61 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 62 | See the License for the specific language governing permissions and 63 | limitations under the License. 64 | ``` 65 | -------------------------------------------------------------------------------- /lib/mixlib/log/child.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: Copyright (c) 2018 Chef Software, Inc. 3 | # License:: Apache License, Version 2.0 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | require_relative "logging" 18 | 19 | module Mixlib 20 | module Log 21 | class Child 22 | include Mixlib::Log::Logging 23 | 24 | attr_reader :parent 25 | attr_accessor :metadata 26 | def initialize(parent, metadata = {}) 27 | @parent = parent 28 | @metadata = metadata 29 | end 30 | 31 | def level 32 | parent.level 33 | end 34 | 35 | # Define the methods to interrogate the logger for the current log level. 36 | # Note that we *only* query the default logger (@logger) and not any other 37 | # loggers that may have been added, even though it is possible to configure 38 | # two (or more) loggers at different log levels. 39 | %i{trace? debug? info? warn? error? fatal?}.each do |method_name| 40 | define_method(method_name) do 41 | parent.send(method_name) 42 | end 43 | end 44 | 45 | def add(severity, message = nil, progname = nil, data: {}, &block) 46 | data = metadata.merge(data) if data.is_a?(Hash) 47 | parent.send(:pass, severity, message, progname, data: data, &block) 48 | end 49 | 50 | def with_child(metadata = {}) 51 | child = Child.new(self, metadata) 52 | if block_given? 53 | yield child 54 | else 55 | child 56 | end 57 | end 58 | 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /lib/mixlib/log/formatter.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Adam Jacob () 3 | # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. 4 | # License:: Apache License, Version 2.0 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | require "logger" 19 | require "time" unless defined?(Time.zone_offset) 20 | 21 | module Mixlib 22 | module Log 23 | class Formatter < Logger::Formatter 24 | @@show_time = true 25 | 26 | def self.show_time=(show = false) 27 | @@show_time = show 28 | end 29 | 30 | # Prints a log message as '[time] severity: message' if Chef::Log::Formatter.show_time == true. 31 | # Otherwise, doesn't print the time. 32 | def call(severity, time, progname, msg) 33 | if @@show_time 34 | sprintf("[%s] %s: %s\n", time.iso8601, severity, msg2str(msg)) 35 | else 36 | sprintf("%s: %s\n", severity, msg2str(msg)) 37 | end 38 | end 39 | 40 | # Converts some argument to a Logger.severity() call to a string. Regular strings pass through like 41 | # normal, Exceptions get formatted as "message (class)\nbacktrace", and other random stuff gets 42 | # put through "object.inspect" 43 | def msg2str(msg) 44 | case msg 45 | when ::Hash 46 | if msg.has_key?(:err) 47 | format_exception(msg[:err]) 48 | else 49 | msg[:msg] 50 | end 51 | when ::String 52 | msg 53 | when ::Exception 54 | format_exception(msg) 55 | else 56 | msg.inspect 57 | end 58 | end 59 | 60 | def format_exception(msg) 61 | "#{msg.message} (#{msg.class})\n" << 62 | (msg.backtrace || []).join("\n") 63 | end 64 | end 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /spec/mixlib/log/formatter_spec.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Adam Jacob () 3 | # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. 4 | # License:: Apache License, Version 2.0 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | require "time" unless defined?(Time.zone_offset) 20 | require "spec_helper" 21 | 22 | RSpec.describe Mixlib::Log::Formatter do 23 | before(:each) do 24 | @formatter = Mixlib::Log::Formatter.new 25 | end 26 | 27 | it "should print raw strings with msg2str(string)" do 28 | expect(@formatter.msg2str("nuthin new")).to eq("nuthin new") 29 | end 30 | 31 | it "should format exceptions properly with msg2str(e)" do 32 | e = IOError.new("legendary roots crew") 33 | expect(@formatter.msg2str(e)).to eq("legendary roots crew (IOError)\n") 34 | end 35 | 36 | it "should format random objects via inspect with msg2str(Object)" do 37 | expect(@formatter.msg2str([ "black thought", "?uestlove" ])).to eq('["black thought", "?uestlove"]') 38 | end 39 | 40 | it "should return a formatted string with call" do 41 | time = Time.new 42 | Mixlib::Log::Formatter.show_time = true 43 | expect(@formatter.call("monkey", time, "test", "mos def")).to eq("[#{time.iso8601}] monkey: mos def\n") 44 | end 45 | 46 | it "should allow you to turn the time on and off in the output" do 47 | Mixlib::Log::Formatter.show_time = false 48 | expect(@formatter.call("monkey", Time.new, "test", "mos def")).to eq("monkey: mos def\n") 49 | end 50 | 51 | context "with structured data" do 52 | let(:data) { {} } 53 | 54 | it "should format a message" do 55 | data[:msg] = "nuthin new" 56 | expect(@formatter.msg2str(data)).to eq("nuthin new") 57 | end 58 | 59 | it "should format an exception" do 60 | data[:err] = IOError.new("legendary roots crew") 61 | expect(@formatter.msg2str(data)).to eq("legendary roots crew (IOError)\n") 62 | end 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /lib/mixlib/log/logger.rb: -------------------------------------------------------------------------------- 1 | require "logger" 2 | require_relative "logging" 3 | 4 | # A subclass of Ruby's stdlib Logger with all the mutex and logrotation stuff 5 | # ripped out, and metadata added in. 6 | module Mixlib 7 | module Log 8 | class Logger < ::Logger 9 | 10 | include Logging 11 | 12 | def trace?; @level <= TRACE; end 13 | 14 | # 15 | # === Synopsis 16 | # 17 | # Logger.new(name, shift_age = 7, shift_size = 1048576) 18 | # Logger.new(name, shift_age = 'weekly') 19 | # 20 | # === Args 21 | # 22 | # +logdev+:: 23 | # The log device. This is a filename (String) or IO object (typically 24 | # +$stdout+, +$stderr+, or an open file). 25 | # +shift_age+:: 26 | # Number of old log files to keep, *or* frequency of rotation (+daily+, 27 | # +weekly+ or +monthly+). 28 | # +shift_size+:: 29 | # Maximum logfile size (only applies when +shift_age+ is a number). 30 | # 31 | # === Description 32 | # 33 | # Create an instance. 34 | # 35 | def initialize(logdev) 36 | super(nil, formatter: ::Mixlib::Log::Formatter.new) 37 | if logdev 38 | @logdev = LocklessLogDevice.new(logdev) 39 | end 40 | end 41 | 42 | def add_data(severity, message, progname, data: {}) 43 | return true if @logdev.nil? || severity < @level 44 | 45 | data ||= {} 46 | if message.is_a?(::Exception) 47 | data[:err] = message 48 | else 49 | data[:msg] = message 50 | end 51 | @logdev.write( 52 | format_message(to_label(severity), Time.now, progname, data) 53 | ) 54 | true 55 | end 56 | alias_method :add, :add_data 57 | 58 | class LocklessLogDevice < LogDevice 59 | 60 | def initialize(log = nil) 61 | @dev = @filename = @shift_age = @shift_size = nil 62 | if log.respond_to?(:write) && log.respond_to?(:close) 63 | @dev = log 64 | else 65 | @dev = open_logfile(log) 66 | @filename = log 67 | end 68 | @dev.sync = true 69 | end 70 | 71 | def write(message) 72 | @dev.write(message) 73 | rescue Exception => ignored 74 | warn("log writing failed. #{ignored}") 75 | end 76 | 77 | def close 78 | @dev.close rescue nil 79 | end 80 | 81 | private 82 | 83 | def open_logfile(filename) 84 | if FileTest.exist?(filename) 85 | open(filename, (File::WRONLY | File::APPEND)) 86 | else 87 | create_logfile(filename) 88 | end 89 | end 90 | 91 | def create_logfile(filename) 92 | logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT)) 93 | add_log_header(logdev) 94 | logdev 95 | end 96 | 97 | def add_log_header(file) 98 | file.write( 99 | "# Logfile created on %s by %s\n" % [Time.now.to_s, Logger::ProgName] 100 | ) 101 | end 102 | 103 | end 104 | 105 | end 106 | end 107 | end 108 | -------------------------------------------------------------------------------- /spec/mixlib/log/child_spec.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: Copyright (c) 2018 Chef Software, Inc. 3 | # License:: Apache License, Version 2.0 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | require "tempfile" unless defined?(Tempfile) 19 | require "stringio" unless defined?(StringIO) 20 | require "spec_helper" 21 | 22 | RSpec.describe Mixlib::Log::Child do 23 | before do 24 | Logit.reset! 25 | Logit.init(io) 26 | Logit.level = :warn 27 | end 28 | 29 | let(:io) { StringIO.new } 30 | 31 | let(:child) { Logit.with_child } 32 | 33 | it "has a parent" do 34 | expect(child.parent).to be(Logit) 35 | end 36 | 37 | it "accepts a message" do 38 | Logit.with_child { |l| l.add(Logger::WARN, "a message") } 39 | expect(io.string).to match(/a message$/) 40 | end 41 | 42 | context "with structured data" do 43 | it "can be created with metadata" do 44 | expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true" }) 45 | Logit.with_child({ child: "true" }) { |l| l.warn("a message") } 46 | end 47 | 48 | it "a message can be logged" do 49 | expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true" }) 50 | Logit.with_child { |l| l.warn("a message", data: { child: "true" }) } 51 | end 52 | 53 | context "merges properly" do 54 | it "in the simple case" do 55 | expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true", meta: "data" }) 56 | Logit.with_child(meta: "data") { |l| l.warn("a message", data: { child: "true" }) } 57 | end 58 | 59 | it "when overwriting" do 60 | expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true", meta: "overwritten" }) 61 | Logit.with_child(meta: "data") { |l| l.warn("a message", data: { child: "true", meta: "overwritten" }) } 62 | end 63 | end 64 | 65 | context "when receiving a message from a child" do 66 | it "passes data on" do 67 | expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true", parent: "first" }) 68 | child.metadata = { parent: "first" } 69 | child.with_child { |l| l.warn("a message", data: { child: "true" }) } 70 | end 71 | 72 | it "merges its own data" do 73 | expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true", parent: "second" }) 74 | child.metadata = { parent: "first" } 75 | child.with_child { |l| l.warn("a message", data: { child: "true", parent: "second" }) } 76 | end 77 | end 78 | end 79 | 80 | context "sends a message to the parent" do 81 | %i{ debug info warn error fatal }.each do |level| 82 | it "at #{level}" do 83 | expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[level], "a #{level} message", nil, data: {}) 84 | Logit.level = level 85 | child.send(level, "a #{level} message") 86 | end 87 | end 88 | end 89 | 90 | context "can query the parent's level" do 91 | %i{ debug info warn error fatal }.each do |level| 92 | it "at #{level}" do 93 | query = "#{level}?".to_sym 94 | Logit.level = level 95 | expect(child.send(query)).to be(true) 96 | end 97 | end 98 | end 99 | end 100 | -------------------------------------------------------------------------------- /.github/workflows/ci-main-pull-request-checks.yml: -------------------------------------------------------------------------------- 1 | # stub to call common GitHub Action (GA) as part of Continuous Integration (CI) Pull Request process checks for main branch 2 | # 3 | # inputs are described in the /common-github-actions/ with same name as this stub 4 | # 5 | 6 | name: CI Pull Request on Main Branch 7 | 8 | on: 9 | pull_request: 10 | branches: [ main, release/** ] 11 | push: 12 | branches: [ main, release/** ] 13 | 14 | workflow_dispatch: 15 | 16 | permissions: 17 | contents: read 18 | 19 | env: 20 | STUB_VERSION: "1.0.1" 21 | 22 | jobs: 23 | echo_version: 24 | name: 'Echo stub version' 25 | runs-on: ubuntu-latest 26 | steps: 27 | - name: echo version of stub and inputs 28 | run: | 29 | echo "[ci-main-pull-request-stub-trufflehog-only.yml] version $STUB_VERSION" 30 | 31 | call-ci-main-pr-check-pipeline: 32 | uses: chef/common-github-actions/.github/workflows/ci-main-pull-request.yml@main 33 | secrets: inherit 34 | permissions: 35 | id-token: write 36 | contents: read 37 | 38 | with: 39 | visibility: ${{ github.event.repository.visibility }} # private, public, or internal 40 | # go-private-modules: GOPRIVATE for Go private modules, default is 'github.com/progress-platform-services/* 41 | 42 | # complexity-checks 43 | perform-complexity-checks: true 44 | # scc-output-filename: 'scc-output.txt' 45 | perform-language-linting: false # Perform language-specific linting and pre-compilation checks 46 | 47 | # trufflehog secret scanning 48 | perform-trufflehog-scan: true 49 | 50 | # BlackDuck SAST (Polaris) and SCA scans 51 | # requires secrets POLARIS_SERVER_URL and POLARIS_ACCESS_TOKEN 52 | perform-blackduck-polaris: false 53 | polaris-application-name: 'Chef-Chef360' # one of these: Chef-Agents, Chef-Automate, Chef-Chef360, Chef-Habitat, Chef-Infrastructure-Server, Chef-Shared-Services 54 | polaris-project-name: ${{ github.event.repository.name }} # typically the application name, followed by - and the repository name, for example Chef-Chef360-chef-vault' 55 | perform-blackduck-sca-scan: false 56 | 57 | # perform application build and unit testing, will use custom repository properties when implemented for chef-primary-application, chef-build-profile, and chef-build-language 58 | build: false 59 | # ga-build-profile: $chef-ga-build-profile 60 | # language: $chef-ga-build-language # this will be removed from stub as autodetected in central GA 61 | unit-tests: false 62 | 63 | # perform SonarQube scan, with or wihout unit test coverage data 64 | # requires secrets SONAR_TOKEN and SONAR_HOST_URL (progress.sonar.com) 65 | perform-sonarqube-scan: false 66 | # perform-sonar-build: true 67 | # build-profile: 'default' 68 | # report-unit-test-coverage: true 69 | 70 | # report to central developer dashboard 71 | report-to-atlassian-dashboard: false 72 | quality-product-name: ${{ github.event.repository.name }} # like 'Chef-360' - the product name for quality reporting, like Chef360, Courier, Inspec 73 | # quality-sonar-app-name: 'YourSonarAppName' 74 | # quality-testing-type: 'Integration' like Unit, Integration, e2e, api, Performance, Security 75 | # quality-service-name: 'YourServiceOrRepoName' 76 | # quality-junit-report: 'path/to/junit/report'' 77 | 78 | # perform native and Habitat packaging, publish to package repositories 79 | package-binaries: false # Package binaries (e.g., RPM, DEB, MSI, dpkg + signing + SHA) 80 | habitat-build: false # Create Habitat packages 81 | publish-packages: false # Publish packages (e.g., container from Dockerfile to ECR, go-releaser binary to releases page, omnibus to artifactory, gems, choco, homebrew, other app stores) 82 | 83 | # generate and export Software Bill of Materials (SBOM) in various formats 84 | generate-sbom: true 85 | export-github-sbom: true # SPDX JSON artifact on job instance 86 | generate-blackduck-sbom: false # requires BlackDuck secrets and inputs as above for SAST scanning 87 | generate-msft-sbom: false 88 | license_scout: false # Run license scout for license compliance (uses .license_scout.yml) 89 | 90 | # udf1: 'default' # user defined flag 1 91 | # udf2: 'default' # user defined flag 2 92 | # udf3: 'default' # user defined flag 3 -------------------------------------------------------------------------------- /lib/mixlib/log.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Adam Jacob () 3 | # Author:: Christopher Brown () 4 | # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. 5 | # License:: Apache License, Version 2.0 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | 19 | require "logger" 20 | require_relative "log/version" 21 | require_relative "log/formatter" 22 | require_relative "log/child" 23 | require_relative "log/logging" 24 | require_relative "log/logger" 25 | 26 | module Mixlib 27 | module Log 28 | 29 | include Logging 30 | 31 | def reset! 32 | @logger ||= nil 33 | @loggers ||= [] 34 | close! 35 | @logger = @loggers = nil 36 | @metadata = {} 37 | end 38 | 39 | # An Array of log devices that will be logged to. Defaults to just the default 40 | # \@logger log device, but you can push to this array to add more devices. 41 | def loggers 42 | @loggers ||= [logger] 43 | end 44 | 45 | ## 46 | # init always returns a configured logger 47 | # and creates a new one if it doesn't yet exist 48 | ## 49 | def logger 50 | @logger ||= init 51 | end 52 | 53 | # Sets the log device to +new_log_device+. Any additional loggers 54 | # that had been added to the +loggers+ array will be cleared. 55 | def logger=(new_log_device) 56 | reset! 57 | @logger = new_log_device 58 | end 59 | 60 | def use_log_devices(other) 61 | if other.respond_to?(:loggers) && other.respond_to?(:logger) 62 | @loggers = other.loggers 63 | @logger = other.logger 64 | elsif other.is_a?(Array) 65 | @loggers = other 66 | @logger = other.first 67 | else 68 | msg = "#use_log_devices takes a Mixlib::Log object or array of log devices. " << 69 | "You gave: #{other.inspect}" 70 | raise ArgumentError, msg 71 | end 72 | @configured = true 73 | end 74 | 75 | # Use Mixlib::Log.init when you want to set up the logger manually. Arguments to this method 76 | # get passed directly to Logger.new, so check out the documentation for the standard Logger class 77 | # to understand what to do here. 78 | # 79 | # If this method is called with no arguments, it will log to STDOUT at the :warn level. 80 | # 81 | # It also configures the Logger instance it creates to use the custom Mixlib::Log::Formatter class. 82 | def init(*opts) 83 | reset! 84 | @logger = logger_for(*opts) 85 | @logger.formatter = Mixlib::Log::Formatter.new if @logger.respond_to?(:formatter=) 86 | @logger.level = Logger::WARN 87 | @configured = true 88 | @parent = nil 89 | @metadata = {} 90 | @logger 91 | end 92 | 93 | # Let the application query if logging objects have been set up 94 | def configured? 95 | @configured 96 | end 97 | 98 | attr_accessor :metadata 99 | 100 | # Sets the level for the Logger object by symbol. Valid arguments are: 101 | # 102 | # :trace 103 | # :debug 104 | # :info 105 | # :warn 106 | # :error 107 | # :fatal 108 | # 109 | # Throws an ArgumentError if you feed it a bogus log level. 110 | def level=(new_level) 111 | level_int = LEVEL_NAMES.key?(new_level) ? new_level : LEVELS[new_level] 112 | raise ArgumentError, "Log level must be one of :trace, :debug, :info, :warn, :error, or :fatal" if level_int.nil? 113 | 114 | loggers.each { |l| l.level = level_int } 115 | end 116 | 117 | def level(new_level = nil) 118 | if new_level.nil? 119 | LEVEL_NAMES[logger.level] 120 | else 121 | self.level = new_level 122 | end 123 | end 124 | 125 | # Define the methods to interrogate the logger for the current log level. 126 | # Note that we *only* query the default logger (@logger) and not any other 127 | # loggers that may have been added, even though it is possible to configure 128 | # two (or more) loggers at different log levels. 129 | %i{trace? debug? info? warn? error? fatal?}.each do |method_name| 130 | define_method(method_name) do 131 | logger.send(method_name) 132 | end 133 | end 134 | 135 | def <<(msg) 136 | loggers.each { |l| l << msg } 137 | end 138 | 139 | def add(severity, message = nil, progname = nil, data: {}, &block) 140 | message, progname, data = yield if block_given? 141 | data = metadata.merge(data) if metadata.is_a?(Hash) && data.is_a?(Hash) 142 | loggers.each do |l| 143 | # if we don't have any metadata, let's not do the potentially expensive 144 | # merging and managing that this call requires 145 | if l.respond_to?(:add_data) && !data.nil? && !data.empty? 146 | l.add_data(severity, message, progname, data: data) 147 | else 148 | l.add(severity, message, progname) 149 | end 150 | end 151 | end 152 | 153 | alias :log :add 154 | 155 | def with_child(metadata = {}) 156 | child = Child.new(self, metadata) 157 | if block_given? 158 | yield child 159 | else 160 | child 161 | end 162 | end 163 | 164 | # Passes any other method calls on directly to the underlying Logger object created with init. If 165 | # this method gets hit before a call to Mixlib::Logger.init has been made, it will call 166 | # Mixlib::Logger.init() with no arguments. 167 | def method_missing(method_symbol, *args, &block) 168 | loggers.each { |l| l.send(method_symbol, *args, &block) } 169 | end 170 | 171 | private 172 | 173 | def logger_for(*opts) 174 | if opts.empty? 175 | Mixlib::Log::Logger.new($stdout) 176 | elsif LEVELS.keys.inject(true) { |quacks, level| quacks && opts.first.respond_to?(level) } 177 | opts.first 178 | else 179 | Mixlib::Log::Logger.new(*opts) 180 | end 181 | end 182 | 183 | def all_loggers 184 | [@logger, *@loggers].uniq 185 | end 186 | 187 | # select all loggers with File log devices 188 | def loggers_to_close 189 | loggers_to_close = [] 190 | all_loggers.each do |logger| 191 | # unfortunately Logger does not provide access to the logdev 192 | # via public API. In order to reduce amount of impact and 193 | # handle only File type log devices I had to use this method 194 | # to get access to it. 195 | next unless logger.instance_variable_defined?(:"@logdev") 196 | next unless (logdev = logger.instance_variable_get(:"@logdev")) 197 | 198 | loggers_to_close << logger if logdev.filename 199 | end 200 | loggers_to_close 201 | end 202 | 203 | def close! 204 | # try to close all file loggers 205 | loggers_to_close.each do |l| 206 | l.close rescue nil 207 | end 208 | end 209 | 210 | end 211 | end 212 | -------------------------------------------------------------------------------- /spec/mixlib/log_spec.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Adam Jacob () 3 | # Author:: Christopher Brown () 4 | # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. 5 | # License:: Apache License, Version 2.0 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | require "tempfile" unless defined?(Tempfile) 21 | require "stringio" unless defined?(StringIO) 22 | require "spec_helper" 23 | 24 | class LoggerLike 25 | attr_accessor :level 26 | attr_reader :messages, :data 27 | def initialize 28 | @messages = "" 29 | @data = [] 30 | end 31 | 32 | def add_data(severity, message = nil, progname = nil, data: {}) 33 | @messages << message 34 | @data << data 35 | end 36 | 37 | def add(severity, message = nil, progname = nil, data: {}) 38 | @messages << message 39 | end 40 | 41 | %i{trace debug info warn error fatal}.each do |method_name| 42 | class_eval(<<-E) 43 | def #{method_name}(message) 44 | @messages << message 45 | end 46 | E 47 | end 48 | end 49 | 50 | RSpec.describe Mixlib::Log do 51 | 52 | # Since we are testing class behaviour for an instance variable 53 | # that gets set once, we need to reset it prior to each example [cb] 54 | before(:each) do 55 | Logit.reset! 56 | end 57 | 58 | it "creates a logger using an IO object" do 59 | io = StringIO.new 60 | Logit.init(io) 61 | Logit << "foo" 62 | expect(io.string).to match(/foo/) 63 | end 64 | 65 | it "creates a logger with a file name" do 66 | Tempfile.open("chef-test-log") do |tempfile| 67 | Logit.init(tempfile.path) 68 | Logit << "bar" 69 | tempfile.rewind 70 | expect(tempfile.read).to match(/bar/) 71 | end 72 | end 73 | 74 | it "uses the logger provided when initialized with a logger like object" do 75 | logger = LoggerLike.new 76 | Logit.init(logger) 77 | Logit.level = :debug 78 | Logit.debug "qux" 79 | expect(logger.messages).to match(/qux/) 80 | end 81 | 82 | it "should re-initialize the logger if init is called again" do 83 | first_logdev, second_logdev = StringIO.new, StringIO.new 84 | Logit.init(first_logdev) 85 | Logit.fatal "FIRST" 86 | expect(first_logdev.string).to match(/FIRST/) 87 | Logit.init(second_logdev) 88 | Logit.fatal "SECOND" 89 | expect(first_logdev.string).to_not match(/SECOND/) 90 | expect(second_logdev.string).to match(/SECOND/) 91 | end 92 | 93 | it "knows that it's been configured" do 94 | Logit.init 95 | expect(Logit.configured?).to be true 96 | end 97 | 98 | it "should set the log level using the binding form, with :trace, :debug, :info, :warn, :error, or :fatal" do 99 | levels = { 100 | trace: Mixlib::Log::TRACE, 101 | debug: Mixlib::Log::DEBUG, 102 | info: Mixlib::Log::INFO, 103 | warn: Mixlib::Log::WARN, 104 | error: Mixlib::Log::ERROR, 105 | fatal: Mixlib::Log::FATAL, 106 | } 107 | levels.each do |symbol, constant| 108 | Logit.level = symbol 109 | expect(Logit.logger.level).to eq(constant) 110 | expect(Logit.level).to eq(symbol) 111 | end 112 | end 113 | 114 | it "passes blocks to the underlying logger object" do 115 | logdev = StringIO.new 116 | Logit.init(logdev) 117 | Logit.fatal { "the_message" } 118 | expect(logdev.string).to match(/the_message/) 119 | end 120 | 121 | it "should set the log level using the method form, with :trace, :debug, :info, :warn, :error, or :fatal" do 122 | levels = { 123 | trace: Mixlib::Log::TRACE, 124 | debug: Mixlib::Log::DEBUG, 125 | info: Mixlib::Log::INFO, 126 | warn: Mixlib::Log::WARN, 127 | error: Mixlib::Log::ERROR, 128 | fatal: Mixlib::Log::FATAL, 129 | } 130 | levels.each do |symbol, constant| 131 | Logit.level(symbol) 132 | expect(Logit.logger.level).to eq(constant) 133 | end 134 | end 135 | 136 | it "should raise an ArgumentError if you try and set the level to something strange using the binding form" do 137 | expect { Logit.level = :the_roots }.to raise_error(ArgumentError) 138 | end 139 | 140 | it "should raise an ArgumentError if you try and set the level to something strange using the method form" do 141 | expect { Logit.level(:the_roots) }.to raise_error(ArgumentError) 142 | end 143 | 144 | it "should pass other method calls directly to logger" do 145 | expect do 146 | # this needs to be inside of the block because the level setting 147 | # is causing the init, which grabs $stderr before rspec replaces 148 | # it for output testing. 149 | Logit.level = :debug 150 | expect(Logit).to be_debug 151 | Logit.debug("Gimme some sugar!") 152 | end.to output(/DEBUG: Gimme some sugar!/).to_stdout 153 | end 154 | 155 | it "should pass add method calls directly to logger" do 156 | logdev = StringIO.new 157 | Logit.init(logdev) 158 | Logit.level = :debug 159 | expect(Logit).to be_debug 160 | expect { Logit.add(Logger::DEBUG, "Gimme some sugar!") }.to_not raise_error 161 | expect(logdev.string).to match(/Gimme some sugar/) 162 | end 163 | 164 | it "should default to STDOUT if init is called with no arguments" do 165 | logger_mock = Struct.new(:formatter, :level).new 166 | # intentionally STDOUT to avoid unfailable test 167 | expect(Logger).to receive(:new).with(STDOUT).and_return(logger_mock) 168 | Logit.init 169 | end 170 | 171 | it "should have by default a base log level of warn" do 172 | logger_mock = Struct.new(:formatter, :level).new 173 | expect(Logger).to receive(:new).and_return(logger_mock) 174 | Logit.init 175 | expect(Logit.level).to eq(:warn) 176 | end 177 | 178 | it "should close File logger" do 179 | opened_files_count_before = 0 180 | ObjectSpace.each_object(File) do |f| 181 | opened_files_count_before += 1 unless f.closed? 182 | end 183 | name = File.join(Dir.tmpdir, "logger.log") 184 | Logit.init(name) 185 | Logit.init(name) 186 | Logit.init(name) 187 | opened_files_count_after = 0 188 | ObjectSpace.each_object(File) do |f| 189 | opened_files_count_after += 1 unless f.closed? 190 | end 191 | expect(opened_files_count_after).to eq(opened_files_count_before + 1) 192 | end 193 | 194 | it "should not close IO logger" do 195 | opened_files_count_before = 0 196 | ObjectSpace.each_object(File) do |f| 197 | opened_files_count_before += 1 unless f.closed? 198 | end 199 | Tempfile.open("chef-test-log") do |file| 200 | Logit.init(file) 201 | Logit.init(file) 202 | Logit.init(file) 203 | opened_files_count_after = 0 204 | ObjectSpace.each_object(File) do |f| 205 | opened_files_count_after += 1 unless f.closed? 206 | end 207 | expect(opened_files_count_after).to eq(opened_files_count_before + 1) 208 | end 209 | end 210 | 211 | it "should return nil from its logging methods" do 212 | # intentionally STDOUT to avoid unfailable test 213 | expect(Logger).to receive(:new).with(STDOUT) { double("a-quiet-logger").as_null_object } 214 | Logit.init 215 | 216 | aggregate_failures "returns nil from logging method" do 217 | expect(Logit.trace("hello")).to be_nil 218 | expect(Logit.debug("hello")).to be_nil 219 | expect(Logit.info("hello")).to be_nil 220 | expect(Logit.warn("hello")).to be_nil 221 | expect(Logit.error("hello")).to be_nil 222 | expect(Logit.fatal("hello")).to be_nil 223 | end 224 | end 225 | 226 | it "should set metadata correctly" do 227 | Logit.metadata = { test: "data" } 228 | expect(Logit.metadata).to eql({ test: "data" }) 229 | end 230 | 231 | it "should format :trace level messages with TRACE: label" do 232 | logdev = StringIO.new 233 | Logit.init(logdev) 234 | Logit.level = :trace 235 | Logit.trace("this is a log message") 236 | aggregate_failures do 237 | expect(logdev.string).to_not match(/ANY:/) 238 | expect(logdev.string).to match(/TRACE:/) 239 | end 240 | end 241 | end 242 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | 4 | ## [v3.2.9](https://github.com/chef/mixlib-log/tree/v3.2.9) (2025-11-14) 5 | 6 | #### Merged Pull Requests 7 | - set up ai assisted development workflow [#94](https://github.com/chef/mixlib-log/pull/94) ([rishichawda](https://github.com/rishichawda)) 8 | 9 | 10 | 11 | ### Changes not yet released to rubygems.org 12 | 13 | #### Merged Pull Requests 14 | - set up ai assisted development workflow [#94](https://github.com/chef/mixlib-log/pull/94) ([rishichawda](https://github.com/rishichawda)) 15 | - Add GitHub Security Actions Workflow [#89](https://github.com/chef/mixlib-log/pull/89) ([sean-sype-simmons](https://github.com/sean-sype-simmons)) 16 | - Update cucumber requirement from ~> 10.0.0 to ~> 10.1.0 [#91](https://github.com/chef/mixlib-log/pull/91) ([dependabot[bot]](https://github.com/dependabot[bot])) 17 | - Update cucumber requirement from ~> 9.2.1 to ~> 10.0.0 [#88](https://github.com/chef/mixlib-log/pull/88) ([dependabot[bot]](https://github.com/dependabot[bot])) 18 | - add myself to codeowners [#85](https://github.com/chef/mixlib-log/pull/85) ([jaymzh](https://github.com/jaymzh)) 19 | - ruby 3.4 upgrade [#86](https://github.com/chef/mixlib-log/pull/86) ([rishichawda](https://github.com/rishichawda)) 20 | 21 | 22 | 23 | ## [v3.1.2](https://github.com/chef/mixlib-log/tree/v3.1.2) (2025-04-10) 24 | 25 | 26 | ## [v3.1.2](https://github.com/chef/mixlib-log/tree/v3.1.2) (2025-04-10) 27 | 28 | ## [v3.2.3](https://github.com/chef/mixlib-log/tree/v3.2.3) (2025-04-01) 29 | 30 | #### Merged Pull Requests 31 | - Chefstyle to Cookstyle migration [#79](https://github.com/chef/mixlib-log/pull/79) ([dafyddcrosby](https://github.com/dafyddcrosby)) 32 | - updating ffi for Ohai [#83](https://github.com/chef/mixlib-log/pull/83) ([johnmccrae](https://github.com/johnmccrae)) 33 | - Relax ffi dependency to allow 1.17.1 and up [#82](https://github.com/chef/mixlib-log/pull/82) ([stanhu](https://github.com/stanhu)) 34 | 35 | ## [v3.2.0](https://github.com/chef/mixlib-log/tree/v3.2.0) (2025-01-28) 36 | 37 | #### Merged Pull Requests 38 | - Fix formatter regression from Ruby 3.3 Logger fix [#78](https://github.com/chef/mixlib-log/pull/78) ([stanhu](https://github.com/stanhu)) 39 | - Move ffi dependency forward [#81](https://github.com/chef/mixlib-log/pull/81) ([jaymzh](https://github.com/jaymzh)) 40 | 41 | ## [v3.1.1](https://github.com/chef/mixlib-log/tree/v3.1.1) (2024-07-12) 42 | 43 | #### Merged Pull Requests 44 | - Replace __FILE__ with __dir__ and other minor chefstyle fixes [#61](https://github.com/chef/mixlib-log/pull/61) ([tas50](https://github.com/tas50)) 45 | - Add Ruby 3.0 testing [#62](https://github.com/chef/mixlib-log/pull/62) ([tas50](https://github.com/tas50)) 46 | - Upgrade to GitHub-native Dependabot [#63](https://github.com/chef/mixlib-log/pull/63) ([dependabot-preview[bot]](https://github.com/dependabot-preview[bot])) 47 | - 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)) 48 | - Bump minimum to 2.7 [#75](https://github.com/chef/mixlib-log/pull/75) ([tpowell-progress](https://github.com/tpowell-progress)) 49 | - Support ruby3.3 Logger by properly initialize super class [#74](https://github.com/chef/mixlib-log/pull/74) ([mtasaka](https://github.com/mtasaka)) 50 | - 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)) 51 | 52 | ## [v3.0.9](https://github.com/chef/mixlib-log/tree/v3.0.9) (2020-08-21) 53 | 54 | #### Merged Pull Requests 55 | - Optimize our requires [#60](https://github.com/chef/mixlib-log/pull/60) ([tas50](https://github.com/tas50)) 56 | 57 | ## [v3.0.8](https://github.com/chef/mixlib-log/tree/v3.0.8) (2019-12-30) 58 | 59 | #### Merged Pull Requests 60 | - Expand testing / Update GitHub templates [#51](https://github.com/chef/mixlib-log/pull/51) ([tas50](https://github.com/tas50)) 61 | - Add Build Kite PR Testing [#52](https://github.com/chef/mixlib-log/pull/52) ([tas50](https://github.com/tas50)) 62 | - Remove Travis PR Testing [#53](https://github.com/chef/mixlib-log/pull/53) ([tas50](https://github.com/tas50)) 63 | - Resolve all warnings emitted during testing [#54](https://github.com/chef/mixlib-log/pull/54) ([zenspider](https://github.com/zenspider)) 64 | - Add windows testing in Buildkite [#56](https://github.com/chef/mixlib-log/pull/56) ([tas50](https://github.com/tas50)) 65 | - Test on Ruby 2.7 + random testing improvements [#58](https://github.com/chef/mixlib-log/pull/58) ([tas50](https://github.com/tas50)) 66 | - Substitute require for require_relative [#59](https://github.com/chef/mixlib-log/pull/59) ([tas50](https://github.com/tas50)) 67 | 68 | ## [v3.0.1](https://github.com/chef/mixlib-log/tree/v3.0.1) (2019-01-05) 69 | 70 | #### Merged Pull Requests 71 | - reverting back to ruby 2.3 support [#48](https://github.com/chef/mixlib-log/pull/48) ([lamont-granquist](https://github.com/lamont-granquist)) 72 | 73 | ## [v3.0.0](https://github.com/chef/mixlib-log/tree/v3.0.0) (2019-01-04) 74 | 75 | #### Merged Pull Requests 76 | - 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)) 77 | 78 | ## [v2.0.9](https://github.com/chef/mixlib-log/tree/v2.0.9) (2018-12-18) 79 | 80 | #### Merged Pull Requests 81 | - remove hashrocket syntax [#41](https://github.com/chef/mixlib-log/pull/41) ([lamont-granquist](https://github.com/lamont-granquist)) 82 | - Remove the changelog generator gem [#42](https://github.com/chef/mixlib-log/pull/42) ([tas50](https://github.com/tas50)) 83 | - Test on all the Ruby versions we support [#43](https://github.com/chef/mixlib-log/pull/43) ([tas50](https://github.com/tas50)) 84 | - Test on Ruby 2.6 in Travis + test on Xenial [#46](https://github.com/chef/mixlib-log/pull/46) ([tas50](https://github.com/tas50)) 85 | - Only ship the required library files in the gem artifact [#45](https://github.com/chef/mixlib-log/pull/45) ([tas50](https://github.com/tas50)) 86 | 87 | ## [v2.0.4](https://github.com/chef/mixlib-log/tree/v2.0.4) (2018-04-12) 88 | 89 | #### Merged Pull Requests 90 | - fix labelling [#37](https://github.com/chef/mixlib-log/pull/37) ([thommay](https://github.com/thommay)) 91 | 92 | ## [2.0.1](https://github.com/chef/mixlib-log/tree/2.0.1) (2018-02-28) 93 | [Full Changelog](https://github.com/chef/mixlib-log/compare/v2.0.0...2.0.1) 94 | 95 | **Merged pull requests:** 96 | 97 | - enable metadata to be got and set [\#32](https://github.com/chef/mixlib-log/pull/32) ([thommay](https://github.com/thommay)) 98 | - Logging methods \(debug, info, warn, error, fatal\) all return nil [\#27](https://github.com/chef/mixlib-log/pull/27) ([olleolleolle](https://github.com/olleolleolle)) 99 | 100 | ## [v2.0.0](https://github.com/chef/mixlib-log/tree/v2.0.0) (2018-02-27) 101 | [Full Changelog](https://github.com/chef/mixlib-log/compare/v1.7.1...v2.0.0) 102 | 103 | **Merged pull requests:** 104 | 105 | - Structured Logging [\#30](https://github.com/chef/mixlib-log/pull/30) ([thommay](https://github.com/thommay)) 106 | - RSpec: use 3.7, disable monkey patching mode [\#28](https://github.com/chef/mixlib-log/pull/28) ([olleolleolle](https://github.com/olleolleolle)) 107 | - README: Format a line of code using Markdown, not RDoc [\#24](https://github.com/chef/mixlib-log/pull/24) ([olleolleolle](https://github.com/olleolleolle)) 108 | - Travis: update Ruby versions, pass lint [\#22](https://github.com/chef/mixlib-log/pull/22) ([olleolleolle](https://github.com/olleolleolle)) 109 | - Require Ruby 2.2+ [\#20](https://github.com/chef/mixlib-log/pull/20) ([tas50](https://github.com/tas50)) 110 | 111 | ## [v1.7.1](https://github.com/chef/mixlib-log/tree/v1.7.1) (2016-08-12) 112 | [Full Changelog](https://github.com/chef/mixlib-log/compare/v1.7.0...v1.7.1) 113 | 114 | **Merged pull requests:** 115 | 116 | - Release 1.7.1 [\#19](https://github.com/chef/mixlib-log/pull/19) ([mwrock](https://github.com/mwrock)) 117 | - Allow applications to query if they've got loggers [\#18](https://github.com/chef/mixlib-log/pull/18) ([thommay](https://github.com/thommay)) 118 | 119 | ## [v1.7.0](https://github.com/chef/mixlib-log/tree/v1.7.0) (2016-08-04) 120 | [Full Changelog](https://github.com/chef/mixlib-log/compare/1.4.1...v1.7.0) 121 | 122 | **Merged pull requests:** 123 | 124 | - test with updated ruby versions and run cucumber [\#16](https://github.com/chef/mixlib-log/pull/16) ([thommay](https://github.com/thommay)) 125 | - Add dev dependency on chefstyle [\#15](https://github.com/chef/mixlib-log/pull/15) ([tas50](https://github.com/tas50)) 126 | - Misc cleanup + add Travis [\#14](https://github.com/chef/mixlib-log/pull/14) ([tas50](https://github.com/tas50)) 127 | - File log devices opened by mixlib-log should be closed. [\#13](https://github.com/chef/mixlib-log/pull/13) ([mhorbul](https://github.com/mhorbul)) 128 | - Include the license type in the .gemspec [\#9](https://github.com/chef/mixlib-log/pull/9) ([benders](https://github.com/benders)) 129 | - MIXLIB-10: don't be so pessimistic about development libraries [\#8](https://github.com/chef/mixlib-log/pull/8) ([jkeiser](https://github.com/jkeiser)) 130 | - 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)) 131 | - Fixing RDoc formatting of README.rdoc. [\#4](https://github.com/chef/mixlib-log/pull/4) ([ampledata](https://github.com/ampledata)) 132 | 133 | ## [1.4.1](https://github.com/chef/mixlib-log/tree/1.4.1) (2012-06-08) 134 | [Full Changelog](https://github.com/chef/mixlib-log/compare/1.4.0...1.4.1) 135 | 136 | ## [1.4.0](https://github.com/chef/mixlib-log/tree/1.4.0) (2012-06-08) 137 | [Full Changelog](https://github.com/chef/mixlib-log/compare/1.3.0...1.4.0) 138 | 139 | **Merged pull requests:** 140 | 141 | - Inconsistent documentation about default base log level [\#5](https://github.com/chef/mixlib-log/pull/5) ([bjoernalbers](https://github.com/bjoernalbers)) 142 | 143 | ## [1.3.0](https://github.com/chef/mixlib-log/tree/1.3.0) (2011-03-17) 144 | [Full Changelog](https://github.com/chef/mixlib-log/compare/1.2.0...1.3.0) 145 | 146 | ## [1.2.0](https://github.com/chef/mixlib-log/tree/1.2.0) (2010-10-15) 147 | [Full Changelog](https://github.com/chef/mixlib-log/compare/alpha_deploy_2...1.2.0) 148 | 149 | ## [alpha_deploy_2](https://github.com/chef/mixlib-log/tree/alpha_deploy_2) (2010-02-28) 150 | [Full Changelog](https://github.com/chef/mixlib-log/compare/alpha_deploy_3...alpha_deploy_2) 151 | 152 | ## [alpha_deploy_3](https://github.com/chef/mixlib-log/tree/alpha_deploy_3) (2010-02-28) 153 | [Full Changelog](https://github.com/chef/mixlib-log/compare/alpha_deploy_4...alpha_deploy_3) 154 | 155 | ## [alpha_deploy_4](https://github.com/chef/mixlib-log/tree/alpha_deploy_4) (2010-02-28) 156 | [Full Changelog](https://github.com/chef/mixlib-log/compare/beta-1...alpha_deploy_4) 157 | 158 | ## [beta-1](https://github.com/chef/mixlib-log/tree/beta-1) (2010-02-28) 159 | [Full Changelog](https://github.com/chef/mixlib-log/compare/1.1.0...beta-1) 160 | 161 | ## [1.1.0](https://github.com/chef/mixlib-log/tree/1.1.0) (2010-02-28) 162 | [Full Changelog](https://github.com/chef/mixlib-log/compare/v1.1.0...1.1.0) 163 | 164 | ## [v1.1.0](https://github.com/chef/mixlib-log/tree/v1.1.0) (2010-01-05) 165 | [Full Changelog](https://github.com/chef/mixlib-log/compare/alpha_deploy_1...v1.1.0) 166 | 167 | ## [alpha_deploy_1](https://github.com/chef/mixlib-log/tree/alpha_deploy_1) (2009-05-12) 168 | [Full Changelog](https://github.com/chef/mixlib-log/compare/v1.0.3...alpha_deploy_1) 169 | 170 | ## [v1.0.3](https://github.com/chef/mixlib-log/tree/v1.0.3) (2009-05-12) 171 | [Full Changelog](https://github.com/chef/mixlib-log/compare/v1.0.2...v1.0.3) 172 | 173 | ## [v1.0.2](https://github.com/chef/mixlib-log/tree/v1.0.2) (2009-05-12) 174 | 175 | 176 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* -------------------------------------------------------------------------------- /.github/copilot-instructions.md: -------------------------------------------------------------------------------- 1 | # Copilot Instructions for mixlib-log Repository 2 | 3 | ## Repository Overview 4 | 5 | The mixlib-log repository provides a Ruby mixin for enabling a class-based logger object. This is a Ruby gem project that follows Chef's development standards and practices. 6 | 7 | ### Repository Structure 8 | 9 | ``` 10 | mixlib-log/ 11 | ├── .github/ # GitHub configuration and workflows 12 | │ ├── CODEOWNERS # Code ownership configuration 13 | │ ├── ISSUE_TEMPLATE/ # Issue templates 14 | │ ├── dependabot.yml # Dependabot configuration 15 | │ └── workflows/ # GitHub Actions workflows 16 | ├── features/ # Cucumber features for behavior testing 17 | │ ├── log.feature # Main logging feature tests 18 | │ ├── steps/ # Step definitions 19 | │ └── support/ # Test support files 20 | ├── lib/ # Main library code 21 | │ └── mixlib/ 22 | │ ├── log.rb # Main logging module 23 | │ └── log/ # Supporting logging classes 24 | │ ├── child.rb # Child logger implementation 25 | │ ├── formatter.rb # Log formatting 26 | │ ├── logger.rb # Logger class 27 | │ ├── logging.rb # Logging utilities 28 | │ └── version.rb # Version information 29 | ├── spec/ # RSpec unit tests 30 | │ ├── spec_helper.rb # Test configuration 31 | │ └── mixlib/ # Test files mirroring lib structure 32 | ├── vendor/ # Bundled dependencies 33 | ├── Gemfile # Gem dependencies 34 | ├── Gemfile.lock # Locked dependency versions 35 | ├── Rakefile # Build tasks 36 | ├── mixlib-log.gemspec # Gem specification 37 | ├── README.md # Project documentation 38 | ├── CHANGELOG.md # Change history 39 | ├── VERSION # Version file 40 | └── LICENSE # Apache 2.0 license 41 | ``` 42 | 43 | ## Jira Integration with MCP Server 44 | 45 | When a Jira ID is provided: 46 | 47 | 1. **Use the atlassian-mcp-server** to fetch Jira issue details 48 | 2. **Read the story requirements** thoroughly from the Jira issue 49 | 3. **Implement the task** according to the specifications 50 | 4. **Reference the Jira ID** in commits and PR descriptions 51 | 52 | ### Jira Workflow Commands 53 | ```bash 54 | # Example MCP server usage for Jira integration 55 | # The atlassian-mcp-server should be configured to access your Jira instance 56 | # Use the following pattern when Jira ID is provided: 57 | # 1. Fetch issue: mcp_atlassian-mcp_getJiraIssue with cloudId and issueIdOrKey 58 | # 2. Read requirements from the issue description and acceptance criteria 59 | # 3. Implement according to the story requirements 60 | ``` 61 | 62 | ## Testing Requirements 63 | 64 | ### Unit Test Coverage 65 | - **Maintain >80% test coverage** for all new and modified code 66 | - Use RSpec for unit tests (located in `spec/` directory) 67 | - Use Cucumber for integration/behavior tests (located in `features/` directory) 68 | - Run tests with: `bundle exec rake spec` and `bundle exec rake features` 69 | 70 | ### Test Commands 71 | ```bash 72 | # Run all tests 73 | bundle exec rake 74 | 75 | # Run only unit tests 76 | bundle exec rake spec 77 | 78 | # Run only integration tests 79 | bundle exec rake features 80 | 81 | # Run style checks 82 | bundle exec rake style 83 | 84 | # Check coverage 85 | bundle exec rspec --format html --out coverage/index.html 86 | ``` 87 | 88 | ## Pull Request and Branch Management 89 | 90 | ### Branch Creation and PR Workflow 91 | 92 | When prompted to create a PR for changes: 93 | 94 | 1. **Create a branch** using the Jira ID as the branch name 95 | 2. **Push changes** to the new branch 96 | 3. **Create a PR** using GitHub CLI 97 | 4. **Include HTML-formatted description** with summary of changes 98 | 99 | ### GitHub CLI Commands 100 | ```bash 101 | # Create and switch to new branch (use Jira ID as branch name) 102 | git checkout -b JIRA-123 103 | 104 | # Stage and commit changes with DCO sign-off 105 | git add . 106 | git commit -s -m "feat: implement feature for JIRA-123 107 | 108 | Detailed description of changes made. 109 | 110 | Signed-off-by: Your Name " 111 | 112 | # Push branch 113 | git push origin JIRA-123 114 | 115 | # Create PR with HTML description 116 | gh pr create --title "feat: implement feature for JIRA-123" \ 117 | --body "

Summary

118 |

Brief description of changes

119 |

Changes Made

120 |
    121 |
  • Change 1
  • 122 |
  • Change 2
  • 123 |
124 |

Testing

125 |

Description of testing performed

126 |

Jira Issue

127 |

Resolves: JIRA-123

" 128 | ``` 129 | 130 | **Important**: All tasks are performed on the local repository. Do not reference `~/.profile` for GitHub authentication steps. 131 | 132 | ## DCO Compliance Requirements 133 | 134 | All commits **MUST** be signed off to comply with the Developer Certificate of Origin (DCO): 135 | 136 | ### DCO Sign-off Requirements 137 | - **Every commit** must include a `Signed-off-by` line 138 | - Use `git commit -s` to automatically add sign-off 139 | - Sign-off certifies you have the right to submit the code under the project's license 140 | - Format: `Signed-off-by: Your Name ` 141 | 142 | ### DCO Commands 143 | ```bash 144 | # Commit with automatic DCO sign-off 145 | git commit -s -m "your commit message" 146 | 147 | # Add DCO sign-off to existing commit 148 | git commit --amend -s 149 | 150 | # Check if commits are signed 151 | git log --show-signature 152 | ``` 153 | 154 | ## Build System Integration 155 | 156 | ### GitHub Actions Workflows 157 | The repository uses GitHub Actions for CI/CD with the following workflow: 158 | - **File**: `.github/workflows/ci-main-pull-request-checks.yml` 159 | - **Triggers**: Pull requests and pushes to `main` and `release/**` branches 160 | - **Common Actions**: Uses `chef/common-github-actions` for standardized CI pipeline 161 | 162 | ### Expeditor Build System 163 | The repository integrates with Chef's Expeditor build system for: 164 | - Automated version bumping 165 | - Changelog updates 166 | - Package building and publishing 167 | - Release management 168 | 169 | ### Available Expeditor Labels 170 | Use these labels to control Expeditor behavior: 171 | - `Expeditor: Bump Version Major` - Bump major version number 172 | - `Expeditor: Bump Version Minor` - Bump minor version number 173 | - `Expeditor: Skip All` - Skip all merge actions 174 | - `Expeditor: Skip Changelog` - Skip changelog updates 175 | - `Expeditor: Skip Habitat` - Skip Habitat package builds 176 | - `Expeditor: Skip Omnibus` - Skip Omnibus builds 177 | - `Expeditor: Skip Version Bump` - Skip version bumping 178 | 179 | ## Repository-Specific GitHub Labels 180 | 181 | ### Aspect Labels (for categorizing issues/PRs) 182 | - `Aspect: Documentation` - Documentation improvements 183 | - `Aspect: Integration` - Integration with other systems 184 | - `Aspect: Packaging` - Distribution and packaging 185 | - `Aspect: Performance` - Performance improvements 186 | - `Aspect: Portability` - Cross-platform compatibility 187 | - `Aspect: Security` - Security-related changes 188 | - `Aspect: Stability` - Reliability improvements 189 | - `Aspect: Testing` - Test coverage and CI improvements 190 | - `Aspect: UI` - User interface changes 191 | - `Aspect: UX` - User experience improvements 192 | 193 | ### Platform Labels 194 | - `Platform: AWS`, `Platform: Azure`, `Platform: GCP` - Cloud platforms 195 | - `Platform: Linux`, `Platform: macOS` - Operating systems 196 | - `Platform: Debian-like`, `Platform: RHEL-like`, `Platform: SLES-like` - Linux distributions 197 | - `Platform: Docker` - Container platform 198 | - `Platform: Unix-like` - Unix-like systems 199 | 200 | ### Special Labels 201 | - `dependencies` - Dependency updates 202 | - `hacktoberfest-accepted` - Hacktoberfest contributions 203 | - `oss-standards` - OSS repository standardization 204 | 205 | ## Prompt-Based Task Execution 206 | 207 | ### Workflow Execution 208 | All tasks should be **prompt-based** with the following pattern: 209 | 210 | 1. **After each step**: Provide a summary of what was completed 211 | 2. **Next step prompt**: Clearly state what the next step will be 212 | 3. **Remaining steps**: List what steps are still remaining 213 | 4. **Confirmation request**: Ask if you want to continue with the next step 214 | 215 | ### Example Prompt Pattern 216 | ``` 217 | ✅ **Step Completed**: [Description of what was just done] 218 | 219 | 📋 **Next Step**: [What will be done next] 220 | 221 | 📝 **Remaining Steps**: 222 | - Step A 223 | - Step B 224 | - Step C 225 | 226 | ❓ **Continue?**: Would you like me to proceed with the next step? 227 | ``` 228 | 229 | ## Complete Implementation Workflow 230 | 231 | When implementing a task, follow this comprehensive workflow: 232 | 233 | ### Phase 1: Analysis and Planning 234 | 1. **Jira Integration** (if Jira ID provided): 235 | - Use atlassian-mcp-server to fetch issue details 236 | - Read and understand story requirements 237 | - Identify acceptance criteria 238 | - **Prompt**: Summarize understanding and ask to continue 239 | 240 | 2. **Code Analysis**: 241 | - Review existing codebase structure 242 | - Identify files that need modification 243 | - Check for similar existing implementations 244 | - **Prompt**: Present analysis and implementation plan 245 | 246 | ### Phase 2: Implementation 247 | 3. **Branch Creation**: 248 | - Create branch with Jira ID name (if applicable) 249 | - **Prompt**: Confirm branch creation and next steps 250 | 251 | 4. **Code Implementation**: 252 | - Implement required functionality 253 | - Follow Ruby and Chef coding standards 254 | - Ensure backward compatibility 255 | - **Prompt**: Present implemented code and ask to continue 256 | 257 | 5. **Unit Test Creation**: 258 | - Write comprehensive unit tests in `spec/` directory 259 | - Ensure >80% code coverage requirement 260 | - Include edge cases and error scenarios 261 | - **Prompt**: Show test coverage and ask to continue 262 | 263 | ### Phase 3: Testing and Validation 264 | 6. **Test Execution**: 265 | - Run unit tests: `bundle exec rake spec` 266 | - Run integration tests: `bundle exec rake features` 267 | - Run style checks: `bundle exec rake style` 268 | - **Prompt**: Report test results and any issues 269 | 270 | 7. **Coverage Verification**: 271 | - Verify >80% test coverage requirement 272 | - Generate coverage reports if needed 273 | - **Prompt**: Confirm coverage meets requirements 274 | 275 | ### Phase 4: Commit and PR 276 | 8. **DCO Compliant Commits**: 277 | - Stage changes with meaningful commit messages 278 | - Ensure all commits are DCO signed (`git commit -s`) 279 | - Reference Jira ID in commit messages 280 | - **Prompt**: Show commit summary and ask to continue 281 | 282 | 9. **PR Creation**: 283 | - Push branch to origin 284 | - Create PR with GitHub CLI 285 | - Use HTML-formatted description with: 286 | - Summary of changes 287 | - Testing performed 288 | - Jira issue reference 289 | - Apply appropriate labels 290 | - **Prompt**: Show PR details and completion summary 291 | 292 | ### Prohibited File Modifications 293 | Do **NOT** modify the following files without explicit instruction: 294 | - `.github/CODEOWNERS` - Code ownership rules 295 | - `LICENSE` - License file 296 | - `VERSION` - Version is managed by Expeditor 297 | - `.github/dependabot.yml` - Dependency management configuration 298 | - Core CI workflow files (unless specifically requested) 299 | 300 | ### Quality Gates 301 | Before completing any task, ensure: 302 | - [ ] All tests pass (`bundle exec rake`) 303 | - [ ] Code coverage >80% 304 | - [ ] Style checks pass (`bundle exec rake style`) 305 | - [ ] DCO sign-off on all commits 306 | - [ ] Jira ID referenced (if applicable) 307 | - [ ] PR has proper HTML description 308 | - [ ] Appropriate labels applied 309 | 310 | ## Additional Notes 311 | 312 | - **Ruby Version**: Follow the Ruby version specified in `.ruby-version` or Gemfile 313 | - **Dependencies**: Use Bundler for dependency management 314 | - **Documentation**: Update README.md if adding new features 315 | - **Changelog**: Expeditor will handle changelog updates automatically 316 | - **Version Bumping**: Handled automatically by Expeditor based on PR labels 317 | 318 | ## AI-Assisted Development & Compliance 319 | 320 | - ✅ Create PR with `ai-assisted` label (if label doesn't exist, create it with description "Work completed with AI assistance following Progress AI policies" and color "9A4DFF") 321 | - ✅ Include "This work was completed with AI assistance following Progress AI policies" in PR description 322 | 323 | ### Jira Ticket Updates (MANDATORY) 324 | 325 | - ✅ **IMMEDIATELY after PR creation**: Update Jira ticket custom field `customfield_11170` ("Does this Work Include AI Assisted Code?") to "Yes" 326 | - ✅ Use atlassian-mcp tools to update the Jira field programmatically 327 | - ✅ **CRITICAL**: Use correct field format: `{"customfield_11170": {"value": "Yes"}}` 328 | - ✅ Verify the field update was successful 329 | 330 | ### Documentation Requirements 331 | 332 | - ✅ Reference AI assistance in commit messages where appropriate 333 | - ✅ Document any AI-generated code patterns or approaches in PR description 334 | - ✅ Maintain transparency about which parts were AI-assisted vs manual implementation 335 | 336 | ### Workflow Integration 337 | 338 | This AI compliance checklist should be integrated into the main development workflow Step 4 (Pull Request Creation): 339 | 340 | ``` 341 | Step 4: Pull Request Creation & AI Compliance 342 | - Step 4.1: Create branch and commit changes WITH SIGNED-OFF COMMITS 343 | - Step 4.2: Push changes to remote 344 | - Step 4.3: Create PR with ai-assisted label 345 | - Step 4.4: IMMEDIATELY update Jira customfield_11170 to "Yes" 346 | - Step 4.5: Verify both PR labels and Jira field are properly set 347 | - Step 4.6: Provide complete summary including AI compliance confirmation 348 | ``` 349 | 350 | - **Never skip Jira field updates** - This is required for Progress AI governance 351 | - **Always verify updates succeeded** - Check response from atlassian-mcp tools 352 | - **Treat as atomic operation** - PR creation and Jira updates should happen together 353 | - **Double-check before final summary** - Confirm all AI compliance items are completed 354 | 355 | ### Audit Trail 356 | 357 | All AI-assisted work must be traceable through: 358 | 359 | 1. GitHub PR labels (`ai-assisted`) 360 | 2. Jira custom field (`customfield_11170` = "Yes") 361 | 3. PR descriptions mentioning AI assistance 362 | 4. Commit messages where relevant 363 | 364 | --- 365 | 366 | This instruction file ensures consistent, high-quality contributions to the mixlib-log repository while maintaining compliance with Chef's development standards and practices. 367 | --------------------------------------------------------------------------------