systemd-journal 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -11
- data/lib/systemd/journal.rb +10 -1
- data/lib/systemd/journal/native.rb +9 -0
- data/lib/systemd/journal/version.rb +1 -1
- data/spec/systemd/journal_spec.rb +7 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb7ad77b556c438d61a805803ce3ea525aae200f
|
4
|
+
data.tar.gz: 135d9669a414f246f1b75e060ba8b6d719bdea2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 063fc619fbc6436e72381812dcb0c3905a3b17d260e8d0223df0dec95b51a8219cbf6ee1c02a3eff3f0f548e474ca8df77ed2f6a97adfe12de90c87018b0a5dd
|
7
|
+
data.tar.gz: 1175078fb9650d9bf12c5bbbd612b87ddb5b5bf5c44974d49fdc4a9344ee1e1f4934a92f35b1f9c8c5a4fbfe5b2d4408b9a1f17a58bff2ebf0ce0bff30c051d4
|
data/README.md
CHANGED
@@ -16,10 +16,10 @@ And then execute:
|
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
19
|
+
require 'systemd/journal'
|
20
|
+
|
19
21
|
Print all messages as they occur:
|
20
22
|
|
21
|
-
require 'systemd/journal'
|
22
|
-
|
23
23
|
j = Systemd::Journal.new
|
24
24
|
j.seek(:tail)
|
25
25
|
|
@@ -27,20 +27,36 @@ Print all messages as they occur:
|
|
27
27
|
puts entry.message
|
28
28
|
end
|
29
29
|
|
30
|
-
Filter
|
31
|
-
|
32
|
-
require 'systemd/journal'
|
30
|
+
Filter events and iterate:
|
33
31
|
|
34
32
|
j = Systemd::Journal.new
|
35
|
-
|
33
|
+
|
36
34
|
# only display entries from SSHD with priority 6.
|
37
|
-
j.
|
38
|
-
j.
|
39
|
-
|
40
|
-
while j.move_next
|
41
|
-
puts j.current_entry.message
|
35
|
+
j.filter(priority: 6, _exe: '/usr/bin/sshd')
|
36
|
+
j.each do |entry|
|
37
|
+
puts entry.message
|
42
38
|
end
|
39
|
+
|
40
|
+
Moving around the journal:
|
41
|
+
|
42
|
+
j = Systemd::Journal.new
|
43
|
+
|
44
|
+
j.seek(:head) # move to the start of journal
|
45
|
+
j.move(10) # move forward by 10 entries
|
46
|
+
c = j.cursor # get a reference to this entry
|
47
|
+
j.move(-5) # move back 5 entries
|
48
|
+
j.seek(c) # move to the saved cursor
|
49
|
+
j.cursor?(c) # verify that we're at the correct entry
|
50
|
+
j.seek(:tail) # move to end of the journal
|
51
|
+
j.move_previous # move back
|
52
|
+
j.move_next # move forward
|
53
|
+
|
54
|
+
j.current_entry # get the entry we're currently positioned at
|
55
|
+
|
56
|
+
# seek the entry that occured closest to this time
|
57
|
+
j.seek(Time.parse("2013-10-31T12:00:00+04:00:00"))
|
43
58
|
|
59
|
+
|
44
60
|
See the documentation for more examples.
|
45
61
|
|
46
62
|
## Contributing
|
data/lib/systemd/journal.rb
CHANGED
@@ -406,7 +406,7 @@ module Systemd
|
|
406
406
|
raise JournalError.new(rc)
|
407
407
|
end
|
408
408
|
|
409
|
-
out_ptr.read_pointer
|
409
|
+
read_and_free_outstr(out_ptr.read_pointer)
|
410
410
|
end
|
411
411
|
|
412
412
|
# Check if the read position is currently at the entry represented by the
|
@@ -428,5 +428,14 @@ module Systemd
|
|
428
428
|
proc{ Native::sd_journal_close(ptr) unless ptr.nil? }
|
429
429
|
end
|
430
430
|
|
431
|
+
# some sd_journal_* functions return strings that we're expected to free
|
432
|
+
# ourselves. This function copies the string from a char* to a ruby string,
|
433
|
+
# frees the char*, and returns the ruby string.
|
434
|
+
def read_and_free_outstr(ptr)
|
435
|
+
str = ptr.read_string
|
436
|
+
LibC.free(ptr)
|
437
|
+
str
|
438
|
+
end
|
439
|
+
|
431
440
|
end
|
432
441
|
end
|
@@ -429,8 +429,14 @@ describe Systemd::Journal do
|
|
429
429
|
describe '#cursor' do
|
430
430
|
it 'returns the current cursor' do
|
431
431
|
j = Systemd::Journal.new
|
432
|
+
|
432
433
|
Systemd::Journal::Native.should_receive(:sd_journal_get_cursor) do |ptr, out_ptr|
|
433
|
-
|
434
|
+
# this memory will be manually freed. not setting autorelease to false
|
435
|
+
# would cause a double free.
|
436
|
+
str = FFI::MemoryPointer.from_string("5678")
|
437
|
+
str.autorelease = false
|
438
|
+
|
439
|
+
out_ptr.write_pointer(str)
|
434
440
|
0
|
435
441
|
end
|
436
442
|
j.cursor.should eq("5678")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: systemd-journal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Ledbetter
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
107
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.0.
|
108
|
+
rubygems_version: 2.0.7
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: Ruby bindings to libsystemd-journal
|