Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc cleanup + add Travis #14

Merged
merged 6 commits into from
Mar 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: ruby
cache: bundler

sudo: false

branches:
only:
- master

before_install:
- bundle --version
- gem --version
rvm:
- 2.1
- 2.2

script:
- bundle exec chefstyle
- bundle exec rake spec
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "http://rubygems.org"
source "https://rubygems.org"

gemspec

Expand Down
23 changes: 12 additions & 11 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
Mixin::Log NOTICE
=================
============
Mixin::Log Notices
============

Developed at Opscode (http://www.opscode.com).
Developed at Chef (http://www.chef.io).

* Copyright 2009, Opscode, Inc. <[email protected]>

* Copyright 2009-2016, Chef Software, Inc. <[email protected]>

Mixin::Log incorporates code from Chef. The Chef notice file follows:

Chef NOTICE
===========
============
Chef Notices
============

Developed at Opscode (http://www.opscode.com).
Developed at Chef (http://www.chef.io).

Contributors and Copyright holders:

* Copyright 2008, Adam Jacob <adam@opscode.com>
* Copyright 2008, Adam Jacob <adam@chef.io>
* Copyright 2008, Arjuna Christensen <[email protected]>
* Copyright 2008, Bryan McLellan <[email protected]>
* Copyright 2008, Ezra Zygmuntowicz <[email protected]>
* Copyright 2009, Sean Cribbs <[email protected]>
* Copyright 2009, Christopher Brown <cb@opscode.com>
* Copyright 2009, Christopher Brown <cb@chef.io>
* Copyright 2009, Thom May <[email protected]>

Chef incorporates code modified from Open4 (http://www.codeforpeople.com/lib/ruby/open4/), which was written by Ara T. Howard.

Chef incorporates code modified from Merb (http://www.merbivore.com), which is Copyright (c) 2008 Engine Yard.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Mixlib::Log

[![Build Status Master](https://travis-ci.org/chef/mixlib-log.svg?branch=master)](https://travis-ci.org/chef/mixlib-log) [![Gem Version](https://badge.fury.io/rb/mixlib-log.svg)](https://badge.fury.io/rb/mixlib-log)

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

```ruby
require 'mixlib/log'

class Log
extend Mixlib::Log
end
```

You can then do:

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

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

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

Enjoy!

## LICENSE:

- Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
- License:: Apache License, Version 2.0

```text
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

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

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

This file was deleted.

23 changes: 11 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
require 'rake'
require 'rubygems/package_task'
require 'rdoc/task'
require 'yaml'
require 'rspec/core/rake_task'
require 'cucumber/rake/task'
require "rake"
require "rubygems/package_task"
require "rdoc/task"
require "yaml"
require "rspec/core/rake_task"
require "cucumber/rake/task"

gemspec = eval(IO.read('mixlib-log.gemspec'))
gemspec = eval(IO.read("mixlib-log.gemspec"))

Gem::PackageTask.new(gemspec) do |pkg|
pkg.gem_spec = gemspec
end

RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
spec.pattern = "spec/**/*_spec.rb"
end

task :default => :spec
Expand All @@ -21,13 +21,12 @@ task :default => :spec
task :test => :spec

RDoc::Task.new do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.rdoc_dir = "rdoc"
rdoc.title = "mixlib-log #{Mixlib::Log::VERSION}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
rdoc.rdoc_files.include("README*")
rdoc.rdoc_files.include("lib/**/*.rb")
end

Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "--format pretty"
end

13 changes: 6 additions & 7 deletions features/steps/log.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# Author:: Adam Jacob (<adam@chef.io>)
# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -37,12 +37,11 @@
end
end

Then /^the regex '(.+)' should be logged$/ do |regex_string|
Then /^the regex '(.+)' should be logged$/ do |regex_string|
regex = Regexp.new(regex_string, Regexp::MULTILINE)
regex.match(@output).should_not == nil
end

Then /^nothing should be logged$/ do
Then /^nothing should be logged$/ do
@output.should == ""
end

21 changes: 10 additions & 11 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# Author:: Adam Jacob (<adam@chef.io>)
# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

$: << File.join(File.dirname(__FILE__), '..', '..', 'lib')
$: << File.join(File.dirname(__FILE__), "..", "..", "lib")

require 'rspec/expectations'
require 'mixlib/log'
require 'tmpdir'
require 'stringio'
require "rspec/expectations"
require "mixlib/log"
require "tmpdir"
require "stringio"

class MyWorld
def initialize
@tmpdir = File.join(Dir.tmpdir, "mixlib_log")
@output = ''
@output = ""
@output_io = StringIO.new(@output)
Logit.init(@output_io)
end
Expand All @@ -43,4 +43,3 @@ def initialize
After do
system("rm -rf #{@tmpdir}")
end

10 changes: 5 additions & 5 deletions features/support/logit.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# Author:: Adam Jacob (<adam@chef.io>)
# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -18,4 +18,4 @@

class Logit
extend Mixlib::Log
end
end
33 changes: 16 additions & 17 deletions lib/mixlib/log.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Author:: Christopher Brown (<cb@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Christopher Brown (<cb@chef.io>)
# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,19 +16,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require 'logger'
require 'mixlib/log/version'
require 'mixlib/log/formatter'
require "logger"
require "mixlib/log/version"
require "mixlib/log/formatter"

module Mixlib
module Log

@logger, @loggers = nil

LEVELS = { :debug=>Logger::DEBUG, :info=>Logger::INFO, :warn=>Logger::WARN, :error=>Logger::ERROR, :fatal=>Logger::FATAL}.freeze
LEVELS = { :debug => Logger::DEBUG, :info => Logger::INFO, :warn => Logger::WARN, :error => Logger::ERROR, :fatal => Logger::FATAL }.freeze
LEVEL_NAMES = LEVELS.invert.freeze


def reset!
@logger, @loggers = nil, nil
end
Expand All @@ -51,7 +50,7 @@ def logger
# that had been added to the +loggers+ array will be cleared.
def logger=(new_log_device)
reset!
@logger=new_log_device
@logger = new_log_device
end

def use_log_devices(other)
Expand All @@ -63,7 +62,7 @@ def use_log_devices(other)
@logger = other.first
else
msg = "#use_log_devices takes a Mixlib::Log object or array of log devices. " <<
"You gave: #{other.inspect}"
"You gave: #{other.inspect}"
raise ArgumentError, msg
end
end
Expand Down Expand Up @@ -95,14 +94,14 @@ def init(*opts)
def level=(new_level)
level_int = LEVEL_NAMES.key?(new_level) ? new_level : LEVELS[new_level]
raise ArgumentError, "Log level must be one of :debug, :info, :warn, :error, or :fatal" if level_int.nil?
loggers.each {|l| l.level = level_int }
loggers.each { |l| l.level = level_int }
end

def level(new_level=nil)
def level(new_level = nil)
if new_level.nil?
LEVEL_NAMES[logger.level]
else
self.level=(new_level)
self.level = (new_level)
end
end

Expand All @@ -129,11 +128,11 @@ def #{method_name}
end

def <<(msg)
loggers.each {|l| l << msg }
loggers.each { |l| l << msg }
end

def add(severity, message = nil, progname = nil, &block)
loggers.each {|l| l.add(severity, message, progname, &block) }
loggers.each { |l| l.add(severity, message, progname, &block) }
end

alias :log :add
Expand All @@ -142,15 +141,15 @@ def add(severity, message = nil, progname = nil, &block)
# this method gets hit before a call to Mixlib::Logger.init has been made, it will call
# Mixlib::Logger.init() with no arguments.
def method_missing(method_symbol, *args, &block)
loggers.each {|l| l.send(method_symbol, *args, &block) }
loggers.each { |l| l.send(method_symbol, *args, &block) }
end

private

def logger_for(*opts)
if opts.empty?
Logger.new(STDOUT)
elsif LEVELS.keys.inject(true) {|quacks, level| quacks && opts.first.respond_to?(level)}
elsif LEVELS.keys.inject(true) { |quacks, level| quacks && opts.first.respond_to?(level) }
opts.first
else
Logger.new(*opts)
Expand Down
Loading