Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed incompatibility with stock logger when using blocks #5

Closed
wants to merge 10 commits into from

5 participants

@chancancode

Specifically, logger.debug('progname') { "A message inside a block" } behaves differently in SyslogLogger and stock logger. In stock logger, "progname" is taken as the progname, and the block will be eval'ed and the result will be used as the log message. In SyslogLogger, "progname" is taken as the message and the block is never evaluated.

@drbrain drbrain was assigned
@chancancode

@tenderlove I noticed that you forked this repo and is prep-ing for a v2.0. However the master branch of this repository seems corrupted... for some reason a bunch of commits were overwritten and lost in the master repo. (See above.) Can you look into this? You might want to pull/rebase from the master branch in my fork.

/cc @drbrain @zenspider

@tenderlove
Owner

Sorry, this repo isn't canonical anymore (but I can't delete it due to the seattlerb p4 sync). Can you send the PR to sparklemotion/sysloglogger ? It is considered canonical now.

@zenspider
Owner
@zenspider
Owner

Sync is turned off. Since there are open issues, I'm not going to delete the project. Please migrate the issues and delete.

@tenderlove
Owner

OK. Thanks @zenspider

@chancancode chancancode referenced this pull request in sparklemotion/sysloglogger
Closed

[DO NOT MERGE] Commits missing #2

@chancancode

Moved this to sparklemotion/sysloglogger#2 and sparklemotion/sysloglogger#3. Closing this ticket here.

@chancancode chancancode closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 5, 2012
  1. @methodmissing
Commits on Mar 22, 2012
  1. @drbrain

    Merge pull request #3 from methodmissing/master

    drbrain authored
    Do not clean messages twice in SyslogLogger#add
  2. @drbrain
  3. @drbrain
  4. @drbrain

    Added .travis.yml

    drbrain authored
  5. @drbrain

    Update README for Hoe

    drbrain authored
  6. @drbrain

    Add git plugin

    drbrain authored
  7. @drbrain

    Remove seattlerb plugin

    drbrain authored
  8. @drbrain

    Set release date

    drbrain authored
Commits on Jun 19, 2012
  1. @chancancode
