apple-system-logger 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47eaba8480a9a1a1645cb05b1097fae01083b9d9f10052ee2818472739b8eaff
4
- data.tar.gz: 8d726f6fbeb7764af96d897cc925b7c609dce96b327e26140e514e8df381bcae
3
+ metadata.gz: 87eeec07795f0ea6b45a066e3178d8fe8a196c5157c862f2479b0fff701fd9c0
4
+ data.tar.gz: f474804c60c51890aaa6ab827f397ea5dc38478e24e0fd3bb11309ae736c0b28
5
5
  SHA512:
6
- metadata.gz: 9a98f320a286f69bf5eab1813c70e5f6c635be8117b3bc5a8f8fc37c78fc1111ed54d86795e0b44ed57ffca2ee72b6d5c76a5d5cebabd5885081714fa2619510
7
- data.tar.gz: 0b53d9d699d57e1c36482eb2134b4b6c2aff8078a39e67c2a0d9682754b898f228251b583e112929a1d41daa70d464ad272afe80fb5fa106d5fee5f81c00b473
6
+ metadata.gz: b1e95379ce5810a866eea2d95cdf7aaa987a80ee4925d328c30400560f5d2580ed0222b8cf2b30a9bcfb76e04de89e14f44f22fb1baacd5e26f7153296999023
7
+ data.tar.gz: 6cb129e0da3705ef0f1fd22a3a572faf9412d4e6a666b05d633c1b06b531ac6c864e0b0ac06d169a4a181c7865b257f83cc8c59b9d69e87083d00c947e43d09e
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.2.0 - 24-Jan-2026
2
+ * Make it thread safe.
3
+
1
4
  ## 0.1.3 - 28-Dec-2025
2
5
  * Fixed the missing message parameter for the error and fatal methods.
3
6
  * Added stricter enforcement for search keys.
data/README.md CHANGED
@@ -45,7 +45,7 @@ because the API does not explicitly forbid other file descriptors, nor
45
45
  does it raise an error.
46
46
 
47
47
  ## Copyright
48
- (C) 2020-2025 Daniel J. Berger, All Rights Reserved
48
+ (C) 2020-2026 Daniel J. Berger, All Rights Reserved
49
49
 
50
50
  ## Warranty
51
51
  This package is provided "as is" and without any express or
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'apple-system-logger'
5
- spec.version = '0.1.3'
5
+ spec.version = '0.2.0'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.email = 'djberg96@gmail.com'
8
8
  spec.license = 'Apache-2.0'
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'logger/functions'
4
4
  require_relative 'logger/constants'
5
+ require 'thread'
5
6
 
6
7
  # The Apple module serves as a namespace only.
7
8
  module Apple
@@ -13,7 +14,7 @@ module Apple
13
14
  include Apple::System::LoggerConstants
14
15
 
15
16
  # The version of this library.
16
- VERSION = '0.1.3'
17
+ VERSION = '0.2.0'
17
18
 
18
19
  # A syslogd facility. The system default is 'user'.
19
20
  attr_reader :facility
@@ -68,6 +69,8 @@ module Apple
68
69
  # TODO: Add string format support and apply it to messages.
69
70
  #
70
71
  def initialize(**kwargs)
72
+ @mutex = Mutex.new
73
+
71
74
  @facility = kwargs[:facility]
72
75
  @level = kwargs[:level] || ASL_LEVEL_DEBUG
73
76
  @progname = kwargs[:progname]
@@ -97,19 +100,25 @@ module Apple
97
100
  # Dump a message with no formatting at the current severity level.
98
101
  #
99
102
  def <<(message)
100
- asl_log(@aslclient, @aslmsg, @level, message)
103
+ @mutex.synchronize do
104
+ asl_log(@aslclient, @aslmsg, @level, message)
105
+ end
101
106
  end
102
107
 
103
108
  # Log a message at the given level.
104
109
  #
105
110
  def add(level, message)
106
- asl_log(@aslclient, @aslmsg, level, message)
111
+ @mutex.synchronize do
112
+ asl_log(@aslclient, @aslmsg, level, message)
113
+ end
107
114
  end
108
115
 
109
116
  # Log a debug message.
110
117
  #
111
118
  def debug(message)
