diff --git a/Manifest b/Manifest index 25caa14..8d611f2 100644 --- a/Manifest +++ b/Manifest @@ -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 diff --git a/README.rdoc b/README.rdoc index 8d7f95d..3d5b10d 100644 --- a/README.rdoc +++ b/README.rdoc @@ -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: @@ -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 @@ -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 @@ -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 diff --git a/Rakefile b/Rakefile index a70bd24..375a92f 100644 --- a/Rakefile +++ b/Rakefile @@ -11,13 +11,13 @@ 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 = "teamplatform@ngmoco.com" - 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 = "daniel304@chello.nl" + 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"] @@ -25,7 +25,7 @@ jt = Jeweler::Tasks.new do |gem| end Jeweler::GemcutterTasks.new -task :default => :package +task :default => :test $dir = File.dirname(__FILE__) @@ -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 diff --git a/VERSION b/VERSION index cfe11fd..53adb84 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6.8 \ No newline at end of file +1.8.2 diff --git a/lib/syslog-formatter.rb b/lib/syslog-formatter.rb index b0420ff..14c264c 100644 --- a/lib/syslog-formatter.rb +++ b/lib/syslog-formatter.rb @@ -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 @@ -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 @@ -36,5 +28,4 @@ def msg2str(msg) msg.inspect end end - -end \ No newline at end of file +end diff --git a/lib/syslog-logger.rb b/lib/syslog-ml-logger.rb similarity index 90% rename from lib/syslog-logger.rb rename to lib/syslog-ml-logger.rb index 041a2ad..162b5d6 100644 --- a/lib/syslog-logger.rb +++ b/lib/syslog-ml-logger.rb @@ -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. @@ -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 @@ -158,4 +167,12 @@ def clean(message) return message end -end \ No newline at end of file + # 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 diff --git a/syslog-ml-logger.gemspec b/syslog-ml-logger.gemspec new file mode 100644 index 0000000..2e9d122 --- /dev/null +++ b/syslog-ml-logger.gemspec @@ -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 = "daniel304@chello.nl" + 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 + diff --git a/test/test_syslog_logger.rb b/test/test_syslog_logger.rb index d768f76..d4cd86d 100644 --- a/test/test_syslog_logger.rb +++ b/test/test_syslog_logger.rb @@ -1,6 +1,6 @@ require 'test/unit' require 'tempfile' -require 'syslog-logger' +require 'syslog-ml-logger' module MockSyslog; end