Giter VIP home page Giter VIP logo

mixlib-log's Introduction

Mixlib::Log

Gem Version Build status

Umbrella Project: Chef Foundation

Project State: Active

Issues Response Time Maximum: 14 days

Pull Request Response Time Maximum: 14 days

Mixlib::Log provides a mixin for enabling a class based logger object, a-la Merb, Chef, and Nanite. To use it:

require 'mixlib/log'

class Log
  extend Mixlib::Log
end

You can then do:

Log.debug('foo')
Log.info('bar')
Log.warn('baz')
Log.error('baz')
Log.fatal('wewt')

By default, Mixlib::Logger logs to STDOUT. To alter this, you should call Log.init, passing any arguments to the standard Ruby Logger. For example:

Log.init('/tmp/logfile')  # log to /tmp/logfile
Log.init('/tmp/logfile', 7)  # log to /tmp/logfile, rotate every day

Enjoy!

Documentation

All documentation is written using YARD. You can generate a by running:

rake docs

Contributing

For information on contributing to this project please see our Contributing Documentation

License & Copyright

  • Copyright:: Copyright (c) 2008-2019 Chef Software, Inc.
  • License:: Apache License, Version 2.0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

mixlib-log's People

Contributors

adamhjk avatar benders avatar bjoernalbers avatar btm avatar chef-ci avatar chef-expeditor[bot] avatar danielsdeleo avatar dependabot-preview[bot] avatar jayashrig158 avatar jeremiahsnapp avatar jkeiser avatar ketan avatar lamont-granquist avatar mhorbul avatar mtasaka avatar mwrock avatar olleolleolle avatar poorndm avatar prajaktapurohit avatar skeshari12 avatar stanhu avatar tas50 avatar tduffield avatar thommay avatar tpowell-progress avatar zenspider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mixlib-log's Issues

Feature Request: logger.info to return nil

I would like logger's logging methods to return nil when they output messages.

Use-case: When logging a message at the end of an ensure clause one often means to "just print", and not return a list of outputters. Perhaps the logger.info used to be a puts. Now, its return value is non-nil and oy vey.

rbenv+bundler deploy: mixlib/log/version (LoadError)

I've been following the rbenv suggestions for production deployments.
All works well for the 148 gems being deployed. However, I am constantly hitting this error with mixlib-log, and only mixlib-log:

    /home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/mixlib-log-1.3.0/lib/mixlib/log.rb:20:in `require': no such file to load -- mixlib/log/version (LoadError)
from /home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/mixlib-log-1.3.0/lib/mixlib/log.rb:20:in `<top (required)>'
from /home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/chef-0.10.8/lib/chef/log.rb:21:in `require'
from /home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/chef-0.10.8/lib/chef/log.rb:21:in `<top (required)>'
from /home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/chef-0.10.8/lib/chef.rb:23:in `require'
from /home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/chef-0.10.8/lib/chef.rb:23:in `<top (required)>'
from /home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/chef-0.10.8/lib/chef/application/solo.rb:18:in `require'
from /home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/chef-0.10.8/lib/chef/application/solo.rb:18:in `<top (required)>'
from /home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/chef-0.10.8/bin/chef-solo:23:in `require'
from /home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/chef-0.10.8/bin/chef-solo:23:in `<top (required)>'
from /home/ubuntu/project/vendor/bundle/ruby/1.9.1/bin/chef-solo:19:in `load'
from /home/ubuntu/project/vendor/bundle/ruby/1.9.1/bin/chef-solo:19:in `<main>'

The bundle install command is (as deploy user):

 bundle install --deployment --binstubs --shebang ruby-local-exec --gemfile /home/ubuntu/project/Gemfile --path /home/ubuntu/project/vendor/bundle

The work around, after the bundle install, is to run (as deploy user):

bin/bundle exec gem install mixlib-log

Then all is OK until the next time the application deploys, then we repeat :)

The issues seems to be that the gemspec does not like bundler, since the log sub-folder and files are missing:

$ ls -la /home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/mixlib-log-1.3.0/lib/mixlib
total 16
drwxr-xr-x 2 ubuntu ubuntu 4096 2012-03-01 08:31 .
drwxr-xr-x 3 ubuntu ubuntu 4096 2012-03-01 08:31 ..
-rw-r--r-- 1 ubuntu ubuntu 5208 2012-03-01 08:31 log.rb

The gem is indeed missing the files:

