locd 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/exe/locd +1 -1
- data/lib/locd/agent.rb +1 -1
- data/lib/locd/cli/command/main.rb +24 -4
- data/lib/locd/launchctl.rb +1 -1
- data/lib/locd/newsyslog.rb +1 -1
- data/lib/locd/proxy.rb +1 -1
- data/lib/locd.rb +1 -3
- data/locd.gemspec +1 -1
- metadata +6 -7
- data/lib/locd/logging.rb +0 -399
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c5204f4e2f4bcd01e4af0c6532c1505b117cadd
|
4
|
+
data.tar.gz: 7268adf8c6b457a0ea347fede69c923202baba32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6d3f99a7a47678345bdfd2785c56e48cd291b026a9c215be9bfdd6117fafbad96cd2d4a65225b1b3feb48f04219c9d8b31ddd5a8c0a10f6ef3ebd4eb4c83364
|
7
|
+
data.tar.gz: '029dae728f2d37236167b21e6ff03c35289cace83e38d18a59fea4f1f71f66a2dfd274e1f1a87eebb1bcaa88106a67acf7fd78606459816288f3d822ba6010a5'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/exe/locd
CHANGED
@@ -6,7 +6,7 @@ require 'locd'
|
|
6
6
|
|
7
7
|
# Setup logging *before* including {Locd::CLI} so that we can get
|
8
8
|
# trace/debug output from that setup if enabled via ENV vars
|
9
|
-
|
9
|
+
NRSER::Logging.setup! application: 'Locd', dest: $stderr, sync: true
|
10
10
|
|
11
11
|
# Logger for this file
|
12
12
|
logger = SemanticLogger[__FILE__]
|
data/lib/locd/agent.rb
CHANGED
@@ -51,7 +51,7 @@ class Locd::Agent
|
|
51
51
|
# ==========================================================================
|
52
52
|
|
53
53
|
# Add {.logger} and {#logger} methods
|
54
|
-
include
|
54
|
+
include NRSER::Logging::Mixin
|
55
55
|
|
56
56
|
# Make agents sortable by label
|
57
57
|
include Comparable
|
@@ -128,11 +128,31 @@ class Locd::CLI::Command::Main < Locd::CLI::Command::Base
|
|
128
128
|
}.to_sym
|
129
129
|
end
|
130
130
|
|
131
|
-
|
132
|
-
Locd::Logging.set_config_levels
|
131
|
+
NRSER::Logging.level = level unless level.nil?
|
133
132
|
|
134
|
-
if [:
|
135
|
-
|
133
|
+
if levels = Locd.config[:log, :levels]
|
134
|
+
levels.each do |name, level|
|
135
|
+
const = begin
|
136
|
+
NRSER.to_const name
|
137
|
+
rescue
|
138
|
+
next
|
139
|
+
end
|
140
|
+
|
141
|
+
level = level.to_sym
|
142
|
+
|
143
|
+
self.logger.debug "Setting logger level",
|
144
|
+
logger: const.logger,
|
145
|
+
level: level
|
146
|
+
|
147
|
+
const.logger.level = level
|
148
|
+
|
149
|
+
self.logger.debug "Logger level set",
|
150
|
+
logger: const.logger
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
if [:trace, :debug].include? NRSER::Logging.level
|
155
|
+
logger.send NRSER::Logging.level, "Hello! We about to start the show..."
|
136
156
|
end
|
137
157
|
end
|
138
158
|
|
data/lib/locd/launchctl.rb
CHANGED
data/lib/locd/newsyslog.rb
CHANGED
data/lib/locd/proxy.rb
CHANGED
data/lib/locd.rb
CHANGED
@@ -13,7 +13,6 @@ require 'shellwords'
|
|
13
13
|
# Deps
|
14
14
|
# -----------------------------------------------------------------------
|
15
15
|
require 'nrser'
|
16
|
-
require 'semantic_logger'
|
17
16
|
require 'cmds'
|
18
17
|
|
19
18
|
# Project / Package
|
@@ -22,7 +21,6 @@ require 'locd/version'
|
|
22
21
|
require 'locd/errors'
|
23
22
|
require 'locd/config'
|
24
23
|
require 'locd/util'
|
25
|
-
require 'locd/logging'
|
26
24
|
require 'locd/label'
|
27
25
|
require 'locd/pattern'
|
28
26
|
require 'locd/launchctl'
|
@@ -59,7 +57,7 @@ module Locd
|
|
59
57
|
# ============================================================================
|
60
58
|
|
61
59
|
# Add {.logger} and {#logger} methods
|
62
|
-
include
|
60
|
+
include NRSER::Logging::Mixin
|
63
61
|
|
64
62
|
|
65
63
|
# Module Methods
|
data/locd.gemspec
CHANGED
@@ -47,7 +47,7 @@ Gem::Specification.new do |spec|
|
|
47
47
|
# ----------------------------------------------------------------------------
|
48
48
|
|
49
49
|
# My guns
|
50
|
-
spec.add_dependency "nrser", '
|
50
|
+
spec.add_dependency "nrser", '~> 0.2.1'
|
51
51
|
|
52
52
|
# Used to process command templates from projects' `//dev/locd.yml` files
|
53
53
|
spec.add_dependency "cmds", ">= 0.2.10"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nrser
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -112,16 +112,16 @@ dependencies:
|
|
112
112
|
name: nrser
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.2.
|
117
|
+
version: 0.2.1
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.2.
|
124
|
+
version: 0.2.1
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: cmds
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -226,7 +226,6 @@ files:
|
|
226
226
|
- lib/locd/errors.rb
|
227
227
|
- lib/locd/label.rb
|
228
228
|
- lib/locd/launchctl.rb
|
229
|
-
- lib/locd/logging.rb
|
230
229
|
- lib/locd/newsyslog.rb
|
231
230
|
- lib/locd/pattern.rb
|
232
231
|
- lib/locd/proxy.rb
|
data/lib/locd/logging.rb
DELETED
@@ -1,399 +0,0 @@
|
|
1
|
-
# Requirements
|
2
|
-
# =======================================================================
|
3
|
-
|
4
|
-
# Stdlib
|
5
|
-
# -----------------------------------------------------------------------
|
6
|
-
require 'forwardable'
|
7
|
-
|
8
|
-
# Deps
|
9
|
-
# -----------------------------------------------------------------------
|
10
|
-
require 'awesome_print'
|
11
|
-
require 'semantic_logger'
|
12
|
-
|
13
|
-
# Project / Package
|
14
|
-
# -----------------------------------------------------------------------
|
15
|
-
|
16
|
-
|
17
|
-
# Refinements
|
18
|
-
# =======================================================================
|
19
|
-
|
20
|
-
using NRSER
|
21
|
-
using NRSER::Types
|
22
|
-
|
23
|
-
|
24
|
-
# Definitions
|
25
|
-
# =======================================================================
|
26
|
-
|
27
|
-
# Utility methods to setup logging with [semantic_logger][].
|
28
|
-
#
|
29
|
-
# [semantic_logger]: http://rocketjob.github.io/semantic_logger/
|
30
|
-
#
|
31
|
-
module Locd::Logging
|
32
|
-
include SemanticLogger::Loggable
|
33
|
-
|
34
|
-
|
35
|
-
# @todo document Formatters module.
|
36
|
-
module Formatters
|
37
|
-
|
38
|
-
# Custom tweaked color formatter (for CLI output).
|
39
|
-
#
|
40
|
-
# - Turns on multiline output in Awesome Print by default.
|
41
|
-
#
|
42
|
-
class Color < SemanticLogger::Formatters::Color
|
43
|
-
|
44
|
-
# Constants
|
45
|
-
# ======================================================================
|
46
|
-
|
47
|
-
|
48
|
-
# Class Methods
|
49
|
-
# ======================================================================
|
50
|
-
|
51
|
-
|
52
|
-
# Attributes
|
53
|
-
# ======================================================================
|
54
|
-
|
55
|
-
|
56
|
-
# Constructor
|
57
|
-
# ======================================================================
|
58
|
-
|
59
|
-
# Instantiate a new `ColorFormatter`.
|
60
|
-
def initialize **options
|
61
|
-
super ap: { multiline: true },
|
62
|
-
color_map: SemanticLogger::Formatters::Color::ColorMap.new(
|
63
|
-
debug: SemanticLogger::AnsiColors::MAGENTA,
|
64
|
-
trace: "\e[1;30m", # "Dark Gray"
|
65
|
-
),
|
66
|
-
**options
|
67
|
-
end # #initialize
|
68
|
-
|
69
|
-
|
70
|
-
# Instance Methods
|
71
|
-
# ======================================================================
|
72
|
-
|
73
|
-
|
74
|
-
# Upcase the log level.
|
75
|
-
#
|
76
|
-
# @return [String]
|
77
|
-
#
|
78
|
-
def level
|
79
|
-
"#{ color }#{ log.level.upcase }#{ color_map.clear }"
|
80
|
-
end
|
81
|
-
|
82
|
-
|
83
|
-
# Create the log entry text. Overridden to customize appearance -
|
84
|
-
# generally reduce amount of info and put payload on it's own line.
|
85
|
-
#
|
86
|
-
# We need to replace *two* super functions, the first being
|
87
|
-
# [SemanticLogger::Formatters::Color#call][]:
|
88
|
-
#
|
89
|
-
# def call(log, logger)
|
90
|
-
# self.color = color_map[log.level]
|
91
|
-
# super(log, logger)
|
92
|
-
# end
|
93
|
-
#
|
94
|
-
# [SemanticLogger::Formatters::Color#call]: https://github.com/rocketjob/semantic_logger/blob/v4.2.0/lib/semantic_logger/formatters/color.rb#L98
|
95
|
-
#
|
96
|
-
# which doesn't do all too much, and the next being it's super-method,
|
97
|
-
# [SemanticLogger::Formatters::Default#call][]:
|
98
|
-
#
|
99
|
-
# # Default text log format
|
100
|
-
# # Generates logs of the form:
|
101
|
-
# # 2011-07-19 14:36:15.660235 D [1149:ScriptThreadProcess] Rails -- Hello World
|
102
|
-
# def call(log, logger)
|
103
|
-
# self.log = log
|
104
|
-
# self.logger = logger
|
105
|
-
#
|
106
|
-
# [time, level, process_info, tags, named_tags, duration, name, message, payload, exception].compact.join(' ')
|
107
|
-
# end
|
108
|
-
#
|
109
|
-
# [SemanticLogger::Formatters::Default#call]: https://github.com/rocketjob/semantic_logger/blob/v4.2.0/lib/semantic_logger/formatters/default.rb#L64
|
110
|
-
#
|
111
|
-
# which does most the real assembly.
|
112
|
-
#
|
113
|
-
# @param [SemanticLogger::Log] log
|
114
|
-
# The log entry to format.
|
115
|
-
#
|
116
|
-
# See [SemanticLogger::Log](https://github.com/rocketjob/semantic_logger/blob/v4.2.0/lib/semantic_logger/log.rb)
|
117
|
-
#
|
118
|
-
# @param [SemanticLogger::Logger] logger
|
119
|
-
# The logger doing the logging (pretty sure, haven't checked).
|
120
|
-
#
|
121
|
-
# See [SemanticLogger::Logger](https://github.com/rocketjob/semantic_logger/blob/v4.2.0/lib/semantic_logger/logger.rb)
|
122
|
-
#
|
123
|
-
# @return [String]
|
124
|
-
# The full log string.
|
125
|
-
#
|
126
|
-
def call log, logger
|
127
|
-
# SemanticLogger::Formatters::Color code
|
128
|
-
self.color = color_map[log.level]
|
129
|
-
|
130
|
-
# SemanticLogger::Formatters::Default code
|
131
|
-
self.log = log
|
132
|
-
self.logger = logger
|
133
|
-
|
134
|
-
is_info = log.level == :info
|
135
|
-
|
136
|
-
[
|
137
|
-
level,
|
138
|
-
tags,
|
139
|
-
named_tags,
|
140
|
-
duration,
|
141
|
-
(is_info ? nil : name),
|
142
|
-
message,
|
143
|
-
payload,
|
144
|
-
exception,
|
145
|
-
].compact.join(' ')
|
146
|
-
|
147
|
-
end # #call
|
148
|
-
|
149
|
-
|
150
|
-
end # class Color
|
151
|
-
|
152
|
-
end # module Formatters
|
153
|
-
|
154
|
-
|
155
|
-
module Appender
|
156
|
-
# Replacement for {SemanticLogger::Appender::Async} that implements the
|
157
|
-
# same interface but just logs synchronously in the current thread.
|
158
|
-
#
|
159
|
-
class Sync
|
160
|
-
extend Forwardable
|
161
|
-
|
162
|
-
# The appender we forward to, which is a {SemanticLogger::Processor}
|
163
|
-
# in practice, since it wouldn't make any sense to wrap a regular
|
164
|
-
# appender in a Sync.
|
165
|
-
#
|
166
|
-
# @return [SemanticLogger::Processor]
|
167
|
-
#
|
168
|
-
attr_accessor :appender
|
169
|
-
|
170
|
-
# Forward methods that can be called directly
|
171
|
-
def_delegator :@appender, :name
|
172
|
-
def_delegator :@appender, :should_log?
|
173
|
-
def_delegator :@appender, :filter
|
174
|
-
def_delegator :@appender, :host
|
175
|
-
def_delegator :@appender, :application
|
176
|
-
def_delegator :@appender, :level
|
177
|
-
def_delegator :@appender, :level=
|
178
|
-
def_delegator :@appender, :logger
|
179
|
-
# Added for sync
|
180
|
-
def_delegator :@appender, :log
|
181
|
-
def_delegator :@appender, :on_log
|
182
|
-
def_delegator :@appender, :flush
|
183
|
-
def_delegator :@appender, :close
|
184
|
-
|
185
|
-
class FakeQueue
|
186
|
-
def self.size
|
187
|
-
0
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
# Appender proxy to allow an existing appender to run asynchronously in a separate thread.
|
192
|
-
#
|
193
|
-
# Parameters:
|
194
|
-
# name: [String]
|
195
|
-
# Name to use for the log thread and the log name when logging any errors from this appender.
|
196
|
-
#
|
197
|
-
# lag_threshold_s [Float]
|
198
|
-
# Log a warning when a log message has been on the queue for longer than this period in seconds.
|
199
|
-
# Default: 30
|
200
|
-
#
|
201
|
-
# lag_check_interval: [Integer]
|
202
|
-
# Number of messages to process before checking for slow logging.
|
203
|
-
# Default: 1,000
|
204
|
-
def initialize(appender:,
|
205
|
-
name: appender.class.name)
|
206
|
-
|
207
|
-
@appender = appender
|
208
|
-
end
|
209
|
-
|
210
|
-
# Needs to be there to support {SemanticLogger::Processor.queue_size},
|
211
|
-
# which gets the queue and returns it's size (which will always be zero
|
212
|
-
# for us).
|
213
|
-
#
|
214
|
-
# We return {FakeQueue}, which only implements a `size` method that
|
215
|
-
# returns zero.
|
216
|
-
#
|
217
|
-
# @return [#size]
|
218
|
-
#
|
219
|
-
def queue; FakeQueue; end
|
220
|
-
|
221
|
-
def lag_check_interval; -1; end
|
222
|
-
|
223
|
-
def lag_check_interval= value
|
224
|
-
raise "Can't set `lag_check_interval` on Sync appender"
|
225
|
-
end
|
226
|
-
|
227
|
-
def lag_threshold_s; -1; end
|
228
|
-
|
229
|
-
def lag_threshold_s= value
|
230
|
-
raise "Can't set `lag_threshold_s` on Sync appender"
|
231
|
-
end
|
232
|
-
|
233
|
-
# @return [false] Sync appender is of course not size-capped.
|
234
|
-
def capped?; false; end
|
235
|
-
|
236
|
-
# The {SemanticLogger::Appender::Async} worker thread is exposed via
|
237
|
-
# this method, which creates it if it doesn't exist and returns it, but
|
238
|
-
# it doesn't seem like the returned value is ever used; the method
|
239
|
-
# call is just invoked to start the thread.
|
240
|
-
#
|
241
|
-
# Hence it seems to make most sense to just return `nil` since we don't
|
242
|
-
# have a thread, and figure out what to do if that causes errors (so far
|
243
|
-
# it seems fine).
|
244
|
-
#
|
245
|
-
# @return [nil]
|
246
|
-
#
|
247
|
-
def thread; end
|
248
|
-
|
249
|
-
# @return [true] Sync appender is always active
|
250
|
-
def active?; true; end
|
251
|
-
|
252
|
-
end # class Sync
|
253
|
-
end # module Appenders
|
254
|
-
|
255
|
-
|
256
|
-
# Module (Class) Methods
|
257
|
-
# =====================================================================
|
258
|
-
|
259
|
-
|
260
|
-
def self.level
|
261
|
-
SemanticLogger.default_level
|
262
|
-
end
|
263
|
-
|
264
|
-
|
265
|
-
def self.level= level
|
266
|
-
SemanticLogger.default_level = level
|
267
|
-
end
|
268
|
-
|
269
|
-
|
270
|
-
def self.setup?
|
271
|
-
!!@setup
|
272
|
-
end
|
273
|
-
|
274
|
-
|
275
|
-
def self.get_config_level
|
276
|
-
if Locd.config[:trace].truthy?
|
277
|
-
return :trace
|
278
|
-
elsif Locd.config[:debug].truthy?
|
279
|
-
return :debug
|
280
|
-
elsif level = Locd.config[:log, :level]
|
281
|
-
return level.to_sym
|
282
|
-
end
|
283
|
-
|
284
|
-
nil
|
285
|
-
end
|
286
|
-
|
287
|
-
|
288
|
-
def self.set_config_levels
|
289
|
-
if levels = Locd.config[:log, :levels]
|
290
|
-
levels.each do |name, level|
|
291
|
-
const = begin
|
292
|
-
NRSER.to_const name
|
293
|
-
rescue
|
294
|
-
next
|
295
|
-
end
|
296
|
-
|
297
|
-
level = level.to_sym
|
298
|
-
|
299
|
-
self.logger.debug "Setting logger level",
|
300
|
-
logger: const.logger,
|
301
|
-
level: level
|
302
|
-
|
303
|
-
const.logger.level = level
|
304
|
-
|
305
|
-
self.logger.debug "Logger level set",
|
306
|
-
logger: const.logger
|
307
|
-
end
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
|
312
|
-
# Setup logging.
|
313
|
-
#
|
314
|
-
# @param [Symbol?] level:
|
315
|
-
# Optional log level. If provided, it takes precedence. Otherwise, we will
|
316
|
-
# look for log levels in the ENV vars. If nothing is found, no default
|
317
|
-
# log level will be set - it will remain whatever default it already is
|
318
|
-
# (usually `:info` unless something else has changed it).
|
319
|
-
#
|
320
|
-
# @param [Boolean] sync:
|
321
|
-
# When `true`, we will hack out Semantic Logger's async (threaded)
|
322
|
-
# processor and install a synchronous one, which is what you want when
|
323
|
-
# running from the CLI so that output is in order with execution (we don't
|
324
|
-
# care about the performance implications there).
|
325
|
-
#
|
326
|
-
# @param [IO | Hash | String] dest:
|
327
|
-
# Set the appender, see {.appender=}.
|
328
|
-
#
|
329
|
-
# @return [true]
|
330
|
-
# If logging was setup.
|
331
|
-
#
|
332
|
-
# @return [false]
|
333
|
-
# If logging has already been setup (warning will be logged as well).
|
334
|
-
#
|
335
|
-
def self.setup level: nil, sync: false, dest: nil
|
336
|
-
if setup?
|
337
|
-
logger.warn "Logging is already setup!"
|
338
|
-
return false
|
339
|
-
end
|
340
|
-
|
341
|
-
SemanticLogger.application = 'locd'
|
342
|
-
|
343
|
-
level = get_config_level if level.nil?
|
344
|
-
self.level = level if level
|
345
|
-
self.appender = dest if dest
|
346
|
-
|
347
|
-
if sync
|
348
|
-
# Hack up SemanticLogger to do sync logging in the main thread
|
349
|
-
|
350
|
-
# Create a {Locd::Logging::Appender::Sync}, which implements the
|
351
|
-
# {SemanticLogger::Appender::Async} interface but just forwards directly
|
352
|
-
# to it's appender in the same thread, and point it where
|
353
|
-
# {SemanticLogger::Processor.instance} (which is an Async) points.
|
354
|
-
#
|
355
|
-
sync_appender = Appender::Sync.new \
|
356
|
-
appender: SemanticLogger::Processor.instance.appender
|
357
|
-
|
358
|
-
# Swap our sync in for the async
|
359
|
-
SemanticLogger::Processor.instance_variable_set \
|
360
|
-
:@processor,
|
361
|
-
sync_appender
|
362
|
-
end
|
363
|
-
|
364
|
-
@setup = true
|
365
|
-
|
366
|
-
true
|
367
|
-
end # .setup
|
368
|
-
|
369
|
-
|
370
|
-
def self.appender
|
371
|
-
@appender
|
372
|
-
end
|
373
|
-
|
374
|
-
|
375
|
-
def self.appender= value
|
376
|
-
# Save ref to current appender (if any) so we can remove it after adding
|
377
|
-
# the new one.
|
378
|
-
old_appender = @appender
|
379
|
-
|
380
|
-
@appender = case value
|
381
|
-
when Hash
|
382
|
-
SemanticLogger.add_appender value
|
383
|
-
when String
|
384
|
-
SemanticLogger.add_appender file_name: value
|
385
|
-
else
|
386
|
-
SemanticLogger.add_appender \
|
387
|
-
io: value,
|
388
|
-
formatter: Formatters::Color.new
|
389
|
-
end
|
390
|
-
|
391
|
-
# Remove the old appender (if there was one). This is done after adding
|
392
|
-
# the new one so that failing won't result with no appenders.
|
393
|
-
SemanticLogger.remove_appender( old_appender ) if old_appender
|
394
|
-
|
395
|
-
@appender
|
396
|
-
end
|
397
|
-
|
398
|
-
|
399
|
-
end # module Locd::Logging
|