112
- asl_log(@aslclient, @aslmsg, ASL_LEVEL_DEBUG, message)
119
+ @mutex.synchronize do
120
+ asl_log(@aslclient, @aslmsg, ASL_LEVEL_DEBUG, message)
121
+ end
113
122
  end
114
123
 
115
124
  # Returns true if the current severity level allows for the printing of debug messages.
@@ -121,7 +130,9 @@ module Apple
121
130
  # Log an info message.
122
131
  #
123
132
  def info(message)
124
- asl_log(@aslclient, @aslmsg, ASL_LEVEL_INFO, message)
133
+ @mutex.synchronize do
134
+ asl_log(@aslclient, @aslmsg, ASL_LEVEL_INFO, message)
135
+ end
125
136
  end
126
137
 
127
138
  # Returns true if the current severity level allows for the printing of info messages.
@@ -133,7 +144,9 @@ module Apple
133
144
  # Log a warning message.
134
145
  #
135
146
  def warn(message)
136
- asl_log(@aslclient, @aslmsg, ASL_LEVEL_WARNING, message)
147
+ @mutex.synchronize do
148
+ asl_log(@aslclient, @aslmsg, ASL_LEVEL_WARNING, message)
149
+ end
137
150
  end
138
151
 
139
152
  # Returns true if the current severity level allows for the printing of warning messages.
@@ -145,7 +158,9 @@ module Apple
145
158
  # Log an error message.
146
159
  #
147
160
  def error(message)
148
- asl_log(@aslclient, @aslmsg, ASL_LEVEL_ERR, message)
161
+ @mutex.synchronize do
162
+ asl_log(@aslclient, @aslmsg, ASL_LEVEL_ERR, message)
163
+ end
149
164
  end
150
165
 
151
166
  # Returns true if the current severity level allows for the printing of error messages.
@@ -157,7 +172,9 @@ module Apple
157
172
  # Log a fatal message. For this library that means an ASL_LEVEL_CRIT message.
158
173
  #
159
174
  def fatal(message)
160
- asl_log(@aslclient, @aslmsg, ASL_LEVEL_CRIT, message)
175
+ @mutex.synchronize do
176
+ asl_log(@aslclient, @aslmsg, ASL_LEVEL_CRIT, message)
177
+ end
161
178
  end
162
179
 
163
180
  # Returns true if the current severity level allows for the printing of fatal messages.
@@ -169,7 +186,9 @@ module Apple
169
186
  # Log an unknown message. For this library that means an ASL_LEVEL_EMERG message.
170
187
  #
171
188
  def unknown(message)
172
- asl_log(@aslclient, @aslmsg, ASL_LEVEL_EMERG, message)
189
+ @mutex.synchronize do
190
+ asl_log(@aslclient, @aslmsg, ASL_LEVEL_EMERG, message)
191
+ end
173
192
  end
174
193
 
175
194
  # Search the logs using the provided query. The query should be a hash of
@@ -223,57 +242,66 @@ module Apple
223
242
  # log.search(:uid => 501, :time => Time.now - 3600)
224
243
  #
225
244
  def search(query)
226
- aslmsg = asl_new(ASL_TYPE_QUERY)
227
- result = []
245
+ @mutex.synchronize do
246
+ result = []
228
247
 
229
- query.each do |key, value|
230
- asl_key = map_key_to_asl_key(key)
248
+ aslmsg = asl_new(ASL_TYPE_QUERY)
231
249
 
232
- flags = ASL_QUERY_OP_EQUAL
233
- flags = (flags | ASL_QUERY_OP_NUMERIC) if value.is_a?(Numeric)
234
- flags = (flags | ASL_QUERY_OP_TRUE) if value == true
250
+ query.each do |key, value|
251
+ asl_key = map_key_to_asl_key(key)
235
252
 
236
- if value.is_a?(Time)
237
- flags = (flags | ASL_QUERY_OP_GREATER_EQUAL)
238
- value = value.to_i
239
- end
253
+ flags = ASL_QUERY_OP_EQUAL
254
+ flags = (flags | ASL_QUERY_OP_NUMERIC) if value.is_a?(Numeric)
255
+ flags = (flags | ASL_QUERY_OP_TRUE) if value == true
256
+
257
+ if value.is_a?(Time)
258
+ flags = (flags | ASL_QUERY_OP_GREATER_EQUAL)
259
+ value = value.to_i
260
+ end
261
+
262
+ if value.is_a?(Regexp)
263
+ flags = (flags | ASL_QUERY_OP_REGEX)
264
+ flags = (flags | ASL_QUERY_OP_CASEFOLD) if value.casefold?
265
+ end
240
266
 