$ bin/bundle exec gem contents mixlib-log
/home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/mixlib-log-1.3.0/LICENSE
/home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/mixlib-log-1.3.0/NOTICE
/home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/mixlib-log-1.3.0/README.rdoc
/home/ubuntu/project/vendor/bundle/ruby/1.9.1/gems/mixlib-log-1.3.0/lib/mixlib/log.rb

And the installed specification is:

$ cat /home/ubuntu/project/vendor/bundle/ruby/1.9.1/specifications/mixlib-log-1.3.0.gemspec 
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
  s.name = "mixlib-log"
  s.version = "1.3.0"

  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
  s.authors = ["Opscode, Inc."]
  s.date = "2011-03-23"
  s.email = "[email protected]"
  s.extra_rdoc_files = ["README.rdoc", "LICENSE", "NOTICE"]
  s.files = ["README.rdoc", "LICENSE", "NOTICE"]
  s.homepage = "http://www.opscode.com"
  s.require_paths = ["lib"]
  s.rubygems_version = "1.8.17"
  s.summary = "A gem that provides a simple mixin for log functionality"

  if s.respond_to? :specification_version then
    s.specification_version = 3

    if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
    else
    end
  else
  end
end

Dependabot can't parse your Gemfile

Dependabot couldn't parse the Gemfile found at /Gemfile.

The error Dependabot encountered was:

Dependabot only supports uninterpolated string arguments to eval_gemfile. Got `__FILE__ + ".local"`

Chef can no longer write logs with 1.7.0

As up upgrading from mixlib-log 1.6.0 to 1.7.0, many of these messages are spat out during a Chef-client run:

log writing failed. closed stream

The chef-client logs are not written. Downgrading to 1.6.0 fixes the issue. Chef version is 12.6.0 and also tried with 12.12.15 with bad results.

Regression in v2.x from v1.x

We changed from calling .new against the core Ruby Logger class to a wrapper implementation which only supports a single argument.

Old logger:
https://github.com/chef/mixlib-log/blob/v1.7.1/lib/mixlib/log.rb#L16
https://github.com/ruby/ruby/blob/trunk/lib/logger.rb#L377-L379

New Logger:
https://github.com/ruby/ruby/blob/trunk/lib/logger.rb#L377-L379
https://github.com/chef/mixlib-log/blob/master/lib/mixlib/log/logger.rb#L35

This broke anything which created a new logger instance with overloaded arguments. SemVer saves us, but I am not sure if this was intentional or not.

(See Chef internal SUSTAIN-930)

rspec testsuite fails with ruby 3.3.0dev

With ruby 3.3.0dev ( I tested ruby/ruby@6d7730a ), mixlib-log git head ( 8643e33 ) rspec testsuite causes error like:

