context_logger 0.0.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.
- checksums.yaml +7 -0
- data/lib/context_logger.rb +65 -0
- data/lib/context_logger/engine.rb +13 -0
- metadata +45 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 333b65a3b19592767012b0e5a6270e730490f3f2
|
|
4
|
+
data.tar.gz: 10a3e036c37d9ef3f0d7371ebae863efb273ef68
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 306dfde81c68038793a82d0d91534a5bb49b16479361486e8601539df899cf6588aa21d55aecdb573be43f81b8b56ca9287c2e31000275e07e09b312fc2c3821
|
|
7
|
+
data.tar.gz: c9f76689f648a08b28915a98c0a47eabb4123d30ec06ccd93d2622c5477bd1c4b50e4ab7a86b71f9a68f8b2ec867435270b3c4f400eed818b4922d8aa6113b93
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require 'context_logger/engine'
|
|
2
|
+
|
|
3
|
+
class ContextLogger
|
|
4
|
+
|
|
5
|
+
# LOG_KEYS = [:context, :action_id, :message]
|
|
6
|
+
SEVERITY_TYPES = [:info, :warn, :error, :debug, :unknown, :fatal]
|
|
7
|
+
|
|
8
|
+
@defaults = {
|
|
9
|
+
context: :ni_log,
|
|
10
|
+
# action_id: nil,
|
|
11
|
+
# server_name: nil,
|
|
12
|
+
# method: nil,
|
|
13
|
+
# params: nil,
|
|
14
|
+
message: 'Empty message',
|
|
15
|
+
# stack_trace: nil
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@options = {}.merge(@defaults)
|
|
19
|
+
|
|
20
|
+
SEVERITY_TYPES.each do |severity_type|
|
|
21
|
+
define_singleton_method severity_type do |context, server, action_id, method, params, message, stack_trace|
|
|
22
|
+
self.log({severity: severity_type, context: context, server: server, action_id: action_id, method: method, params: params, message: message, stack_trace: stack_trace})
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
@context_loggers = {}
|
|
27
|
+
|
|
28
|
+
def self.setup(options)
|
|
29
|
+
@options = (@options || {}).merge(options)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.options
|
|
33
|
+
return @options
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.logs_folder
|
|
37
|
+
# TODO: set the path from config
|
|
38
|
+
@logs_folder ||= "#{Rails.root}/log"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def self.log_file_path(current_context)
|
|
45
|
+
file_name = current_context.to_s.downcase.gsub(/ /, '_').gsub(/[^0-9a-z_]/, '')
|
|
46
|
+
return "#{logs_folder}/#{file_name}.log"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def self.log(params)
|
|
50
|
+
params_with_defaults = options.merge(params.reject{|_, v| v.nil?})
|
|
51
|
+
|
|
52
|
+
current_context = params_with_defaults[:context]
|
|
53
|
+
current_severity = params_with_defaults[:severity]
|
|
54
|
+
|
|
55
|
+
logger_instance = logger_of_context(current_context)
|
|
56
|
+
|
|
57
|
+
logger_instance.send current_severity.to_sym, params_with_defaults.except(:context, :severity)
|
|
58
|
+
Rails.logger.send current_severity.to_sym, params_with_defaults.except(:severity)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def self.logger_of_context(current_context)
|
|
62
|
+
@context_loggers[current_context] ||= Logger.new(log_file_path(current_context))
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module ContextLoggerEngine
|
|
2
|
+
class Engine < ::Rails::Engine
|
|
3
|
+
isolate_namespace ContextLogger
|
|
4
|
+
|
|
5
|
+
initializer :append_migrations do |app|
|
|
6
|
+
unless app.root.to_s.match root.to_s
|
|
7
|
+
config.paths["db/migrate"].expanded.each do |expanded_path|
|
|
8
|
+
app.config.paths["db/migrate"] << expanded_path
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: context_logger
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Alexander Libster
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-11-11 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: writes log to db and log file and exposes it via http
|
|
14
|
+
email: 012alex012@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/context_logger.rb
|
|
20
|
+
- lib/context_logger/engine.rb
|
|
21
|
+
homepage: ''
|
|
22
|
+
licenses:
|
|
23
|
+
- MIT
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubyforge_project:
|
|
41
|
+
rubygems_version: 2.2.2
|
|
42
|
+
signing_key:
|
|
43
|
+
specification_version: 4
|
|
44
|
+
summary: writes log to db and log file and exposes it via http
|
|
45
|
+
test_files: []
|