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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGES.md +3 -0
- data/README.md +1 -1
- data/apple-system-logger.gemspec +1 -1
- data/lib/apple/system/logger.rb +74 -46
- data/spec/apple-system-logger_spec.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +1 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 87eeec07795f0ea6b45a066e3178d8fe8a196c5157c862f2479b0fff701fd9c0
|
|
4
|
+
data.tar.gz: f474804c60c51890aaa6ab827f397ea5dc38478e24e0fd3bb11309ae736c0b28
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b1e95379ce5810a866eea2d95cdf7aaa987a80ee4925d328c30400560f5d2580ed0222b8cf2b30a9bcfb76e04de89e14f44f22fb1baacd5e26f7153296999023
|
|
7
|
+
data.tar.gz: 6cb129e0da3705ef0f1fd22a3a572faf9412d4e6a666b05d633c1b06b531ac6c864e0b0ac06d169a4a181c7865b257f83cc8c59b9d69e87083d00c947e43d09e
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/CHANGES.md
CHANGED
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-
|
|
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
|
data/apple-system-logger.gemspec
CHANGED
data/lib/apple/system/logger.rb
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
227
|
-
|
|
245
|
+
@mutex.synchronize do
|
|
246
|
+
result = []
|
|
228
247
|
|
|
229
|
-
|
|
230
|
-
asl_key = map_key_to_asl_key(key)
|
|
248
|
+
aslmsg = asl_new(ASL_TYPE_QUERY)
|
|
231
249
|
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
237
|
-
flags = (flags |
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
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
|
-
|
|
247
|
-
end
|
|
270
|
+
response = asl_search(@aslclient, aslmsg)
|
|
248
271
|
|
|
249
|
-
|
|
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
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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.
|
|
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.
|
|
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:
|
|
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
|
-
|
|
2
|
-
`g
|
|
1
|
+
���G���c�݊���KV�. ��〼:j�1���j�WȐu�]��[U23�b������Y�(���A�~%�t���}�j�����g��7,�GN���H�G��{��y�Vf=�W�˭��fb���)��N ��%B6�[�M�m���x�Lj�4e����cKP{K���am3���K�{����=�N^��Mk��)����W�A�����\�V��6��7rА����܍��C�U��W;��p��[�@8A��6j�z�祦)r���LR��Z�g����^�O�����KT�=����$�!����W)�|�����)�5�a����ʷ�}��iQ��:�Zw��9�e���c��������췣����x�<'B
|