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

Multiple lines #3

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Manifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
lib/syslog-logger.rb
lib/syslog-ml-logger.rb
lib/syslog-formatter.rb
Manifest
Rakefile
README.rdoc
syslog-logger.gemspec
syslog-ml-logger.gemspec
test/test_syslog_logger.rb
20 changes: 16 additions & 4 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
= SyslogLogger
= SyslogMlLogger

http://github.com/ngmoco/sysloglogger
http://github.com/Daniel304/syslog-ml-logger
http://rubygems.org/gems/syslog-ml-logger

== DESCRIPTION:

Expand All @@ -17,17 +18,21 @@ will be ignored.
This particular Logger::Syslog improves the original by correctly mapping Rails log severities to
the Syslog counterparts. It also adds the ability to select a syslog facility other than "user."

Version 1.8.2 quick fix
Version 1.8.1 fixed missing last character thanks to fork of scambra and undefined method each-line when message isn't an array.
Version 1.8.0 cuts lines longer then 1024 characters in multiple lines cause syslog cuts them off.
Version 1.7.3 sends multiple lines to the syslog server instead of one large line which is cut of.
Version 1.6.7 takes a formatter as logger does and uses call to format the message.

== SYNOPSIS:

=== config/environment.rb

config.gem 'syslog-logger'
require 'syslog-ml-logger'

=== Gemfile

gem 'syslog-logger'
gem 'syslog-ml-logger'

=== config/environments/production.rb

Expand All @@ -39,6 +44,10 @@ By default, Logger::Syslog uses the program name 'rails' and the facility 'user'
changed via the arguments to Logger::Syslog.new:

RAILS_DEFAULT_LOGGER = Logger::Syslog.new('mygreatapp', Syslog::LOG_LOCAL7)

Or use when using multiple environments with multiple projects

config.logger = Logger::Syslog.new(Rails.env + '-' + Rails.root.to_s.gsub(/\/[path-to-rails-apps]\/(.*)\/ruby/,'\1'), Syslog::LOG_LOCAL0)

=== BSD syslog setup

Expand Down Expand Up @@ -90,6 +99,9 @@ syslogd(8) manpage for further details.

== LICENSE:

Extending below with:
Copyright (c) 2012, Daniel van den Oord

Copyright (c) 2008, 2009 Eric Hodel, Christopher Powell, Ian Lesperance,
Dana Contreras, Brian Smith, Ashley Martens

Expand Down
18 changes: 9 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ rescue LoadError
end

jt = Jeweler::Tasks.new do |gem|
gem.name = "syslog-logger"
gem.summary = "An improved Logger replacement that logs to syslog. It is almost drop-in with a few caveats."
gem.description = "An improved Logger replacement that logs to syslog. It is almost drop-in with a few caveats."
gem.email = "[email protected]"
gem.homepage = "http://github.com/ngmoco/syslog_logger"
gem.authors = ["Eric Hodel; Chris Powell; Matthew Boeh; Ian Lesperance; Dana Danger; Brian Smith; Ashley Martens"]
gem.files = FileList["lib/syslog-logger.rb", "lib/syslog-formatter.rb", "README.rdoc"]
gem.name = "syslog-ml-logger"
gem.summary = "An improved Logger replacement that logs multiple-lines to syslog. It is almost drop-in with a few caveats."
gem.description = "An improved Logger replacement that logs multiple-lines to syslog. It is almost drop-in with a few caveats."
gem.email = "[email protected]"
gem.homepage = "https://github.com/Daniel304/syslog-ml-logger"
gem.authors = ["Daniel van den Oord;Erwin Rohde,Eric Hodel; Chris Powell; Matthew Boeh; Ian Lesperance; Dana Danger; Brian Smith; Ashley Martens"]
gem.files = FileList["lib/syslog-ml-logger.rb", "lib/syslog-formatter.rb", "README.rdoc"]
gem.test_files = FileList["test/test_syslog_logger.rb"]
gem.has_rdoc = true
gem.extra_rdoc_files = ["README.rdoc"]
gem.rdoc_options = ["--line-numbers", "--inline-source", "--title", "SyslogLogger", "--main", "README.rdoc"]
end
Jeweler::GemcutterTasks.new

