Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
44 lib/yell.rb
@@ -12,7 +12,7 @@
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
-#
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -22,6 +22,8 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module Yell #:nodoc:
+
+ # Holds all Yell severities
Severities = [ 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL', 'UNKNOWN' ]
class << self
@@ -36,11 +38,25 @@ def new( *args, &block )
# Shortcut to Yell::Level.new
#
- # @return [Yell::Level] A Yell::Level instance
+ # @return [Yell::Level] The level instance
def level( val = nil )
Yell::Level.new( val )
end
+ # Shortcut to Yell::Repository[]
+ #
+ # @return [Yell::Logger] The logger instance
+ def []( name )
+ Yell::Repository[ name ]
+ end
+
+ # Shortcut to Yell::Repository[]=
+ #
+ # @return [Yell::Logger] The logger instance
+ def []=( name, logger )
+ Yell::Repository[ name ] = logger
+ end
+
# Shortcut to Yell::Fomatter.new
#
# @return [Yell::Formatter] A Yell::Formatter instance
@@ -48,28 +64,32 @@ def format( pattern, date_pattern = nil )
Yell::Formatter.new( pattern, date_pattern )
end
- def env #:nodoc:
- ENV['YELL_ENV'] || ENV['RACK_ENV'] ||ENV['RAILS_ENV'] || 'development'
- end
-
+ # Loads a config from a YAML file
def load!( file )
Yell.new Yell::Configuration.load!( file )
end
- def _deprecate( version, message, options = {} )
- warning = ["Deprecation Warning (since v#{version}): #{message}" ]
- warning << " before: #{options[:before]}" if options[:before]
- warning << " after: #{options[:after]}" if options[:after]
+ def env #:nodoc:
+ ENV['YELL_ENV'] || ENV['RACK_ENV'] ||ENV['RAILS_ENV'] || 'development'
+ end
+
+ def _deprecate( version, message, options = {} ) #:nodoc:
+ messages = ["Deprecation Warning (since v#{version}): #{message}" ]
+ messages << " before: #{options[:before]}" if options[:before]
+ messages << " after: #{options[:after]}" if options[:after]
- $stderr.puts warning.join( "\n" )
+ _warn( *messages )
end
+ def _warn( *messages )
+ $stderr.puts messages.join( "\n" )
+ end
end
end
require File.dirname(__FILE__) + '/yell/configuration'
-
+require File.dirname(__FILE__) + '/yell/repository'
require File.dirname(__FILE__) + '/yell/event'
require File.dirname(__FILE__) + '/yell/level'
require File.dirname(__FILE__) + '/yell/formatter'
View
2  lib/yell/logger.rb
@@ -77,7 +77,7 @@ def initialize( *args, &block )
#
# @param [Symbol] type The type of the adapter, may be `:file` or `:datefile` (default `:file`)
#
- # @return A new +Yell::Adapter+ instance
+ # @return [Yell::Adapter] The instance
#
# @raise [Yell::NoSuchAdapter] Will be thrown when the adapter is not defined
def adapter( type = :file, *args, &block )
View
44 lib/yell/repository.rb
@@ -0,0 +1,44 @@
+# encoding: utf-8
+
+require 'monitor'
+require "singleton"
+
+module Yell #:nodoc:
+ class Repository
+ extend MonitorMixin
+ include Singleton
+
+ attr_accessor :loggers
+
+ def initialize
+ @loggers = {}
+ end
+
+ # Set loggers in the repository
+ #
+ # @example Set a logger
+ # Yell::Repository[ 'development' ] = Yell::Logger.new :stdout
+ #
+ # @return [Yell::Logger] The logger instance
+ def self.[]=( name, logger )
+ synchronize { instance.loggers[name] = logger }
+ end
+
+ # Get loggers from the repository
+ #
+ # @example Get the logger
+ # Yell::Repository[ 'development' ]
+ #
+ # @return [Yell::Logger] The logger instance
+ def self.[]( name )
+ synchronize { instance.loggers[name] }
+ end
+
+ # Clears all logger instances (handy for testing)
+ def self.clear
+ synchronize { instance.loggers.clear }
+ end
+
+ end
+end
+
View
2  lib/yell/version.rb
@@ -1,7 +1,7 @@
# encoding: utf-8
module Yell #:nodoc:
- VERSION = "0.12.1"
+ VERSION = "0.13.0"
end
View
4 spec/spec_helper.rb
@@ -12,6 +12,10 @@
RSpec.configure do |config|
config.mock_framework = :rr
+ config.before do
+ Yell::Repository.clear
+ end
+
config.after do
Dir[ fixture_path + "/*.log" ].each { |f| File.delete f }
end
View
41 spec/threaded/yell_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+describe "running Yell multi-threaded" do
+ let( :threads ) { 100 }
+
+ let( :filename ) { fixture_path + '/threaded.log' }
+ let( :lines ) { `wc -l #{filename}`.to_i }
+
+ it "should write all messages from one instance" do
+ logger = Yell.new( filename )
+
+ (1..threads).map do |count|
+ Thread.new { 10.times { logger.info count } }
+ end.each(&:join)
+
+ lines.should == 10*threads
+ end
+
+ # it "should write all messages from multiple instances" do
+ # (1..threads).map do |count|
+ # logger = Yell.new( filename )
+
+ # Thread.new do
+ # 10.times { logger.info count }
+ # end
+ # end.each(&:join)
+
+ # lines.should == 10*threads
+ # end
+
+ it "should write all messages from one repository" do
+ Yell[ 'threaded' ] = Yell.new( filename )
+
+ (1..threads).map do |count|
+ Thread.new { 10.times { Yell['threaded'].info count } }
+ end.each(&:join)
+
+ lines.should == 10*threads
+ end
+
+end
View
33 spec/yell/repository_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe Yell::Repository do
+ let( :name ) { 'test' }
+ let( :logger ) { Yell.new :stdout }
+
+ subject { Yell[name] }
+
+
+ context ".[]" do
+ context "when not set" do
+ it { should be_nil }
+ end
+
+ context "when assigned" do
+ before do
+ Yell[ name ] = logger
+ end
+
+ it { should == logger }
+ end
+ end
+
+ context ".[]=" do
+ before do
+ Yell[ name ] = logger
+ end
+
+ it { should == logger }
+ end
+
+end
+

No commit comments for this range

Something went wrong with that request. Please try again.