$ rspec spec
.....
Failures:

  1) Mixlib::Log::Child can query the parent's level at debug
     Failure/Error: logger.send(method_name)

     NoMethodError:
       undefined method `[]' for nil
     # ./lib/mixlib/log.rb:131:in `block (2 levels) in <module:Log>'
     # ./lib/mixlib/log/child.rb:41:in `block (2 levels) in <class:Child>'
     # ./spec/mixlib/log/child_spec.rb:95:in `block (4 levels) in <top (required)>'

  2) Mixlib::Log::Child can query the parent's level at info
     Failure/Error: logger.send(method_name)

     NoMethodError:
       undefined method `[]' for nil
     # ./lib/mixlib/log.rb:131:in `block (2 levels) in <module:Log>'
     # ./lib/mixlib/log/child.rb:41:in `block (2 levels) in <class:Child>'
     # ./spec/mixlib/log/child_spec.rb:95:in `block (4 levels) in <top (required)>'

  3) Mixlib::Log::Child can query the parent's level at warn
     Failure/Error: logger.send(method_name)

     NoMethodError:
       undefined method `[]' for nil
     # ./lib/mixlib/log.rb:131:in `block (2 levels) in <module:Log>'
     # ./lib/mixlib/log/child.rb:41:in `block (2 levels) in <class:Child>'
     # ./spec/mixlib/log/child_spec.rb:95:in `block (4 levels) in <top (required)>'

  4) Mixlib::Log::Child can query the parent's level at error
     Failure/Error: logger.send(method_name)

     NoMethodError:
       undefined method `[]' for nil
     # ./lib/mixlib/log.rb:131:in `block (2 levels) in <module:Log>'
     # ./lib/mixlib/log/child.rb:41:in `block (2 levels) in <class:Child>'
     # ./spec/mixlib/log/child_spec.rb:95:in `block (4 levels) in <top (required)>'

  5) Mixlib::Log::Child can query the parent's level at fatal
     Failure/Error: logger.send(method_name)

     NoMethodError:
       undefined method `[]' for nil
     # ./lib/mixlib/log.rb:131:in `block (2 levels) in <module:Log>'
     # ./lib/mixlib/log/child.rb:41:in `block (2 levels) in <class:Child>'
     # ./spec/mixlib/log/child_spec.rb:95:in `block (4 levels) in <top (required)>'

  6) Mixlib::Log should set the log level using the binding form,  with :trace, :debug, :info, :warn, :error, or :fatal
     Failure/Error: expect(Logit.logger.level).to eq(constant)

     NoMethodError:
       undefined method `[]' for nil
     # ./spec/mixlib/log_spec.rb:109:in `block (3 levels) in <top (required)>'
     # ./spec/mixlib/log_spec.rb:107:in `each'
     # ./spec/mixlib/log_spec.rb:107:in `block (2 levels) in <top (required)>'

  7) Mixlib::Log should set the log level using the method form, with :trace, :debug, :info, :warn, :error, or :fatal
     Failure/Error: expect(Logit.logger.level).to eq(constant)

     NoMethodError:
       undefined method `[]' for nil
     # ./spec/mixlib/log_spec.rb:132:in `block (3 levels) in <top (required)>'
     # ./spec/mixlib/log_spec.rb:130:in `each'
     # ./spec/mixlib/log_spec.rb:130:in `block (2 levels) in <top (required)>'

  8) Mixlib::Log should pass other method calls directly to logger
     Failure/Error: logger.send(method_name)

     NoMethodError:
       undefined method `[]' for nil
     # ./lib/mixlib/log.rb:131:in `block (2 levels) in <module:Log>'
     # ./spec/mixlib/log_spec.rb:150:in `block (3 levels) in <top (required)>'
     # ./spec/mixlib/log_spec.rb:145:in `block (2 levels) in <top (required)>'

  9) Mixlib::Log should pass add method calls directly to logger
     Failure/Error: logger.send(method_name)

     NoMethodError:
       undefined method `[]' for nil
     # ./lib/mixlib/log.rb:131:in `block (2 levels) in <module:Log>'
     # ./spec/mixlib/log_spec.rb:159:in `block (2 levels) in <top (required)>'

Finished in 0.02143 seconds (files took 0.07924 seconds to load)
44 examples, 9 failures

This is due to change in ruby Logger:
ruby/ruby@194520f
ruby/logger#85

and almost the same fix as steveklabnik/mono_logger#12 is needed.

Breaking change in minor version.

From Gemfile.lock:

    chef (12.22.3)
      mixlib-authentication (~> 1.4)
      mixlib-log (~> 1.3)

mixlib-authentication uses logger.trace, but it is available in mixlib-log 2.x, isn't it?

Anyway, mixlib-authentiation 1.4.2 works.
I believe the easiest way is to add trace here in 1.x version.

There are also no explicit dependines from mixlib-authentication to mixlib-log.
I blame this commit: chef/mixlib-authentication@9384e69

`initialize': wrong number of arguments when passing time to ::init

Version:

v3.0.1

Environment:

RHEL 6
ChefDK v4.0.60

Scenario:

Trying to leverage the built-in log rotation

Steps to Reproduce:

require 'mixlib/log'

class Log
  extend Mixlib::Log
end

Log.init('/tmp/logfile', 7)

Expected Result:

I would expect this to start logging to /tmp/logfile and to automatically rotate the log.

Actual Result:

Traceback (most recent call last):
        6: from /opt/chefdk/embedded/bin/irb:11:in `<main>'
        5: from (irb):7
        4: from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/mixlib-log-3.0.1/lib/mixlib/log.rb:83:in `init'
        3: from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/mixlib-log-3.0.1/lib/mixlib/log.rb:177:in `logger_for'
        2: from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/mixlib-log-3.0.1/lib/mixlib/log.rb:177:in `new'
        1: from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/mixlib-log-3.0.1/lib/mixlib/log/logger.rb:35:in `initialize'
ArgumentError (wrong number of arguments (given 2, expected 1))

Feature request: be able to override logdev after creation

This could be a useful feature, especially in specs where you often want to silence the logging.

I looked briefly at the code in https://github.com/chef/mixlib-log/blob/master/lib/mixlib/log/logger.rb, and it seems to be pretty simple; it's just an attr_accessor or attr_writer that would need to be added.

Are you against it for philosophical reasons, or would you consider a PR that adds this? Or is there another suggested way to change the output device of a logger after it has been created?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.