semlogger

This commit is contained in:
Denis Knauf 2012-05-14 12:02:50 +02:00
parent bef0442c3b
commit 431028811e
13 changed files with 76 additions and 54 deletions

3
.gitignore vendored
View file

@ -1,5 +1,4 @@
*.gemspec
*.gem
t*.gem
*.rbc
.bundle
.config

View file

@ -1,4 +1,4 @@
Slogger
Semlogger
=======
(Semi-)Structured Logger for Ruby (and Rails)
(Semi-)Structured Logger for Ruby (and Rails)

View file

@ -4,11 +4,11 @@ require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "slogger"
gem.name = "semlogger"
gem.summary = %Q{(Semi-)Structured Logger}
gem.description = %Q{(Semi-)Structured Logger for Ruby (and Rails)}
gem.email = %w[Denis.Knauf@gmail.com]
gem.homepage = "http://github.com/DenisKnauf/Slogger"
gem.homepage = "http://github.com/DenisKnauf/semlogger"
gem.authors = ["Denis Knauf"]
gem.files = %w[AUTHORS README.md VERSION LICENSE lib/**/*.rb]
gem.require_paths = %w[lib]
@ -52,7 +52,7 @@ Rake::RDocTask.new do |rdoc|
end
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "Slogger #{version}"
rdoc.title = "semlogger #{version}"
rdoc.rdoc_files.include 'README.md'
rdoc.rdoc_files.include 'AUTHORS'
rdoc.rdoc_files.include 'LICENSE'

View file

@ -1,9 +1,9 @@
require 'json'
class Slogger < ::Logger
class Semlogger < ::Logger
def initialize logdev = nil, *a, &e
case logdev
when String, nil then logdev = ::Slogger::Writer.new logdev
when String, nil then logdev = ::Semlogger::Writer.new logdev
end
@level, @data, @tags, @logdev = DEBUG, {}, [], logdev
end
@ -75,8 +75,8 @@ class Slogger < ::Logger
end
end
require 'slogger/rotate'
require 'slogger/multiplex'
require 'slogger/rack'
require 'slogger/filter'
require 'slogger/writer'
require 'semlogger/rotate'
require 'semlogger/multiplex'
require 'semlogger/rack'
require 'semlogger/filter'
require 'semlogger/writer'

View file

@ -1,4 +1,4 @@
class Slogger::Filter
class Semlogger::Filter
attr_accessor :level, :logdev
def initialize level, logdev
@ -15,9 +15,9 @@ end
%w[debug info warn error fatal].each do |level|
eval <<-EOC
class ::Slogger::F#{level.camelcase} < Slogger::Filter
class ::Semlogger::F#{level.camelcase} < Semlogger::Filter
def initialize *a
super Slogger::#{level.upcase}, *a
super Semlogger::#{level.upcase}, *a
end
end
EOC

View file

@ -1,4 +1,4 @@
class Slogger::Formatter < ::Logger::Formatter
class Semlogger::Formatter < ::Logger::Formatter
def initialize tags, data
@tags, @data = tags, data
end

View file

@ -1,4 +1,4 @@
class Slogger::Multiplex
class Semlogger::Multiplex
def initialize( *dests) @__dests__ = dests end
def write( *a, &e) @__dests__.each {|d| d.write *a, &e } end

View file

@ -1,4 +1,4 @@
class Slogger::Rack < Rails::Rack::Logger
class Semlogger::Rack < Rails::Rack::Logger
def initialize app, tags = nil, data = nil
super app, tags
@data = data

View file

@ -1,4 +1,4 @@
class Slogger::Rotate
class Semlogger::Rotate
attr_reader :file
def filename() @filename.dup end

View file

@ -1,4 +1,4 @@
class Slogger::Tailer < Rails::Rack::LogTailer
class Semlogger::Tailer < Rails::Rack::LogTailer
def initialize app, log = nil
@app = app
log ||= Rails.root.join( 'log', Rails.env).to_s.gsub('%', '%%') + '.%Y-%m-%d.%$.log'

View file

@ -1,9 +1,9 @@
class Slogger::Output
class Semlogger::Output
end
class Slogger::Writer < Slogger::Output
class Semlogger::Writer < Semlogger::Output
def initialize logdev = nil
@logdev = logdev || ::Slogger::Rotate.new( ::Rails.root.join( 'log', ::Rails.env).to_s.gsub('%', '%%') + '.%Y-%m-%d.%$.log')
@logdev = logdev || ::Semlogger::Rotate.new( ::Rails.root.join( 'log', ::Rails.env).to_s.gsub('%', '%%') + '.%Y-%m-%d.%$.log')
end
def add severity, time, progname, data, tags, message
@ -11,7 +11,7 @@ class Slogger::Writer < Slogger::Output
end
end
class Slogger::Printer < Slogger::Output
class Semlogger::Printer < Semlogger::Output
def initialize logdev = nil
@logdev = logdev || $stdout
@last_reqid = nil

View file

@ -1,28 +0,0 @@
class Slogger::Transaction
include UUIDTools
attr_reader :app, :id, :default_id
class <<self
attr_accessor :transaction
def to_s() transaction.to_s end
def id() transaction.id end
end
def new_id
UUID.random_create
end
def initialize app, logger = nil, default_id = nil
@app, @default_id = app, default_id || new_id
(logger||self.class).transaction = self
end
def call *paras
@id = new_id
@app.call *paras
ensure
@id = @default_id
end
def to_s() @id.to_s end
end

51
semlogger.gemspec Normal file
View file

@ -0,0 +1,51 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{semlogger}
s.version = "0.0.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Denis Knauf"]
s.date = %q{2012-05-14}
s.description = %q{(Semi-)Structured Logger for Ruby (and Rails)}
s.email = ["Denis.Knauf@gmail.com"]
s.extra_rdoc_files = [
"LICENSE",
"README.md"
]
s.files = [
"AUTHORS",
"LICENSE",
"README.md",
"VERSION",
"lib/semlogger.rb",
"lib/semlogger/filter.rb",
"lib/semlogger/formatter.rb",
"lib/semlogger/multiplex.rb",
"lib/semlogger/rack.rb",
"lib/semlogger/rotate.rb",
"lib/semlogger/tailer.rb",
"lib/semlogger/writer.rb"
]
s.homepage = %q{http://github.com/DenisKnauf/semlogger}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.7}
s.summary = %q{(Semi-)Structured Logger}
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<json>, [">= 0"])
else
s.add_dependency(%q<json>, [">= 0"])
end
else
s.add_dependency(%q<json>, [">= 0"])
end
end