rb_log 0.1.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/rb_log +89 -0
  3. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 69103e1836f4e9433d4458f3090fd72c52a34687
4
+ data.tar.gz: 437a7b854caa6a577768ec0f20bf93fe7c782b37
5
+ SHA512:
6
+ metadata.gz: 773afa398f20139f2c17ab857d5611e6888aa80e7d97c41b12942209c17a245a1258fb17887bbffcf646086f9189fc16d31d8ff8d3f181e3d88eaa4838608857
7
+ data.tar.gz: fba18904578c1e5368f51f5476a0cd7c189f910db5c7219dc2f41b3b9cb97f564e1db6505517f90f3b9e476acae887b3686f12b396494fa39ef20c9dbd00c801
data/bin/rb_log ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'syslog'
4
+ require 'optparse'
5
+ require 'ostruct'
6
+
7
+ class RbLogOptions
8
+
9
+ def self.parse(args)
10
+ options = OpenStruct.new
11
+ options.tag = ""
12
+ options.facility = ""
13
+
14
+ opt_parser = OptionParser.new do |opts|
15
+ opts.banner = "Usage: rb_log [options]"
16
+ opts.separator ""
17
+ opts.separator "Specific options:"
18
+
19
+ opts.on("-t", "--tag TAG", "Specify a tag for log messages") do |tag|
20
+ options.tag = tag
21
+ end
22
+
23
+ opts.on("-f", "--facility SYSLOG_FACILITY", "Specify a logging facility to use") do |fac|
24
+ options.facility = fac
25
+ end
26
+
27
+ opts.on_tail("-h", "--help", "Show this message") do
28
+ puts opts
29
+ exit
30
+ end
31
+
32
+ opts.on_tail("--version", "Show version") do
33
+ puts ::Version.join('.')
34
+ exit
35
+ end
36
+ end # end opt_parser
37
+ opt_parser.parse!(args)
38
+ options
39
+ end # end parse()
40
+
41
+ end # End class RbLog
42
+
43
+ class RbLog
44
+
45
+ def initialize(tag, facility)
46
+ @syslog = syslog(tag, facility_map[facility.to_sym])
47
+ @syslog
48
+ end # End #initialize
49
+
50
+ def syslog(tag, facility)
51
+ facility = Syslog::LOG_DAEMON if facility.nil?
52
+ Syslog.open(tag, Syslog::LOG_PID && Syslog::LOG_NOWAIT, facility)
53
+ end # End #syslog
54
+
55
+ def log(msg)
56
+ @syslog.log(Syslog::LOG_INFO, msg)
57
+ end # End #log
58
+
59
+ def facility_map
60
+ {
61
+ auth: Syslog::LOG_AUTH,
62
+ authpriv: Syslog::LOG_AUTHPRIV,
63
+ cron: Syslog::LOG_CRON,
64
+ daemon: Syslog::LOG_DAEMON,
65
+ syslog: Syslog::LOG_SYSLOG,
66
+ user: Syslog::LOG_USER,
67
+ local1: Syslog::LOG_LOCAL1,
68
+ local2: Syslog::LOG_LOCAL2,
69
+ local3: Syslog::LOG_LOCAL3,
70
+ local4: Syslog::LOG_LOCAL4,
71
+ local5: Syslog::LOG_LOCAL5,
72
+ local6: Syslog::LOG_LOCAL6,
73
+ local7: Syslog::LOG_LOCAL7
74
+ }
75
+ end
76
+
77
+ end # End class RbLog
78
+
79
+ begin
80
+ options = RbLogOptions.parse(ARGV)
81
+ logger = RbLog.new(options.tag, options.facility)
82
+ STDIN.each_line do |li|
83
+ logger.log(li)
84
+ end
85
+ rescue OptionParser::ParseError => e
86
+ puts "Something done gone wrong"
87
+ puts e.message
88
+ exit
89
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rb_log
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Phillips
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A clone of linux logger utility. While logger abides by RFC5424, this
14
+ utility does not. There will not be any message truncation.
15
+ email: platform@omadahealth.com
16
+ executables:
17
+ - rb_log
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/rb_log
22
+ homepage:
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.4.5.1
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Ruby logger implementation
46
+ test_files: []