lonline 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/generators/lonline_generator.rb +114 -0
- data/lib/lonline.rb +248 -0
- data/lib/lonline/version.rb +3 -0
- data/lib/lonline_report.rb +161 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e7881beef7a86ecb8796452640f609951435a563
|
4
|
+
data.tar.gz: 4b9078505a7baf1d203880c3d7ecacc363785b7e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1eb613295148a2b31a104bb3afa4f7745a300d649be91989fa3182fac8a8f11a4963d3c0a31be17a33cb2319050dbfa7a7a87b1e5df1e57c44dd05e0f2bb956f
|
7
|
+
data.tar.gz: 3c3a7d8d13dec976fce98c628552a50cf3ba9be8fca96d3d4f2f0e01958aa9f0f13206dc204134a9b5fb7dc6ba8e722d95542ab8fd51026cc59fa18231537475
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# This generator creates the files to setup lonline
|
2
|
+
# Will create an initializer to load lonline settings
|
3
|
+
# Will create a setting file as a template to put information about
|
4
|
+
# Dynamicloud credentials and more settings.
|
5
|
+
class LonlineGenerator < Rails::Generators::Base
|
6
|
+
def create_initializer_file
|
7
|
+
create_file 'config/initializers/lonline.rb',
|
8
|
+
"Lonline::SETUP.load('config/lonline.yml', Rails.env)
|
9
|
+
# The line below sets the logger you're using in your program, every call of lonline will execute the same method in your logger
|
10
|
+
# For example:
|
11
|
+
# Lonline.log.fatal('The app has crashed and its state is unavailable') # This call will execute the following method in your logger
|
12
|
+
# logger.fatal('The app has crashed and its state is unavailable') # If this method is unavailable, lonline
|
13
|
+
# will catch the error without any feedback to you.
|
14
|
+
# If you don't need this behaviour, remove this line.
|
15
|
+
Lonline::SETUP.logger = Rails.logger"
|
16
|
+
|
17
|
+
create_file 'config/lonline.yml',
|
18
|
+
"test: &default
|
19
|
+
# Credentials for REST APIs
|
20
|
+
# Go to https://www.dynamicloud.org/manage and get the API keys available in your profile
|
21
|
+
# If you don't have an account in Dynamicloud, visit https://www.dynamicloud.org/signupform
|
22
|
+
# You can easily use a social network to sign up
|
23
|
+
csk: Enter your Client_Secret_Key
|
24
|
+
aci: Enter your API_Client_Id
|
25
|
+
# This is the model identifier for test and development environment
|
26
|
+
# The model contains the structure to store logs into the cloud
|
27
|
+
# For more information about models in Dynamicloud visit https://www.dynamicloud.org/documents/mfdoc
|
28
|
+
model_identifier: 0
|
29
|
+
# async = true is the best choice to avoid impact in your app's execution.
|
30
|
+
# If you want to wait for every request, set async: false
|
31
|
+
async: false
|
32
|
+
# Shows every warning like rejected request from Dynamicloud and other warnings in lonline
|
33
|
+
warning: true
|
34
|
+
# Send the backtrace (the ordered method calls) of the log. If you want to avoid this set to false
|
35
|
+
backtrace: true
|
36
|
+
# This tag indicates the level of lonline
|
37
|
+
# The following table is an explanation of levels in Lonline (Descriptions from the great Log4j library):
|
38
|
+
# ------------------------------------------------------------------------------------------------------------
|
39
|
+
# | Level | Activated levels | Description |
|
40
|
+
# ------------------------------------------------------------------------------------------------------------
|
41
|
+
# | fatal | Fatal | Designates very severe error events that will presumably lead |
|
42
|
+
# | | | the application to abort. |
|
43
|
+
# ------------------------------------------------------------------------------------------------------------
|
44
|
+
# | error | Fatal, Error | Designates error events that might still allow the application |
|
45
|
+
# | | | to continue running. |
|
46
|
+
# ------------------------------------------------------------------------------------------------------------
|
47
|
+
# | warn | Fatal, Error, Warn | Designates potentially harmful situations. |
|
48
|
+
# ------------------------------------------------------------------------------------------------------------
|
49
|
+
# | info | Fatal, Error, Warn, Info | Designates informational messages that highlight the progress |
|
50
|
+
# | | | of the application at coarse-grained level. |
|
51
|
+
# ------------------------------------------------------------------------------------------------------------
|
52
|
+
# | debug | Fatal, Error, Info, Warn, | Designates fine-grained informational events that are most |
|
53
|
+
# | | Debug | useful to debug an application. |
|
54
|
+
# ------------------------------------------------------------------------------------------------------------
|
55
|
+
# | trace | All levels | Traces the code execution between methods, lines, etc. |
|
56
|
+
# ------------------------------------------------------------------------------------------------------------
|
57
|
+
# | off | None | The highest possible rank and is intended to turn off logging. |
|
58
|
+
# ------------------------------------------------------------------------------------------------------------
|
59
|
+
level: trace
|
60
|
+
# report_limit indicates how many records lonline will execute to fetch data from Dynamicloud.
|
61
|
+
# If you need to increase this value, please think about the available requests per month in your account.
|
62
|
+
# Dynamicloud uses a limit of records per request, at this time the max records per request is 20. So,
|
63
|
+
# report_limit=100 are 5 request.
|
64
|
+
report_limit: 100
|
65
|
+
development:
|
66
|
+
<<: *default
|
67
|
+
production:
|
68
|
+
<<: *default
|
69
|
+
# Credentials for REST APIs in production environment
|
70
|
+
# Go to https://www.dynamicloud.org/manage and get the API keys available in your profile
|
71
|
+
# If you don't have an account in Dynamicloud, visit https://www.dynamicloud.org/signupform
|
72
|
+
# You can easily use a social network to sign up
|
73
|
+
csk: Enter your Client_Secret_Key
|
74
|
+
aci: Enter your API_Client_Id
|
75
|
+
# This is the model id for production environment
|
76
|
+
model_identifier: 0
|
77
|
+
# async = true is the best choice to avoid impact in your app's execution.
|
78
|
+
# If you want to wait for every request, set async: false
|
79
|
+
async: true
|
80
|
+
# Shows every warning like rejected request from Dynamicloud
|
81
|
+
warning: false
|
82
|
+
# Send the backtrace of the log. If you want to avoid this set to false
|
83
|
+
backtrace: true
|
84
|
+
# This tag indicates the level of lonline
|
85
|
+
# The following table is an explanation of levels in Lonline (Descriptions from the great Log4j library):
|
86
|
+
# ------------------------------------------------------------------------------------------------------------
|
87
|
+
# | Level | Activated levels | Description |
|
88
|
+
# ------------------------------------------------------------------------------------------------------------
|
89
|
+
# | fatal | Fatal | Designates very severe error events that will presumably lead |
|
90
|
+
# | | | the application to abort. |
|
91
|
+
# ------------------------------------------------------------------------------------------------------------
|
92
|
+
# | error | Fatal, Error | Designates error events that might still allow the application |
|
93
|
+
# | | | to continue running. |
|
94
|
+
# ------------------------------------------------------------------------------------------------------------
|
95
|
+
# | warn | Fatal, Error, Warn | Designates potentially harmful situations. |
|
96
|
+
# ------------------------------------------------------------------------------------------------------------
|
97
|
+
# | info | Fatal, Error, Warn, Info | Designates informational messages that highlight the progress |
|
98
|
+
# | | | of the application at coarse-grained level. |
|
99
|
+
# ------------------------------------------------------------------------------------------------------------
|
100
|
+
# | debug | Fatal, Error, Info, Warn | Designates fine-grained informational events that are most |
|
101
|
+
# | | Debug | useful to debug an application. |
|
102
|
+
# ------------------------------------------------------------------------------------------------------------
|
103
|
+
# | trace | All levels | Traces the code execution between methods, lines, etc. |
|
104
|
+
# ------------------------------------------------------------------------------------------------------------
|
105
|
+
# | off | None | The highest possible rank and is intended to turn off logging. |
|
106
|
+
# ------------------------------------------------------------------------------------------------------------
|
107
|
+
level: error
|
108
|
+
# report_limit indicates how many records lonline will execute to fetch data from Dynamicloud.
|
109
|
+
# If you need to increase this value, please think about the available requests per month in your account.
|
110
|
+
# Dynamicloud uses a limit of records per request, at this time the max records per request is 20. So,
|
111
|
+
# report_limit=100 are 5 request (if your report execution has at least 100 logs).
|
112
|
+
report_limit: 100"
|
113
|
+
end
|
114
|
+
end
|
data/lib/lonline.rb
ADDED
@@ -0,0 +1,248 @@
|
|
1
|
+
#Copyright (c) 2016 Dynamicloud
|
2
|
+
#
|
3
|
+
#Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
#of this software and associated documentation files (the "Software"), to deal
|
5
|
+
#in the Software without restriction, including without limitation the rights
|
6
|
+
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
#copies of the Software, and to permit persons to whom the Software is
|
8
|
+
#furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
#The above copyright notice and this permission notice shall be included in all
|
11
|
+
#copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
#SOFTWARE.
|
20
|
+
#
|
21
|
+
#Lonline module provides the main functions to log and send data to the cloud
|
22
|
+
#
|
23
|
+
#The uses of Lonline are the followings:
|
24
|
+
#
|
25
|
+
#Lonline.log.trace('Calling method Y')
|
26
|
+
#Lonline.log.debug('Creating new object')
|
27
|
+
#Lonline.log.info('Process has finished')
|
28
|
+
#Lonline.log.warn('It could'n create this object, the process will try later.)
|
29
|
+
#Lonline.log.error('Unable to load setting file')
|
30
|
+
#Lonline.log.fatal('The app has crashed and its state is unavailable')
|
31
|
+
#
|
32
|
+
#If you active warning in lonline, every rejected request from Dynamicloud will be printed in stdout.
|
33
|
+
#
|
34
|
+
#Lonline will verify the level of logging to avoid unnecessary request to Dynamicloud
|
35
|
+
#
|
36
|
+
#Important: Dynamicloud offers in its free version 5.000 monthly requests and 500Mb of disk space.
|
37
|
+
#
|
38
|
+
#Dynamicloud is a powerful service that offers a dynamic way to add attributes to your business.
|
39
|
+
#To send additional data, you need to pass a hash with the additional attributes (Fields)
|
40
|
+
#
|
41
|
+
#For example:
|
42
|
+
#
|
43
|
+
#Lonline.log.fatal('Testing trace', {:module => 'Logging from financial module.'})
|
44
|
+
#
|
45
|
+
#The above call, indicates to lonline that you need to send an additional field called 'module'.
|
46
|
+
#
|
47
|
+
#For further information, visit lonline's repository on https://github.com/dynamicloud/lonline_for_ruby
|
48
|
+
|
49
|
+
require 'dynamic_api'
|
50
|
+
require 'yaml'
|
51
|
+
|
52
|
+
module Lonline
|
53
|
+
# The available levels in lonline.
|
54
|
+
LEVELS = {
|
55
|
+
:false => 7,
|
56
|
+
:off => 7,
|
57
|
+
:fatal => 6,
|
58
|
+
:error => 5,
|
59
|
+
:warn => 4,
|
60
|
+
:info => 3,
|
61
|
+
:debug => 2,
|
62
|
+
:trace => 1
|
63
|
+
}
|
64
|
+
|
65
|
+
# This class provides the four methods to log and send data to the cloud.
|
66
|
+
class Log
|
67
|
+
attr_accessor :logger
|
68
|
+
|
69
|
+
def initialize
|
70
|
+
@logger = nil
|
71
|
+
end
|
72
|
+
|
73
|
+
# The DEBUG Level designates fine-grained informational events that are most useful to debug an application.
|
74
|
+
def debug(text, additional_data = {})
|
75
|
+
begin
|
76
|
+
@logger.debug(text)
|
77
|
+
rescue
|
78
|
+
#ignore
|
79
|
+
ensure
|
80
|
+
send_log(:debug, text, additional_data)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# The INFO level designates informational messages that highlight the progress of the application at coarse-grained level.
|
85
|
+
def info(text, additional_data = {})
|
86
|
+
begin
|
87
|
+
@logger.info(text)
|
88
|
+
rescue
|
89
|
+
#ignore
|
90
|
+
ensure
|
91
|
+
send_log(:info, text, additional_data)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# The WARN level designates potentially harmful situations.
|
96
|
+
def warn(text, additional_data = {})
|
97
|
+
begin
|
98
|
+
@logger.warn(text)
|
99
|
+
rescue
|
100
|
+
#ignore
|
101
|
+
ensure
|
102
|
+
send_log(:warn, text, additional_data)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# The ERROR level designates error events that might still allow the application to continue running.
|
107
|
+
def error(text, additional_data = {})
|
108
|
+
begin
|
109
|
+
@logger.error(text)
|
110
|
+
rescue
|
111
|
+
#ignore
|
112
|
+
ensure
|
113
|
+
send_log(:error, text, additional_data)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# The FATAL level designates very severe error events that will presumably lead the application to abort.
|
118
|
+
def fatal(text, additional_data = {})
|
119
|
+
begin
|
120
|
+
@logger.fatal(text)
|
121
|
+
rescue
|
122
|
+
#ignore
|
123
|
+
ensure
|
124
|
+
send_log(:fatal, text, additional_data)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# The TRACE Level designates finer-grained informational events than the DEBUG
|
129
|
+
def trace(text, additional_data = {})
|
130
|
+
begin
|
131
|
+
@logger.trace(text)
|
132
|
+
rescue
|
133
|
+
#ignore
|
134
|
+
ensure
|
135
|
+
send_log(:trace, text, additional_data)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# This method sends the log to Dynamicloud
|
140
|
+
# Dynamic provider will be created using the configuration in lonline.yml (csk and aci)
|
141
|
+
# If any error occurs a warning will be printed only if warning flag is true
|
142
|
+
# The additional_data param are additional data you need to send.
|
143
|
+
def send_log(level, text, additional_data = {})
|
144
|
+
unless Lonline::SETUP::SETTINGS[:config].nil?
|
145
|
+
# Verify logging level
|
146
|
+
allowed_level = Lonline::LEVELS[:off]
|
147
|
+
if Lonline::SETUP::SETTINGS[:config]['level'].nil?
|
148
|
+
Lonline.warn_it('Lonline is using default level :off')
|
149
|
+
else
|
150
|
+
allowed_level = Lonline::LEVELS[Lonline::SETUP::SETTINGS[:config]['level'].to_s.to_sym]
|
151
|
+
if allowed_level.nil?
|
152
|
+
Lonline.warn_it('Lonline is using default level :off')
|
153
|
+
allowed_level = Lonline::LEVELS[:off]
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
current_level = Lonline::LEVELS[level]
|
158
|
+
|
159
|
+
unless current_level >= allowed_level
|
160
|
+
return
|
161
|
+
end
|
162
|
+
# End of level verification
|
163
|
+
|
164
|
+
trace = {
|
165
|
+
:lonlinelevel => level.to_s,
|
166
|
+
:lonlinetext => text
|
167
|
+
}
|
168
|
+
|
169
|
+
trace.merge!(additional_data)
|
170
|
+
|
171
|
+
if Lonline::SETUP::SETTINGS[:config]['backtrace']
|
172
|
+
sub_array = caller[1..caller.length]
|
173
|
+
trace[:lonlinetrace] = sub_array.join("\n")
|
174
|
+
end
|
175
|
+
|
176
|
+
if Lonline::SETUP::SETTINGS[:config]['async']
|
177
|
+
Lonline.warn_it 'Async mode'
|
178
|
+
|
179
|
+
t = schedule(trace)
|
180
|
+
|
181
|
+
# For test environment the async mode is disabled.
|
182
|
+
if Lonline::SETUP::SETTINGS[:config]['env'].eql?('test')
|
183
|
+
Lonline.warn_it 'For test environment, the async process is disabled'
|
184
|
+
|
185
|
+
t.join
|
186
|
+
end
|
187
|
+
else
|
188
|
+
Lonline.warn_it 'Sync mode'
|
189
|
+
call_dynamicloud_service(trace)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def schedule(trace)
|
195
|
+
Thread.new {
|
196
|
+
call_dynamicloud_service(trace)
|
197
|
+
}
|
198
|
+
end
|
199
|
+
|
200
|
+
def call_dynamicloud_service(trace)
|
201
|
+
provider = Dynamicloud::API::DynamicProvider.new(
|
202
|
+
{
|
203
|
+
:csk => Lonline::SETUP::SETTINGS[:config]['csk'],
|
204
|
+
:aci => Lonline::SETUP::SETTINGS[:config]['aci']
|
205
|
+
})
|
206
|
+
begin
|
207
|
+
provider.save_record Lonline::SETUP::SETTINGS[:config]['model_identifier'], trace
|
208
|
+
rescue Exception => e
|
209
|
+
Lonline.warn_it(e.message)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# Global logger
|
215
|
+
LOGGER = Log.new
|
216
|
+
|
217
|
+
# This method returns the global logger.
|
218
|
+
def self.log
|
219
|
+
LOGGER
|
220
|
+
end
|
221
|
+
|
222
|
+
# Prints the warning
|
223
|
+
def self.warn_it(text)
|
224
|
+
if Lonline::SETUP::SETTINGS[:config]['warning']
|
225
|
+
puts "[Lonline WARN @ #{Time.new.utc.strftime('%d %B, %Y %T')}] - #{text}"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
# This module provides methods to setup lonline
|
230
|
+
module SETUP
|
231
|
+
def self.logger=(logger)
|
232
|
+
LOGGER.logger = logger;
|
233
|
+
end
|
234
|
+
|
235
|
+
SETTINGS = {:config => {}}
|
236
|
+
|
237
|
+
# Load yml file with the settings to setup lonline
|
238
|
+
def self.load(file_name, env = ENV['LONLINE_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development')
|
239
|
+
begin
|
240
|
+
SETTINGS[:config] = YAML.load_file(file_name)[env]
|
241
|
+
SETTINGS[:config]['env'] = env
|
242
|
+
rescue Exception => e
|
243
|
+
Lonline.warn_it("It couldn't setup lonline.")
|
244
|
+
Lonline.warn_it(e.message)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
#Copyright (c) 2016 Dynamicloud
|
2
|
+
#
|
3
|
+
#Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
#of this software and associated documentation files (the "Software"), to deal
|
5
|
+
#in the Software without restriction, including without limitation the rights
|
6
|
+
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
#copies of the Software, and to permit persons to whom the Software is
|
8
|
+
#furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
#The above copyright notice and this permission notice shall be included in all
|
11
|
+
#copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
#SOFTWARE.
|
20
|
+
#
|
21
|
+
# Lonline is a great tool to log your program into the cloud.
|
22
|
+
# This module provides methods to get the stored logs from your account in Dynamicloud.
|
23
|
+
#
|
24
|
+
# Lonline::Report executes queries provided from Dynamicloud library and will
|
25
|
+
# fetch until 100 records by default, if you want to increase this, set the number
|
26
|
+
# of records in report_limit (lonline.yml)
|
27
|
+
#
|
28
|
+
# Additionally, Lonline::Record provides a method to count how many logs were printed
|
29
|
+
# in a specific time.
|
30
|
+
#
|
31
|
+
# How to use:
|
32
|
+
#
|
33
|
+
# Lonline::Report.fetch(:error) do |report| # This call will fetch the error logs from now
|
34
|
+
# puts log[:text] # Log you have sent
|
35
|
+
# puts log[:trace] # Trace you have sent
|
36
|
+
# puts log[:when] # When this log was created
|
37
|
+
# puts report['additional'] #This could be an additional field you have sent
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# Lonline::Report.fetch(:fatal, Time.new.utc) do |report| # This call will fetch the fatal logs from 2 days ago
|
41
|
+
# puts log[:text] # Log you have sent
|
42
|
+
# puts log[:trace] # Trace you have sent
|
43
|
+
# puts log[:when] # When this log was created
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# Fetch how many logs were printed from Time.new.utc (Today)
|
47
|
+
#
|
48
|
+
# count = Lonline::Report.count(:fatal, Time.new.utc)
|
49
|
+
# puts count
|
50
|
+
|
51
|
+
require 'dynamic_api'
|
52
|
+
require 'dynamic_criteria'
|
53
|
+
|
54
|
+
module Lonline
|
55
|
+
# This module provides by default two methods fetch and count. If you want to add your own reports, just
|
56
|
+
# add the necessary methods to this module.
|
57
|
+
module Report
|
58
|
+
# This method counts the logs between a specific time according to 'from and to' params
|
59
|
+
#
|
60
|
+
# How to use:
|
61
|
+
#
|
62
|
+
# Fetch how many logs were printed from Time.new.utc (Today)
|
63
|
+
# count = Lonline::Report.count(:fatal, Time.new.utc)
|
64
|
+
# puts count
|
65
|
+
def self.count(level, from, to = Time.new.utc)
|
66
|
+
provider = get_provider
|
67
|
+
|
68
|
+
query = provider.create_query Lonline::SETUP::SETTINGS[:config]['model_identifier']
|
69
|
+
condition = Dynamicloud::API::Criteria::Conditions.and(Dynamicloud::API::Criteria::Conditions.equals('lonlinelevel', level.to_s),
|
70
|
+
Dynamicloud::API::Criteria::Conditions.between('added_at', from.strftime('%Y-%m-%d %T'),
|
71
|
+
to.strftime('%Y-%m-%d %T')))
|
72
|
+
|
73
|
+
results = query.add(condition).get_results(['count(*) as count'])
|
74
|
+
|
75
|
+
results.records[0]['count'].to_i
|
76
|
+
end
|
77
|
+
|
78
|
+
# This method fetches the logs according to level param and will be those created between from and to params.
|
79
|
+
# The results are decrease ordered by creation.
|
80
|
+
#
|
81
|
+
# How to use:
|
82
|
+
#
|
83
|
+
# Lonline::Report.fetch(:fatal, Time.new.utc - 2.days) do |report| # This call will fetch the fatal logs from 2 days ago (Rails app)
|
84
|
+
# puts log[:text] # Log you have sent
|
85
|
+
# puts log[:trace] # Trace you have sent
|
86
|
+
# puts log[:when] # When this log was created
|
87
|
+
# puts report['additional'] #This could be an additional field you have sent
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
# Lonline::Report.fetch(:fatal, Time.new.utc) do |report| # This call will fetch the fatal logs from today
|
91
|
+
# puts log[:text] # Log you have sent
|
92
|
+
# puts log[:trace] # Trace you have sent
|
93
|
+
# puts log[:when] # When this log was created
|
94
|
+
# end
|
95
|
+
def self.fetch(level, from, to = Time.new.utc, &block)
|
96
|
+
provider = get_provider
|
97
|
+
|
98
|
+
query = provider.create_query Lonline::SETUP::SETTINGS[:config]['model_identifier']
|
99
|
+
condition = Dynamicloud::API::Criteria::Conditions.and(Dynamicloud::API::Criteria::Conditions.equals('lonlinelevel', level.to_s),
|
100
|
+
Dynamicloud::API::Criteria::Conditions.between('added_at', from.strftime('%Y-%m-%d %T'),
|
101
|
+
to.strftime('%Y-%m-%d %T')))
|
102
|
+
results = query.order_by('id').desc.add(condition).get_results
|
103
|
+
|
104
|
+
handle_results(query, block, results, results.fast_returned_size)
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
# Returns the dynamicloud provider using the CSK and ACI provided from lonline.yml
|
109
|
+
def self.get_provider
|
110
|
+
Dynamicloud::API::DynamicProvider.new(
|
111
|
+
{
|
112
|
+
:csk => Lonline::SETUP::SETTINGS[:config]['csk'],
|
113
|
+
:aci => Lonline::SETUP::SETTINGS[:config]['aci']
|
114
|
+
})
|
115
|
+
end
|
116
|
+
|
117
|
+
# This method normalizes the records and will call the block passing the normalized record.
|
118
|
+
def self.handle_results(query, block, results, how_much_so_far)
|
119
|
+
results.records.each do |r|
|
120
|
+
block.call(normalize_record(r))
|
121
|
+
end
|
122
|
+
|
123
|
+
if how_much_so_far >= Lonline::SETUP::SETTINGS[:config]['report_limit'].to_i
|
124
|
+
return
|
125
|
+
end
|
126
|
+
|
127
|
+
# Dynamicloud provides the next method, this method automatically fetches the next set of logs.
|
128
|
+
results = query.next
|
129
|
+
|
130
|
+
if results.fast_returned_size > 0
|
131
|
+
handle_results(query, block, results, how_much_so_far + results.fast_returned_size)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# This method normalizes the record from Dynamicloud replacing the real field names to readable names
|
136
|
+
# For example: lonlinetext => text
|
137
|
+
# created_at => when
|
138
|
+
def self.normalize_record(log)
|
139
|
+
normalized = {
|
140
|
+
:level => log['lonlinelevel'],
|
141
|
+
:text => log['lonlinetext'],
|
142
|
+
:trace => log['lonlinetrace'],
|
143
|
+
:when => log['added_at']
|
144
|
+
}
|
145
|
+
|
146
|
+
log.each do |k, v|
|
147
|
+
unless k.eql?('lonlinelevel') || k.eql?('lonlinetext') ||
|
148
|
+
k.eql?('lonlinetrace') || k.eql?('added_at') ||
|
149
|
+
k.eql?('id') || k.eql?('owner_id') || k.eql?('model_id') ||
|
150
|
+
k.eql?('changed_at')
|
151
|
+
|
152
|
+
normalized[k.to_sym] = v
|
153
|
+
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
normalized
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lonline
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- lonline
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dynamicloud
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
description: "\n You will be able to execute the following operations:\n lonline.log.trace()
|
84
|
+
-\n lonline.log.debug() -\n lonline.log.info() -\n lonline.log.warn() -\n
|
85
|
+
\ lonline.log.error() -\n lonline.log.fatal() - Additionally, Lonline provides
|
86
|
+
methods to get report about your logs.\n "
|
87
|
+
email:
|
88
|
+
- support@dynamicloud.com
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- lib/generators/lonline_generator.rb
|
94
|
+
- lib/lonline.rb
|
95
|
+
- lib/lonline/version.rb
|
96
|
+
- lib/lonline_report.rb
|
97
|
+
homepage: https://rubygems.org/gems/lonline
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata:
|
101
|
+
allowed_push_host: https://rubygems.org
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.4.8
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: This gem allows you to log your program into the cloud.
|
122
|
+
test_files: []
|