task :default => :package
task :default => :test

$dir = File.dirname(__FILE__)

Expand All @@ -42,6 +42,6 @@ task :publish => [ :test, :build ] do
system "git tag v#{jt.jeweler.version}"
system "git push origin v#{jt.jeweler.version}"
system "git push origin master"
system "gem push pkg/syslog-logger-#{jt.jeweler.version}.gem"
system "gem push pkg/syslog-ml-logger-#{jt.jeweler.version}.gem"
system "git clean -fd"
end
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.8
1.8.2
15 changes: 3 additions & 12 deletions lib/syslog-formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# [Time.mSec] [SeverityLabel]: message

class Logger::SyslogFormatter < Logger::Formatter
Format = "[%s] [%5s]: %s\n"
Format = "[%5s]: %s\n"

attr_accessor :datetime_format

Expand All @@ -12,19 +12,11 @@ def initialize
end

def call(severity, time, progname, msg)
Format % [format_datetime(time), severity, msg2str(msg)]
Format % [severity, msg2str(msg)]
end

protected

def format_datetime(time)
if @datetime_format.nil?
time.strftime("%H:%M:%S.") << "%06d " % time.usec
else
time.strftime(@datetime_format)
end
end

def msg2str(msg)
case msg
when ::String
Expand All @@ -36,5 +28,4 @@ def msg2str(msg)
msg.inspect
end
end

end
end
23 changes: 20 additions & 3 deletions lib/syslog-logger.rb → lib/syslog-ml-logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ class Logger::Syslog
include Logger::Severity

# The version of Logger::Syslog you are using.
VERSION = '1.6.8'
VERSION = '1.8.2'

# Max length of syslog string
MAXLENGTH = 1024

# From 'man syslog.h':
# LOG_EMERG A panic condition was reported to all processes.
Expand Down Expand Up @@ -117,7 +120,13 @@ def add(severity, message = nil, progname = nil, &block)
progname = @progname
end
end
SYSLOG.send(LEVEL_LOGGER_MAP[severity], format_message(format_severity(severity), Time.now, progname, clean(message)))

# breakup multiple lines into multiple syslog messages
message.each do | line |
cut(line).each do |msg|
SYSLOG.send(LEVEL_LOGGER_MAP[severity], format_message(format_severity(severity), Time.now, progname, clean(msg)))
end
end
true
end

Expand Down Expand Up @@ -158,4 +167,12 @@ def clean(message)
return message
end

end
# Cut lines in strings having a max length of 1024
def cut(line)
msgs = []
(0..(line.length / MAXLENGTH)).each do |i|
msgs << line[i*MAXLENGTH, MAXLENGTH + 1]
end
return msgs
end
end
41 changes: 41 additions & 0 deletions syslog-ml-logger.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = "syslog-ml-logger"
s.version = "1.8.2"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Daniel van den Oord;Erwin Rohde,Eric Hodel; Chris Powell; Matthew Boeh; Ian Lesperance; Dana Danger; Brian Smith; Ashley Martens"]
s.date = "2012-12-04"
s.description = "An improved Logger replacement that logs multiple-lines to syslog. It is almost drop-in with a few caveats."
s.email = "[email protected]"
s.extra_rdoc_files = [
"README.rdoc"
]
s.files = [
"README.rdoc",
"lib/syslog-formatter.rb",
"lib/syslog-ml-logger.rb"
]
s.homepage = "https://github.com/Daniel304/syslog-ml-logger"
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "SyslogLogger", "--main", "README.rdoc"]
s.require_paths = ["lib"]
s.rubygems_version = "1.8.24"
s.summary = "An improved Logger replacement that logs multiple-lines to syslog. It is almost drop-in with a few caveats."
s.test_files = [
"test/test_syslog_logger.rb"
]

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

2 changes: 1 addition & 1 deletion test/test_syslog_logger.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test/unit'
require 'tempfile'
require 'syslog-logger'
require 'syslog-ml-logger'

module MockSyslog; end

Expand Down