loggo_rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/loggo_rails.rb +14 -0
- data/lib/loggo_rails/client.rb +34 -0
- data/lib/loggo_rails/engine.rb +67 -0
- data/lib/loggo_rails/formatter.rb +181 -0
- data/lib/loggo_rails/logger.rb +8 -0
- data/lib/loggo_rails/sync.rb +24 -0
- data/lib/loggo_rails/version.rb +3 -0
- data/loggo_rails.gemspec +29 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 322276f03e6284f2a9f14f99fa72ae4aa8a62f36
|
4
|
+
data.tar.gz: 10ddf9b8cb3fff7b14e292d9ab3bde0dfcd0a94f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b62016fe5d856bbacba34ada628d7ff1d18b41c8d3f63a563edead09602494a90eb272208be01e836fde7dc0a069eb0566e12a40b7cf99e9065b4657bdce15b
|
7
|
+
data.tar.gz: c5a98b943ba4ac4cdde6b5c92140000d89803742a59a4bf46f9e65cb06f2ca7f5ada5285a797ec2075a33781fd27b93dc994e64be3a5af933044b9125cf7ff48
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at webmaster.lelo@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Alboom Pro
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# LoggoRails
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/loggo_rails`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'loggo_rails'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install loggo_rails
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Welington Sampaio/loggo_rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "loggo_rails"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/loggo_rails.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'active_support/dependencies/autoload'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module LoggoRails
|
6
|
+
include ::ActiveSupport::Autoload
|
7
|
+
|
8
|
+
autoload :Client, 'loggo_rails/client'
|
9
|
+
autoload :Formatter, 'loggo_rails/formatter'
|
10
|
+
autoload :Logger, 'loggo_rails/logger'
|
11
|
+
autoload :Sync, 'loggo_rails/sync'
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'loggo_rails/engine'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module LoggoRails
|
2
|
+
class Client
|
3
|
+
API_URL = 'http://localhost:3579'.freeze
|
4
|
+
|
5
|
+
attr_reader :token
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@token = Rails.configuration.loggo_rails.token
|
9
|
+
end
|
10
|
+
|
11
|
+
def insert(options)
|
12
|
+
RestClient::Request.execute(
|
13
|
+
headers: client_headers,
|
14
|
+
method: :put,
|
15
|
+
url: insert_url,
|
16
|
+
payload: options.to_json,
|
17
|
+
verify_ssl: false
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def client_headers
|
24
|
+
{
|
25
|
+
'Authorization': token,
|
26
|
+
'Content-Type': 'application/json'
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def insert_url
|
31
|
+
"#{Rails.configuration.loggo_rails.api_url || API_URL}/insert"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module LoggoRails
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
config.loggo_rails = ActiveSupport::OrderedOptions.new
|
4
|
+
|
5
|
+
|
6
|
+
config.loggo_rails.logger = LoggoRails::Logger.new false
|
7
|
+
config.loggo_rails.formatter = LoggoRails::Formatter.new
|
8
|
+
config.loggo_rails.api_url = nil
|
9
|
+
config.loggo_rails.app_name = 'rails-logs'
|
10
|
+
|
11
|
+
# Replace Rails logger initializer
|
12
|
+
Rails::Application::Bootstrap.initializers.delete_if {|i| i.name == :initialize_logger}
|
13
|
+
|
14
|
+
initializer :initialize_logger, group: :all do
|
15
|
+
|
16
|
+
config = Rails.application.config
|
17
|
+
config.colorize_logging = false
|
18
|
+
config.log_tags = [:request_id, :remote_ip]
|
19
|
+
config.loggo_rails.logger.formatter = config.loggo_rails.formatter
|
20
|
+
Rails.logger = config.logger = ActiveSupport::TaggedLogging.new config.loggo_rails.logger
|
21
|
+
|
22
|
+
# # Replace Rails loggers
|
23
|
+
# [:active_record, :action_controller, :action_mailer, :action_view].each do |name|
|
24
|
+
# ActiveSupport.on_load(name) {include SemanticLogger::Loggable}
|
25
|
+
# end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Before any initializers run, but after the gems have been loaded
|
29
|
+
# config.before_initialize do
|
30
|
+
# # Replace the Sidekiq logger
|
31
|
+
# Sidekiq::Logging.logger = SemanticLogger[Sidekiq]
|
32
|
+
#
|
33
|
+
# # Set the logger for concurrent-ruby
|
34
|
+
# Concurrent.global_logger = SemanticLogger[Concurrent] if defined?(Concurrent)
|
35
|
+
#
|
36
|
+
# # Rails Patches
|
37
|
+
# # require('rails_semantic_logger/extensions/action_cable/tagged_logger_proxy') if defined?(ActionCable)
|
38
|
+
# # require('rails_semantic_logger/extensions/action_controller/live') if defined?(ActionController::Live)
|
39
|
+
# require('rails_semantic_logger/extensions/action_dispatch/debug_exceptions') if defined?(ActionDispatch::DebugExceptions)
|
40
|
+
# require('rails_semantic_logger/extensions/action_view/streaming_template_renderer') if defined?(ActionView::StreamingTemplateRenderer::Body)
|
41
|
+
# require('rails_semantic_logger/extensions/active_job/logging') if defined?(ActiveJob)
|
42
|
+
# require('rails_semantic_logger/extensions/active_model_serializers/logging') if defined?(ActiveModelSerializers)
|
43
|
+
#
|
44
|
+
# # if config.rails_semantic_logger.semantic
|
45
|
+
# require('rails_semantic_logger/extensions/rails/rack/logger') if defined?(Rails::Rack::Logger)
|
46
|
+
# require('rails_semantic_logger/extensions/action_controller/log_subscriber') if defined?(ActionController)
|
47
|
+
# require('rails_semantic_logger/extensions/active_record/log_subscriber') if defined?(ActiveRecord::LogSubscriber)
|
48
|
+
# # end
|
49
|
+
#
|
50
|
+
# # unless config.rails_semantic_logger.started
|
51
|
+
# require('rails_semantic_logger/extensions/rails/rack/logger_info_as_debug') if defined?(Rails::Rack::Logger)
|
52
|
+
# # end
|
53
|
+
#
|
54
|
+
# # unless config.rails_semantic_logger.rendered
|
55
|
+
# require('rails_semantic_logger/extensions/action_view/log_subscriber') if defined?(ActionView::LogSubscriber)
|
56
|
+
# # end
|
57
|
+
#
|
58
|
+
# # if config.rails_semantic_logger.processing
|
59
|
+
# require('rails_semantic_logger/extensions/action_controller/log_subscriber_processing') if defined?(ActionView::LogSubscriber)
|
60
|
+
# # end
|
61
|
+
#
|
62
|
+
# # if config.rails_semantic_logger.named_tags && defined?(Rails::Rack::Logger)
|
63
|
+
# Rails::Rack::Logger.named_tags = config.rails_semantic_logger.named_tags
|
64
|
+
# # end
|
65
|
+
# end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
module LoggoRails
|
2
|
+
class Formatter < ::Logger::Formatter
|
3
|
+
|
4
|
+
# [123213-12312-1231-123] [123.123.123.123] body of message
|
5
|
+
REGEX_SESSION_IP = /^\[(?<session>[^\]]+)\]\s\[(?<ip>[^\]]+)\]\s(?<content>.+)/m.freeze
|
6
|
+
|
7
|
+
# Started GET "/api/v1/albums" for 127.0.0.1 at 2017-04-26 19:03:33 -0300
|
8
|
+
REGEX_STARTED = /Started (?<method>[\S]+) "(?<path>[^"]+)" for (?<ip>[\S]+) at (?<time>.+)/.freeze
|
9
|
+
|
10
|
+
# Processing by Api::V1::AlbumsController#update as JSON
|
11
|
+
REGEX_PROCESSING = /Processing by (?<controller>[^\#]+)\#(?<action>\w+) as (?<format>\w+)/.freeze
|
12
|
+
|
13
|
+
# Parameters: {"album"=>{"title"=>"asdsadas", "status"=>"draft", "view_mode"=>"list", "cover"=>""}}
|
14
|
+
REGEX_PARAMETERS = /Parameters: (?<parameters>.+)/.freeze
|
15
|
+
|
16
|
+
# Unpermitted parameters: group, slug, autoFocus, focused, oldName
|
17
|
+
REGEX_UNPERMITTED_PARAMETERS = /Unpermitted parameters: (?<unpermittedparameters>[\w, ]+)/.freeze
|
18
|
+
|
19
|
+
# SQL (3.5ms) INSERT INTO `albuns` (`id_cliente`, `titulo`, `url`, `capa`, `status`) VALUES (3, 'asdsadas', 'asdsadas', '', 'draft')
|
20
|
+
# Album Load (0.7ms) SELECT `albuns`.* FROM `albuns` WHERE `albuns`.`deleted_at` IS NULL AND `albuns`.`id_cliente` = 3 AND `albuns`.`id` = 22898 LIMIT 1
|
21
|
+
# Client Load (3.6ms) SELECT `clientes`.* FROM `clientes` WHERE `clientes`.`id` = 3 LIMIT 1
|
22
|
+
# SQL (4.3ms) DELETE FROM `categorias` WHERE `categorias`.`id` = 7
|
23
|
+
REGEX_SQL = /(SQL|(?<model>[\S]+) [\S]+)\s+\((?<time>[^)]+)\)\s+(?<query>.+)/.freeze
|
24
|
+
|
25
|
+
# Rendered api/v1/categories/show.rabl (1.0ms)
|
26
|
+
REGEX_RENDERED = /Rendered (?<view>\S+) \((?<time>[^\)]+)\)/.freeze
|
27
|
+
|
28
|
+
# Rendering api/v1/categories/show.rabl
|
29
|
+
REGEX_RENDERING = /Rendering (<view>\S+)/
|
30
|
+
.freeze
|
31
|
+
# Completed 201 Created in 65ms (Views: 10.4ms | ActiveRecord: 38.2ms)
|
32
|
+
# Completed 404 Not Found in 13ms (Views: 0.2ms | ActiveRecord: 0.8ms)
|
33
|
+
# Completed 204 No Content in 172ms (ActiveRecord: 67.1ms)
|
34
|
+
REGEX_COMPLETED_FULL = /Completed (?<response>\d+) .+ in (?<time>\S+)(?<details>.+)?/.freeze
|
35
|
+
|
36
|
+
# (Views: 10.4ms | ActiveRecord: 38.2ms)
|
37
|
+
# (Views: 0.2ms | ActiveRecord: 0.8ms)
|
38
|
+
# (ActiveRecord: 67.1ms)
|
39
|
+
REGEX_COMPLETED_VIEWS = /Views: (?<time>[^\s\)]+)/.freeze
|
40
|
+
|
41
|
+
# (Views: 10.4ms | ActiveRecord: 38.2ms)
|
42
|
+
# (Views: 0.2ms | ActiveRecord: 0.8ms)
|
43
|
+
# (ActiveRecord: 67.1ms)
|
44
|
+
REGEX_COMPLETED_ACTIVE_RECORD = /ActiveRecord: (?<time>[^\s\)]+)/.freeze
|
45
|
+
|
46
|
+
attr_reader :sync
|
47
|
+
|
48
|
+
def initialize
|
49
|
+
@sync = LoggoRails::Sync.new
|
50
|
+
end
|
51
|
+
|
52
|
+
def call(severity, time, progname, msg)
|
53
|
+
Thread.new do
|
54
|
+
parsed = parse_message msg2str(msg), progname
|
55
|
+
return unless parsed
|
56
|
+
node, descr, content = parsed
|
57
|
+
sync.write(
|
58
|
+
app: Rails.configuration.loggo_rails.app_name,
|
59
|
+
log: {
|
60
|
+
timestamp: time,
|
61
|
+
type: severity,
|
62
|
+
node: node,
|
63
|
+
description: descr,
|
64
|
+
content: content
|
65
|
+
}
|
66
|
+
)
|
67
|
+
end
|
68
|
+
super
|
69
|
+
end
|
70
|
+
|
71
|
+
protected
|
72
|
+
|
73
|
+
def parse_message(msg, progname)
|
74
|
+
session, ip, msg = load_session_ip_from msg.strip
|
75
|
+
return false unless session
|
76
|
+
msg.strip!
|
77
|
+
node, match = test_node msg
|
78
|
+
content = {
|
79
|
+
process_id: $$,
|
80
|
+
session: session,
|
81
|
+
ip: ip,
|
82
|
+
progname: progname,
|
83
|
+
}
|
84
|
+
match.names.each do |name|
|
85
|
+
case name
|
86
|
+
when 'details'
|
87
|
+
content = completed_details(content, match[name])
|
88
|
+
when 'parameters'
|
89
|
+
content[name] = proccess_parameters(match[name])
|
90
|
+
when 'unpermittedparameters'
|
91
|
+
content[:parameters] = proccess_parameters(match[name])
|
92
|
+
else
|
93
|
+
content[name] = match[name]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
[node, msg.split("\n")[0], content]
|
97
|
+
end
|
98
|
+
|
99
|
+
def load_session_ip_from(msg)
|
100
|
+
match = REGEX_SESSION_IP.match msg
|
101
|
+
if match
|
102
|
+
[match[:session], match[:ip], match[:content]]
|
103
|
+
else
|
104
|
+
[false, false, false]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_node(content)
|
109
|
+
nodes = {
|
110
|
+
started: REGEX_STARTED,
|
111
|
+
processing: REGEX_PROCESSING,
|
112
|
+
parameters: REGEX_PARAMETERS,
|
113
|
+
unpermitted_parameters: REGEX_UNPERMITTED_PARAMETERS,
|
114
|
+
sql: REGEX_SQL,
|
115
|
+
render: [REGEX_RENDERED, REGEX_RENDERING],
|
116
|
+
completed: REGEX_COMPLETED_FULL
|
117
|
+
}
|
118
|
+
|
119
|
+
nodes.each_key do |key|
|
120
|
+
if nodes[key].is_a? Array
|
121
|
+
nodes[key].each do |rgx|
|
122
|
+
match = rgx.match content
|
123
|
+
return [key, match] if match
|
124
|
+
end
|
125
|
+
else
|
126
|
+
match = nodes[key].match content
|
127
|
+
return [key, match] if match
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
[false, false]
|
132
|
+
end
|
133
|
+
|
134
|
+
def completed_details(content, match)
|
135
|
+
return content if match.blank?
|
136
|
+
match.strip!
|
137
|
+
nodes = {
|
138
|
+
views: REGEX_COMPLETED_VIEWS,
|
139
|
+
active_record: REGEX_COMPLETED_ACTIVE_RECORD
|
140
|
+
}
|
141
|
+
nodes.each_key do |key|
|
142
|
+
m = nodes[key].match match
|
143
|
+
content[key] = m[:time] if m
|
144
|
+
end
|
145
|
+
content
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
# Convert the log parameters to Hash Object
|
150
|
+
#
|
151
|
+
# @see https://gist.github.com/gene1wood/bd8159ad90b0799d9436
|
152
|
+
#
|
153
|
+
# @param str String
|
154
|
+
# @return Hash
|
155
|
+
def proccess_parameters(str)
|
156
|
+
str.strip!
|
157
|
+
# Transform object string symbols to quoted strings
|
158
|
+
str.gsub!(/([{,]\s*):([^>\s]+)\s*=>/, '\1"\2"=>')
|
159
|
+
|
160
|
+
# Transform object string numbers to quoted strings
|
161
|
+
str.gsub!(/([{,]\s*)([0-9]+\.?[0-9]*)\s*=>/, '\1"\2"=>')
|
162
|
+
|
163
|
+
# Transform object value symbols to quotes strings
|
164
|
+
str.gsub!(/([{,]\s*)(".+?"|[0-9]+\.?[0-9]*)\s*=>\s*:([^,}\s]+\s*)/, '\1\2=>"\3"')
|
165
|
+
|
166
|
+
# Transform array value symbols to quotes strings
|
167
|
+
str.gsub!(/([\[,]\s*):([^,\]\s]+)/, '\1"\2"')
|
168
|
+
|
169
|
+
# Transform object string object value delimiter to colon delimiter
|
170
|
+
str.gsub!(/([{,]\s*)(".+?"|[0-9]+\.?[0-9]*)\s*=>/, '\1\2:')
|
171
|
+
|
172
|
+
JSON.parse(str)
|
173
|
+
end
|
174
|
+
|
175
|
+
# @param str String
|
176
|
+
# @return Array
|
177
|
+
def proccess_unpermitted_parameters(str)
|
178
|
+
str.split(', ')
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module LoggoRails
|
2
|
+
class Sync
|
3
|
+
include MonitorMixin
|
4
|
+
|
5
|
+
def initialize()
|
6
|
+
mon_initialize
|
7
|
+
end
|
8
|
+
|
9
|
+
def write(msg)
|
10
|
+
synchronize do
|
11
|
+
client.insert msg
|
12
|
+
end
|
13
|
+
rescue Exception => ignored
|
14
|
+
warn("log writing failed. #{ignored}")
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def client
|
20
|
+
@client ||= LoggoRails::Client.new
|
21
|
+
@client
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/loggo_rails.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'loggo_rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'loggo_rails'
|
8
|
+
spec.version = LoggoRails::VERSION
|
9
|
+
spec.authors = ['Welington Sampaio']
|
10
|
+
spec.email = ['lelo@alboompro.com']
|
11
|
+
|
12
|
+
spec.summary = 'Simple sync logging with a Log-Go service for Rails Applications'
|
13
|
+
spec.description = 'Log-GO is a centralized Log Service, high availability and scalable Write in GO. This projet should '
|
14
|
+
spec.homepage = 'https://www.alboompro.com/'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_dependency 'rails', '~> 5.0'
|
24
|
+
spec.add_dependency 'json', '~> 1.7'
|
25
|
+
spec.add_dependency 'rest-client', '~> 1.6'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: loggo_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Welington Sampaio
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description: 'Log-GO is a centralized Log Service, high availability and scalable
|
84
|
+
Write in GO. This projet should '
|
85
|
+
email:
|
86
|
+
- lelo@alboompro.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- CODE_OF_CONDUCT.md
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/loggo_rails.rb
|
100
|
+
- lib/loggo_rails/client.rb
|
101
|
+
- lib/loggo_rails/engine.rb
|
102
|
+
- lib/loggo_rails/formatter.rb
|
103
|
+
- lib/loggo_rails/logger.rb
|
104
|
+
- lib/loggo_rails/sync.rb
|
105
|
+
- lib/loggo_rails/version.rb
|
106
|
+
- loggo_rails.gemspec
|
107
|
+
homepage: https://www.alboompro.com/
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.5.1
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Simple sync logging with a Log-Go service for Rails Applications
|
131
|
+
test_files: []
|