This page is out of date. Refresh to see the latest.
View
3  .gitignore
@@ -0,0 +1,3 @@
+*.swp
+/doc
+/pkg
View
15 .travis.yml
@@ -0,0 +1,15 @@
+---
+after_script:
+- rake travis:after -t
+before_script:
+- gem install hoe-travis --no-rdoc --no-ri
+- rake travis:before -t
+language: ruby
+notifications:
+ email:
+ - drbrain@segment7.net
+rvm:
+- 1.8.7
+- 1.9.2
+- 1.9.3
+script: rake travis
View
6 History.txt
@@ -1,3 +1,9 @@
+== 1.4.1 / 2012-03-22
+
+* Bug fixes
+ * Messages for syslog() are no longer cleaned twice. Pull Request #3 by
+ Lourens Naudé
+
== 1.4.0 / 2007-05-08
* Split from rails_analyzer_tools.
View
53 README.txt
@@ -1,17 +1,56 @@
= SyslogLogger
+Documentation :: http://docs.seattlerb.org/SyslogLogger
+Source :: https://github.com/seattlerb/sysloglogger
+Bugtracker :: https://github.com/seattlerb/sysloglogger/issues
+
+== DESCRIPTION
+
SyslogLogger is a Logger replacement that logs to syslog. It is almost
-drop-in with a few caveats.
+drop-in with a few differences.
+
+== FEATURES
+
+* Works like Logger
+* Logs to syslog(3) mapping Logger levels to syslog(3) levels
+
+== SYNOPSIS
+
+ require 'syslog_logger'
+
+ logger = SyslogLogger.new 'your_application_name'
+
+ logger.info 'did something cool'
+
+== INSTALL
+
+ gem install SyslogLogger
+
+You may need to configure your syslog.conf to place application logs in a
+particular file. See SyslogLogger for details.
-http://seattlerb.rubyforge.org/SyslogLogger
+== LICENSE
-http://rubyforge.org/projects/seattlerb
+(The MIT License)
-== About
+Copyright (c) Eric Hodel
-See SyslogLogger
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
-== Install
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
- sudo gem install SyslogLogger
+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 NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
7 Rakefile
@@ -1,14 +1,15 @@
# -*- ruby -*-
require 'hoe'
-require './lib/syslog_logger.rb'
-Hoe.plugin :seattlerb
+Hoe.plugin :travis
+Hoe.plugin :git
Hoe.spec 'SyslogLogger' do
developer 'Eric Hodel', 'drbrain@segment7.net'
- self.rubyforge_name = 'seattlerb'
+ rdoc_locations <<
+ 'docs.seattlerb.org:/data/www/docs.seattlerb.org/SyslogLogger'
end
# vim: syntax=Ruby
View
59 lib/syslog_logger.rb
@@ -77,10 +77,15 @@ class SyslogLogger
##
# The version of SyslogLogger you are using.
- VERSION = '1.4.0'
+ VERSION = '1.4.1'
##
# Maps Logger warning types to syslog(3) warning types.
+ #
+ # Messages from ruby applications are not considered as critical as messages
+ # from other processes using syslog(3), so most messages are reduced by one
+ # level. For example, a fatal message for ruby's Logger is considered an
+ # error for syslog(3).
LOGGER_MAP = {
:unknown => :alert,
@@ -114,10 +119,8 @@ class SyslogLogger
def self.make_methods(meth)
eval <<-EOM, nil, __FILE__, __LINE__ + 1
- def #{meth}(message = nil)
- return true if #{LOGGER_LEVEL_MAP[meth]} < @level
- SYSLOG.#{LOGGER_MAP[meth]} clean(message || yield)
- return true
+ def #{meth}(progname = nil, &block)
+ add(Logger::#{meth.upcase}, nil, progname, &block)
end
def #{meth}?
@@ -126,6 +129,42 @@ def #{meth}?
EOM
end
+ ##
+ # :method: unknown
+ #
+ # Logs a +message+ at the unknown (syslog alert) log level, or logs the
+ # message returned from the block.
+
+ ##
+ # :method: fatal
+ #
+ # Logs a +message+ at the fatal (syslog err) log level, or logs the message
+ # returned from the block.
+
+ ##
+ # :method: error
+ #
+ # Logs a +message+ at the error (syslog warning) log level, or logs the
+ # message returned from the block.
+
+ ##
+ # :method: warn
+ #
+ # Logs a +message+ at the warn (syslog notice) log level, or logs the
+ # message returned from the block.
+
+ ##
+ # :method: info
+ #
+ # Logs a +message+ at the info (syslog info) log level, or logs the message
+ # returned from the block.
+
+ ##
+ # :method: debug
+ #
+ # Logs a +message+ at the debug (syslog debug) log level, or logs the
+ # message returned from the block.
+
LOGGER_MAP.each_key do |level|
make_methods level
end
@@ -155,7 +194,15 @@ def initialize(program_name = 'rails')
def add(severity, message = nil, progname = nil, &block)
severity ||= Logger::UNKNOWN
return true if severity < @level
- message = clean(message || block.call)
+
+ if message.nil?
+ if block_given?
+ message = yield
+ else
+ message = progname
+ end
+ end
+
SYSLOG.send LEVEL_LOGGER_MAP[severity], clean(message)
return true
end
View
18 test/test_syslog_logger.rb
@@ -50,12 +50,12 @@ class Log
attr_reader :line, :label, :datetime, :pid, :severity, :progname, :msg
def initialize(line)
@line = line
- /\A(\w+), \[([^#]*)#(\d+)\]\s+(\w+) -- (\w*): ([\x0-\xff]*)/ =~ @line
+ /\A(\w+), \[([^#]*)#(\d+)\]\s+(\w+) -- (\w*): ([\x0-\xff]*)\n\z/ =~ @line
@label, @datetime, @pid, @severity, @progname, @msg = $1, $2, $3, $4, $5, $6
end
end
- def log_add(severity, msg, progname = nil, &block)
+ def log_add(severity, msg = nil, progname = nil, &block)
log(:add, severity, msg, progname, &block)
end
@@ -443,6 +443,18 @@ def test_debug_eh
assert_equal false, @logger.debug?
end
+ def test_blocks
+ message = 'A message logged from within a block'
+ msg = log(:debug) { message }
+ assert_equal LEVEL_LABEL_MAP[Logger::DEBUG], msg.severity
+ assert_equal message, msg.msg
+
+ # Test compatibility with logger.debug('progname') { 'a message' }
+ msg = log(:debug, 'progname') { message }
+ assert_equal LEVEL_LABEL_MAP[Logger::DEBUG], msg.severity
+ assert_equal message, msg.msg
+ end
+
end
class TestSyslogLogger < TestLogger
@@ -464,7 +476,7 @@ def initialize(line)
end
end
- def log_add(severity, msg, progname = nil, &block)
+ def log_add(severity, msg = nil, progname = nil, &block)
log(:add, severity, msg, progname, &block)
end
Something went wrong with that request. Please try again.