syslogger 1.6.2 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32d5b47d8aa6a4b2a3df0bf108b8ed76fea1540a
4
- data.tar.gz: 314383df890e4fa2badaeb3a9b39f4f148f626be
3
+ metadata.gz: 55d44b66d0d0f21132b492ac60cca50af4b3af74
4
+ data.tar.gz: f352bce8e245b7a0766c8f487f1b90cffd1c7aac
5
5
  SHA512:
6
- metadata.gz: 5762ef3865af23f47acdeb71f4b8d197780a7a02b87604b53e561871fe9ac8815a794e41024b3f4ef57f8ff6e6c657166165a4b5ec021c855f6f26d574202585
7
- data.tar.gz: ff39d2bf1863e1c391cb3c6b7f4625c9aa021838463df85be82d1801192f4ea6e18ab50c6f8912c055faebaf4c9dff036687628bb88709c895caec807ac3d579
6
+ metadata.gz: 561f991cf10f575fbcc79780af70ef52f586895ce0aa232d1405ddb957cb9b17847d41b8d02b31108700670ca62ed917a74d4b18567f90f5bd7d6033c447f93e
7
+ data.tar.gz: 37c03b6e2241578271de3027587fe06a96c938a0b540a04882c6de58af3b9220964179cd033c38489b9d340cda977dd16e79396f3536ba7c2ceb7510719349f5
@@ -4,7 +4,9 @@ require 'thread'
4
4
 
5
5
  class Syslogger
6
6
 
7
- VERSION = "1.6.2"
7
+ VERSION = "1.6.3"
8
+
9
+ MUTEX = Mutex.new
8
10
 
9
11
  attr_reader :level, :ident, :options, :facility, :max_octets
10
12
  attr_accessor :formatter
@@ -47,7 +49,6 @@ class Syslogger
47
49
  @options = options || (Syslog::LOG_PID | Syslog::LOG_CONS)
48
50
  @facility = facility
49
51
  @level = Logger::INFO
50
- @mutex = Mutex.new
51
52
  @formatter = proc do |severity, datetime, progname, msg|
52
53
  msg
53
54
  end
@@ -90,12 +91,13 @@ class Syslogger
90
91
  message, progname = progname, nil
91
92
  end
92
93
  progname ||= @ident
93
-
94
- @mutex.synchronize do
94
+ mask = Syslog::LOG_UPTO(MAPPING[@level])
95
+ communication = clean(message || block && block.call)
96
+ formatted_communication = formatter.call([severity], Time.now, progname, communication)
97
+
98
+ MUTEX.synchronize do
95
99
  Syslog.open(progname, @options, @facility) do |s|
96
- s.mask = Syslog::LOG_UPTO(MAPPING[@level])
97
- communication = clean(message || block && block.call)
98
- formatted_communication = formatter.call([severity], Time.now, progname, communication)
100
+ s.mask = mask
99
101
  if self.max_octets
100
102
  buffer = "#{tags_text}"
101
103
  formatted_communication.bytes do |byte|
@@ -102,6 +102,40 @@ describe "Syslogger" do
102
102
  logger.write "yop"
103
103
  end
104
104
 
105
+ it "should allow multiple instances to log at the same time" do
106
+ logger1 = Syslogger.new("my_app1", Syslog::LOG_PID, Syslog::LOG_USER)
107
+ logger2 = Syslogger.new("my_app2", Syslog::LOG_PID, Syslog::LOG_USER)
108
+
109
+ thread1 = Thread.new do
110
+ 5000.times do |i|
111
+ logger1.write "logger1"
112
+ end
113
+ end
114
+
115
+ thread2 = Thread.new do
116
+ 5000.times do |i|
117
+ logger2.write "logger1"
118
+ end
119
+ end
120
+
121
+ thread1.join
122
+ thread2.join
123
+ end
124
+
125
+ it "should not fail under chaos" do
126
+ threads = []
127
+ (1..10).each do
128
+ threads << Thread.new do
129
+ (1..100).each do |index|
130
+ logger = Syslogger.new(Thread.current.inspect, Syslog::LOG_PID, Syslog::LOG_USER)
131
+ logger.write index
132
+ end
133
+ end
134
+ end
135
+
136
+ threads.each{|thread| thread.join }
137
+ end
138
+
105
139
  describe "add" do
106
140
  before do
107
141
  @logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syslogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Rohr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-08 00:00:00.000000000 Z
11
+ date: 2015-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake