Skip to content

Commit b821d50

Browse files
committed
Use custom UtilLinuxLogger instead syslog
`syslog` used to be part of StdLib. But beginning with Ruby 3.4, it was extracted into default gems. This is problematic when Ruby is executed with `--disable-gems`, because there is no easy way to require `syslog`. Therefore, this commit introduces custom `UtilLinuxLogger`. This use `logger` command from util-linux and implemnts just minimal `Syslog` interface required. While this could have been used just as a fallback, when `syslog` can't be required, it will be easier to use it every time. Fixes #12
1 parent 591aafd commit b821d50

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ gem "abrt", :require => false
1818

1919
line into your *Gemfile*.
2020

21+
### Dependencies
22+
23+
This library is `logger` utility from util-linux for logging purposes. Please
24+
make sure it is available on your system for proper functionality.
25+
2126
## Usage
2227

2328
There are several ways how to run any application with ABRT handler enabled.

lib/abrt/handler.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'socket'
2-
require 'syslog'
2+
require_relative 'util_linux_logger'
33
require_relative 'exception'
44

55
module ABRT
@@ -16,7 +16,7 @@ def self.handle_exception(exception)
1616
private
1717

1818
def self.syslog
19-
@syslog ||= Syslog.open 'abrt'
19+
@syslog ||= UtilLinuxLogger.open 'abrt'
2020
end
2121

2222
def self.report(exception, io = nil)

lib/abrt/util_linux_logger.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# UtilLinuxLogger is small utility class intended to be drop in replacement for
2+
# Syslog. It uses `logger` command from util-linux project to provide system
3+
# logging facilities.
4+
#
5+
# It implements just minimal interface required by ABRT project.
6+
class UtilLinuxLogger
7+
# :yields: syslog
8+
#
9+
# Open the UtilLinuxLoggersyslog facility.
10+
#
11+
# `ident` is a String which identifies the calling program.
12+
def self.open(ident)
13+
self.new(ident)
14+
end
15+
16+
def initialize(ident)
17+
@ident = ident
18+
end
19+
20+
def notice(format_string, *arguments)
21+
log 'user.notice', format_string, *arguments
22+
end
23+
24+
def err(format_string, *arguments)
25+
log 'user.err', format_string, *arguments
26+
end
27+
28+
private
29+
def log(priority, format_string, *arguments)
30+
IO.popen "logger -p #{priority} -t #{@ident} --socket-errors=off", 'w' do |io|
31+
io.write sprintf(format_string, *arguments)
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)