journald-native 1.0.1
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 +7 -0
- data/.gitignore +27 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +9 -0
- data/ext/journald_native/extconf.rb +20 -0
- data/ext/journald_native/journald_native.c +139 -0
- data/journald-native.gemspec +27 -0
- data/lib/journald/native.rb +7 -0
- data/lib/journald/native/version.rb +5 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 434d6c7409f38d0c734102b165c7422774b4b765
|
4
|
+
data.tar.gz: dbb1a39c162a253430a5ddf497a7b6ecc8c71ee5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 53b67e58815b34992d37b8a39339372e2d27393bbefe533d37375aac7fd4ef9386fd35fecece27ee7c9b201f56488d12fed26d22d24a1b17bb00e72fdad67473
|
7
|
+
data.tar.gz: ec9ac27fa92aeb99b0258780342ebdbf34805f90db345990f5e650db5bf9a4ffd8e738f8a64612b7612a03bd4f540ab8091a4a74e8635b234f5caec24d503f68
|
data/.gitignore
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
Makefile
|
24
|
+
*.iml
|
25
|
+
*.ipr
|
26
|
+
*.iws
|
27
|
+
.rakeTasks
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Anton Smirnov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# journald-native
|
2
|
+
|
3
|
+
A systemd-journal native logging lib wrapper.
|
4
|
+
[See sd-journal help for more info](http://www.freedesktop.org/software/systemd/man/sd_journal_print.html)
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
require 'journald/native'
|
10
|
+
```
|
11
|
+
|
12
|
+
### Constants
|
13
|
+
|
14
|
+
Constants are used to denote a log level
|
15
|
+
|
16
|
+
Available constants:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
Journald::LOG_EMERG # system is unusable
|
20
|
+
Journald::LOG_ALERT # action must be taken immediately
|
21
|
+
Journald::LOG_CRIT # critical conditions
|
22
|
+
Journald::LOG_ERR # error conditions
|
23
|
+
Journald::LOG_WARNING # warning conditions
|
24
|
+
Journald::LOG_NOTICE # normal but significant condition
|
25
|
+
Journald::LOG_INFO # informational
|
26
|
+
Journald::LOG_DEBUG # debug-level messages
|
27
|
+
```
|
28
|
+
|
29
|
+
systemd-journal uses syslog constants to denote level therefore they are equal to those of the Syslog module,
|
30
|
+
e.g. ```Journald::LOG_WARNING == Syslog::LOG_WARNING```.
|
31
|
+
[See syslog man page for more info](http://man7.org/linux/man-pages/man3/syslog.3.html)
|
32
|
+
|
33
|
+
### Methods
|
34
|
+
|
35
|
+
Methods of Journald::Native class wrap systemd-journal calls.
|
36
|
+
[See sd-journal help for more info](http://www.freedesktop.org/software/systemd/man/sd_journal_print.html)
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
Journald::Native.send "MESSAGE=message", "PRIORITY=#{Journald::LOG_WARNING}"
|
40
|
+
Journald::Native.print Journald::LOG_WARNING, "message"
|
41
|
+
Journald::Native.perror "message"
|
42
|
+
```
|
43
|
+
|
44
|
+
It is not recommended to use ```print``` and ```perror``` as you may lose ```'\0'``` byte in your string due to
|
45
|
+
C zero-terminated string format (all zero bytes in the middle will be removed) On the contrary ```send``` uses
|
46
|
+
binary buffers and does not have such shortcoming.
|
47
|
+
|
48
|
+
### License
|
49
|
+
|
50
|
+
Licensed under the MIT License. See ```LICENSE.txt``` for more info
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
LIBDIR = RbConfig::CONFIG['libdir']
|
4
|
+
INCLUDEDIR = RbConfig::CONFIG['includedir']
|
5
|
+
|
6
|
+
HEADER_DIRS = [INCLUDEDIR]
|
7
|
+
|
8
|
+
LIB_DIRS = [LIBDIR]
|
9
|
+
|
10
|
+
dir_config('systemd', HEADER_DIRS, LIB_DIRS)
|
11
|
+
|
12
|
+
# check headers
|
13
|
+
abort 'systemd/sd-journal.h is missing. please install systemd-journal' unless find_header('systemd/sd-journal.h')
|
14
|
+
|
15
|
+
# check functions
|
16
|
+
%w(sd_journal_print sd_journal_sendv sd_journal_perror).each do |func|
|
17
|
+
abort "#{func}() is missing. systemd-journal is not usable" unless find_library('systemd-journal', func)
|
18
|
+
end
|
19
|
+
|
20
|
+
create_makefile('journald_native')
|
@@ -0,0 +1,139 @@
|
|
1
|
+
/* Do not add C line and file to the log messages */
|
2
|
+
#define SD_JOURNAL_SUPPRESS_LOCATION
|
3
|
+
|
4
|
+
#include <ruby.h>
|
5
|
+
#include <systemd/sd-journal.h>
|
6
|
+
|
7
|
+
void Init_journald_native();
|
8
|
+
|
9
|
+
/* initializers */
|
10
|
+
static void jdl_init_modules();
|
11
|
+
static void jdl_init_constants();
|
12
|
+
static void jdl_init_methods();
|
13
|
+
|
14
|
+
/* methods */
|
15
|
+
static VALUE jdl_native_print(VALUE self, VALUE priority, VALUE message);
|
16
|
+
static VALUE jdl_native_send(int argc, VALUE* argv, VALUE self);
|
17
|
+
static VALUE jdl_native_perror(VALUE self, VALUE message);
|
18
|
+
|
19
|
+
/* aux */
|
20
|
+
static char * jdl_alloc_safe_string(VALUE string);
|
21
|
+
|
22
|
+
/* globals */
|
23
|
+
static VALUE mJournald;
|
24
|
+
static VALUE mNative;
|
25
|
+
|
26
|
+
void Init_journald_native()
|
27
|
+
{
|
28
|
+
jdl_init_modules();
|
29
|
+
jdl_init_constants();
|
30
|
+
jdl_init_methods();
|
31
|
+
}
|
32
|
+
|
33
|
+
static void jdl_init_modules()
|
34
|
+
{
|
35
|
+
mJournald = rb_define_module("Journald");
|
36
|
+
mNative = rb_define_module_under(mJournald, "Native");
|
37
|
+
}
|
38
|
+
|
39
|
+
static void jdl_init_constants()
|
40
|
+
{
|
41
|
+
rb_define_const(mJournald, "LOG_EMERG", INT2NUM(LOG_EMERG)); /* system is unusable */
|
42
|
+
rb_define_const(mJournald, "LOG_ALERT", INT2NUM(LOG_ALERT)); /* action must be taken immediately */
|
43
|
+
rb_define_const(mJournald, "LOG_CRIT", INT2NUM(LOG_CRIT)); /* critical conditions */
|
44
|
+
rb_define_const(mJournald, "LOG_ERR", INT2NUM(LOG_ERR)); /* error conditions */
|
45
|
+
rb_define_const(mJournald, "LOG_WARNING", INT2NUM(LOG_WARNING)); /* warning conditions */
|
46
|
+
rb_define_const(mJournald, "LOG_NOTICE", INT2NUM(LOG_NOTICE)); /* normal but significant condition */
|
47
|
+
rb_define_const(mJournald, "LOG_INFO", INT2NUM(LOG_INFO)); /* informational */
|
48
|
+
rb_define_const(mJournald, "LOG_DEBUG", INT2NUM(LOG_DEBUG)); /* debug-level messages */
|
49
|
+
}
|
50
|
+
|
51
|
+
static void jdl_init_methods()
|
52
|
+
{
|
53
|
+
rb_define_singleton_method(mNative, "print", jdl_native_print, 2);
|
54
|
+
rb_define_singleton_method(mNative, "send", jdl_native_send, -1); // -1 to pass as C array
|
55
|
+
rb_define_singleton_method(mNative, "perror", jdl_native_perror, 1);
|
56
|
+
}
|
57
|
+
|
58
|
+
static VALUE jdl_native_print(VALUE v_self, VALUE v_priority, VALUE v_message)
|
59
|
+
{
|
60
|
+
int priority, result;
|
61
|
+
char *message;
|
62
|
+
|
63
|
+
priority = NUM2INT(v_priority);
|
64
|
+
message = jdl_alloc_safe_string(v_message);
|
65
|
+
|
66
|
+
result = sd_journal_print(priority, "%s", message);
|
67
|
+
|
68
|
+
free(message);
|
69
|
+
|
70
|
+
return INT2NUM(result);
|
71
|
+
}
|
72
|
+
|
73
|
+
static VALUE jdl_native_send(int argc, VALUE* argv, VALUE self)
|
74
|
+
{
|
75
|
+
//const char * fmt = "%s";
|
76
|
+
struct iovec *msgs;
|
77
|
+
size_t i;
|
78
|
+
int result;
|
79
|
+
|
80
|
+
msgs = calloc(argc, sizeof(struct iovec));
|
81
|
+
|
82
|
+
for (i = 0; i < argc; i++) {
|
83
|
+
VALUE v = argv[i];
|
84
|
+
StringValue(v);
|
85
|
+
msgs[i].iov_base = RSTRING_PTR(v);
|
86
|
+
msgs[i].iov_len = RSTRING_LEN(v);
|
87
|
+
}
|
88
|
+
|
89
|
+
result = sd_journal_sendv(msgs, argc);
|
90
|
+
|
91
|
+
free(msgs);
|
92
|
+
|
93
|
+
return INT2NUM(result);
|
94
|
+
}
|
95
|
+
|
96
|
+
static VALUE jdl_native_perror(VALUE v_self, VALUE v_message)
|
97
|
+
{
|
98
|
+
int result;
|
99
|
+
char *message;
|
100
|
+
|
101
|
+
message = jdl_alloc_safe_string(v_message);
|
102
|
+
|
103
|
+
result = sd_journal_perror(message);
|
104
|
+
|
105
|
+
free(message);
|
106
|
+
|
107
|
+
return INT2NUM(result);
|
108
|
+
}
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Remove zeros from string and ensure it's zero-terminated
|
112
|
+
*/
|
113
|
+
static char * jdl_alloc_safe_string(VALUE v_string)
|
114
|
+
{
|
115
|
+
char *str;
|
116
|
+
size_t len;
|
117
|
+
|
118
|
+
char *newstr,
|
119
|
+
*ptr;
|
120
|
+
size_t i;
|
121
|
+
|
122
|
+
/* convert tos sring */
|
123
|
+
StringValue(v_string);
|
124
|
+
|
125
|
+
str = RSTRING_PTR(v_string);
|
126
|
+
len = RSTRING_LEN(v_string);
|
127
|
+
|
128
|
+
newstr = calloc(len + 1, sizeof(char));
|
129
|
+
|
130
|
+
for (i = 0, ptr = newstr; i < len; i++) {
|
131
|
+
if (str[i]) {
|
132
|
+
*(ptr++) = str[i];
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
*ptr = '\0';
|
137
|
+
|
138
|
+
return newstr;
|
139
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'journald/native/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'journald-native'
|
8
|
+
spec.version = Journald::Native::VERSION
|
9
|
+
spec.authors = ['Anton Smirnov']
|
10
|
+
spec.email = ['sandfox@sandfox.im']
|
11
|
+
spec.summary = %q{systemd-journal logging native lib wrapper}
|
12
|
+
# spec.description = %q{Write a longer description. Optional.}
|
13
|
+
spec.homepage = 'https://github.com/sandfox-im/journald-native'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.extensions << 'ext/journald_native/extconf.rb'
|
21
|
+
|
22
|
+
spec.required_ruby_version = '>= 1.9.2'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rake-compiler'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: journald-native
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anton Smirnov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- sandfox@sandfox.im
|
58
|
+
executables: []
|
59
|
+
extensions:
|
60
|
+
- ext/journald_native/extconf.rb
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- ext/journald_native/extconf.rb
|
69
|
+
- ext/journald_native/journald_native.c
|
70
|
+
- journald-native.gemspec
|
71
|
+
- lib/journald/native.rb
|
72
|
+
- lib/journald/native/version.rb
|
73
|
+
homepage: https://github.com/sandfox-im/journald-native
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.9.2
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.1.11
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: systemd-journal logging native lib wrapper
|
97
|
+
test_files: []
|
98
|
+
has_rdoc:
|