vidazing_logger 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/vidazing_logger +73 -10
- data/lib/vidazing_logger/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 597cce23473e1b7e9e1d03f92f4f9aa1cae675cd0ba3de80e3585fd83d477816
|
4
|
+
data.tar.gz: e4bf6b437906a14ee5c1a1322573ccbdd6dd67736c4f1259b8b6b378bbd9a9cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 491a52560233c3242381c18321d2e386309125f8c6d1f15e2ec56cc2a2f2e75dfde1494c1aaa03a1935fb8ef7f140aaea94c7f78a780c881f4088891b6c14dca
|
7
|
+
data.tar.gz: 36d141514030631ffc8743dfd3e95166db599ba3e5e35b87359d6363f62bed19c30a06964192056d2e0fac2c81a8a9f892118672ce3f71b543631da33a236aa1
|
data/bin/vidazing_logger
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require 'vidazing_logger/logger_builder'
|
4
5
|
require 'vidazing_logger'
|
5
6
|
|
6
7
|
require 'optparse'
|
@@ -13,12 +14,32 @@ require 'ostruct'
|
|
13
14
|
class VidazingOptions
|
14
15
|
attr_reader :level, :clean
|
15
16
|
|
17
|
+
# Store properties used by +VidazingLogger+
|
16
18
|
def initialize
|
17
19
|
@level = 'info'
|
18
20
|
@clean = false
|
21
|
+
@file_io = false
|
22
|
+
@verbose = false
|
23
|
+
|
19
24
|
@options_parser = create_options_parser
|
20
25
|
end
|
21
26
|
|
27
|
+
# If file_io is true the logger will write to 'logs/'
|
28
|
+
#
|
29
|
+
# @return file_io [TrueClass, FalseClass]
|
30
|
+
# @since 0.2.1
|
31
|
+
def file_io?
|
32
|
+
@file_io
|
33
|
+
end
|
34
|
+
|
35
|
+
# Show extra debug information for this script
|
36
|
+
#
|
37
|
+
# @return verbose [TrueClass, FalseClass]
|
38
|
+
# @since 0.2.1
|
39
|
+
def verbose?
|
40
|
+
@verbose
|
41
|
+
end
|
42
|
+
|
22
43
|
def create_options_parser # rubocop:disable Metrics/MethodLength
|
23
44
|
OptionParser.new do |opts|
|
24
45
|
opts.banner = 'Usage: vidazing_logger [options] "Message"'
|
@@ -39,6 +60,17 @@ class VidazingOptions
|
|
39
60
|
opts.on_tail('-c', '--clean', 'Remove the logs/ directory') do
|
40
61
|
@clean = true
|
41
62
|
end
|
63
|
+
|
64
|
+
file_io_help =
|
65
|
+
'Enables writing to the \'logs/\' ' \
|
66
|
+
'directory on the file system'
|
67
|
+
opts.on_tail('-f', '--file-io', file_io_help) do
|
68
|
+
@file_io = true
|
69
|
+
end
|
70
|
+
|
71
|
+
opts.on_tail('-v', '--verbose', 'Show debug messages') do
|
72
|
+
@verbose = true
|
73
|
+
end
|
42
74
|
end
|
43
75
|
end
|
44
76
|
|
@@ -47,17 +79,48 @@ class VidazingOptions
|
|
47
79
|
end
|
48
80
|
end
|
49
81
|
|
50
|
-
|
51
|
-
|
82
|
+
# Handles options
|
83
|
+
class Main
|
84
|
+
def initialize
|
85
|
+
@vidazing_options = VidazingOptions.new
|
86
|
+
@vidazing_options.parse(ARGV)
|
52
87
|
|
53
|
-
if vidazing_options.clean
|
54
|
-
|
55
|
-
|
56
|
-
end
|
88
|
+
if @vidazing_options.clean
|
89
|
+
puts 'Cleaning the logs/ directory'
|
90
|
+
VidazingLogger.clean
|
91
|
+
end
|
57
92
|
|
58
|
-
|
59
|
-
message = ARGV.join(' ')
|
93
|
+
return if ARGV.empty?
|
60
94
|
|
61
|
-
|
62
|
-
|
95
|
+
message = ARGV.join(' ')
|
96
|
+
log_message(message)
|
97
|
+
end
|
98
|
+
|
99
|
+
def log_message(message)
|
100
|
+
if @vidazing_options.file_io?
|
101
|
+
verbose_log('Logging to \'logs\' directory + STDERR + STDOUT')
|
102
|
+
|
103
|
+
log = VidazingLogger.logger
|
104
|
+
else
|
105
|
+
verbose_log 'Logging to STDERR + STDOUT'
|
106
|
+
|
107
|
+
log = build_stdio_logger
|
108
|
+
end
|
109
|
+
|
110
|
+
log.public_send(@vidazing_options.level, message)
|
111
|
+
end
|
112
|
+
|
113
|
+
def build_stdio_logger
|
114
|
+
VidazingLogger::LoggerBuilder.build(name: 'Vidazing') do |builder|
|
115
|
+
builder
|
116
|
+
.add_stdout
|
117
|
+
.add_stderr
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def verbose_log(message)
|
122
|
+
puts message if @vidazing_options.verbose?
|
123
|
+
end
|
63
124
|
end
|
125
|
+
|
126
|
+
Main.new
|