241
- if value.is_a?(Regexp)
242
- flags = (flags | ASL_QUERY_OP_REGEX)
243
- flags = (flags | ASL_QUERY_OP_CASEFOLD) if value.casefold?
267
+ asl_set_query(aslmsg, asl_key, value.to_s, flags)
244
268
  end
245
269
 
246
- asl_set_query(aslmsg, asl_key, value.to_s, flags)
247
- end
270
+ response = asl_search(@aslclient, aslmsg)
248
271
 
249
- response = asl_search(@aslclient, aslmsg)
250
-
251
- while m = aslresponse_next(response)
252
- break if m.null?
253
- i = 0
254
- hash = {}
255
- while key = asl_key(m, i)
256
- break if key.nil? || key.empty?
257
- value = asl_get(m, key)
258
- hash[key] = value
259
- i += 1
272
+ if response.nil?
273
+ raise RuntimeError, "asl_search function call failed"
260
274
  end
261
- result << hash
262
- end
263
275
 
264
- result
265
- ensure
266
- aslresponse_free(response) if response
267
- asl_free(aslmsg)
276
+ while m = aslresponse_next(response)
277
+ break if m.null?
278
+ i = 0
279
+ hash = {}
280
+ while key = asl_key(m, i)
281
+ break if key.nil? || key.empty?
282
+ value = asl_get(m, key)
283
+ hash[key] = value
284
+ i += 1
285
+ end
286
+ result << hash
287
+ end
288
+
289
+ result
290
+ ensure
291
+ aslresponse_free(response) if response
292
+ asl_free(aslmsg)
293
+ end
268
294
  end
269
295
 
270
296
  # Close the logger instance. You should always do this.
271
297
  #
272
298
  def close
273
- asl_free(@aslmsg) if @aslmsg
274
- asl_close(@aslclient) if @aslclient
275
- @aslmsg = nil
276
- @aslclient = nil
299
+ @mutex.synchronize do
300
+ asl_free(@aslmsg) if @aslmsg
301
+ asl_close(@aslclient) if @aslclient
302
+ @aslmsg = nil
303
+ @aslclient = nil
304
+ end
277
305
  end
278
306
 
279
307
  private
@@ -7,7 +7,7 @@ RSpec.describe Apple::System::Logger do
7
7
 
8
8
  context 'version' do
9
9
  example 'version constant is set to expected value' do
10
- expect(described_class::VERSION).to eql('0.1.3')
10
+ expect(described_class::VERSION).to eql('0.2.0')
11
11
  end
12
12
 
13
13
  example 'version constant is frozen' do
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apple-system-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  - !ruby/object:Gem::Version
154
154
  version: '0'
155
155
  requirements: []
156
- rubygems_version: 3.7.2
156
+ rubygems_version: 4.0.3
157
157
  specification_version: 4
158
158
  summary: A Ruby interface for the Apple System Logger
159
159
  test_files:
metadata.gz.sig CHANGED
@@ -1,2 +1 @@
1
- BB"Kd5&�|[��y��m5nGRc��R&.|��g��E���|U�K�ɄJa�)��a�~�D--����om������A��‚�I2��P���uyGI���O��4�$sy1��N=�����I&�$zKO������!l�a��첵�(f��!I����=tC�8d]˅P ܭ�Nd,cF7R5]>���ޜ?��A�/��L
2
- `g
1
+ ���G���c�݊���KV�. ��〼:j1��� jWȐu�]��[U23�b������׈Y�(���A�~%�t���}�j�����g��7,�GN���H�G��{��y�Vf=�W�˭��fb���)��N ��%B6[Mm���xLj�4e����cKP{K���am3���K{����=�N^��Mk��)����W�A�����\�V��6��7rА� ���܍��C�U��W;��p��[�@8A��6jz�祦)r ���LR��Zg����^�O�����KT�=����$�!����W)�|�����)5�a����ʷ�}��iQ��:�Zw��9e���c��������췣�� ��x�<'B