lux-fw 0.5.36 → 0.6.2
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/bin/README.md +26 -13
- data/bin/cli/benchmark.rb +18 -0
- data/bin/cli/cerb.rb +90 -0
- data/bin/cli/config.rb +4 -11
- data/bin/cli/console.rb +72 -30
- data/bin/cli/eval.rb +5 -27
- data/bin/cli/generate.rb +9 -11
- data/bin/cli/get.rb +14 -6
- data/bin/cli/memory.rb +12 -0
- data/bin/cli/new.rb +2 -0
- data/bin/cli/secrets.rb +3 -31
- data/bin/cli/server.rb +28 -9
- data/bin/cli/stats.rb +26 -20
- data/bin/cli/template.rb +10 -0
- data/bin/generate_doc +168 -0
- data/bin/lux +73 -10
- data/lib/README.md +18 -8
- data/lib/common/crypt.rb +60 -9
- data/lib/common/string_base.rb +54 -15
- data/lib/common/struct_opts.rb +30 -0
- data/lib/common/time_difference.rb +75 -0
- data/lib/loader.rb +41 -0
- data/lib/lux/application/README.md +67 -105
- data/lib/lux/application/application.rb +87 -329
- data/lib/lux/application/lib/magic_routes.rb +22 -0
- data/lib/lux/application/lib/nav.rb +218 -99
- data/lib/lux/application/lib/render.rb +47 -67
- data/lib/lux/application/lib/routes.rb +242 -0
- data/lib/lux/application/lib/shared.rb +47 -0
- data/lib/lux/application/lux_adapter.rb +6 -0
- data/lib/lux/application/lux_config.rb +26 -0
- data/lib/lux/cache/Find Results +24 -0
- data/lib/lux/cache/README.md +28 -35
- data/lib/lux/cache/cache.rb +78 -26
- data/lib/lux/cache/lib/memcached_server.rb +36 -0
- data/lib/lux/cache/lib/memory_server.rb +44 -0
- data/lib/lux/cache/lib/null_server.rb +33 -0
- data/lib/lux/cache/lib/sqlite_server.rb +62 -0
- data/lib/lux/cache/lux_adapter.rb +19 -0
- data/lib/lux/config/config.rb +93 -144
- data/lib/lux/config/lux_adapter.rb +27 -0
- data/lib/lux/controller/README.md +67 -12
- data/lib/lux/controller/controller.rb +237 -187
- data/lib/lux/current/README.md +29 -10
- data/lib/lux/current/current.rb +166 -77
- data/lib/lux/current/lib/current.rb +6 -0
- data/lib/lux/current/lib/encrypt_params.rb +38 -36
- data/lib/lux/current/lib/session.rb +86 -65
- data/lib/lux/current/lux_adapter.rb +5 -0
- data/lib/lux/environment/README.md +24 -0
- data/lib/lux/environment/environment.rb +91 -0
- data/lib/lux/environment/lux_adapter.rb +13 -0
- data/lib/lux/error/README.md +18 -19
- data/lib/lux/error/error.rb +207 -152
- data/lib/lux/error/lux_adapter.rb +9 -0
- data/lib/lux/logger/README.md +45 -0
- data/lib/lux/logger/lux_adapter.rb +27 -0
- data/lib/lux/lux.rb +72 -129
- data/lib/lux/mailer/README.md +12 -5
- data/lib/lux/mailer/lux_config.rb +4 -0
- data/lib/lux/mailer/mailer.rb +81 -59
- data/lib/lux/plugin/README.md +19 -0
- data/lib/lux/plugin/lux_adapter.rb +8 -0
- data/lib/lux/plugin/plugin.rb +65 -0
- data/lib/lux/render/README.md +100 -0
- data/lib/lux/render/render.rb +12 -0
- data/lib/lux/response/README.md +57 -1
- data/lib/lux/response/lib/file.rb +87 -65
- data/lib/lux/response/lib/flash.rb +49 -34
- data/lib/lux/response/lib/header.rb +34 -33
- data/lib/lux/response/response.rb +252 -164
- data/lib/lux/template/helper.rb +130 -0
- data/lib/lux/template/inline_render_proxy.rb +31 -0
- data/lib/lux/template/lux_adapter.rb +5 -0
- data/lib/lux/template/template.rb +127 -0
- data/lib/lux-fw.rb +15 -33
- data/lib/overload/array.rb +33 -7
- data/lib/overload/blank.rb +8 -3
- data/lib/overload/boolean.rb +46 -0
- data/lib/overload/class.rb +28 -0
- data/lib/overload/dir.rb +117 -7
- data/lib/overload/file.rb +40 -5
- data/lib/overload/float.rb +38 -3
- data/lib/overload/hash.rb +81 -91
- data/lib/overload/integer.rb +15 -0
- data/lib/overload/json.rb +26 -0
- data/lib/overload/nil.rb +4 -8
- data/lib/overload/object.rb +91 -24
- data/lib/overload/pathname.rb +11 -0
- data/lib/overload/raise_variants.rb +26 -36
- data/lib/overload/string.rb +100 -27
- data/lib/overload/thread_simple.rb +100 -0
- data/lib/overload/time.rb +60 -38
- data/tasks/loader.rb +20 -7
- metadata +170 -169
- data/bin/.DS_Store +0 -0
- data/bin/build_gem +0 -77
- data/bin/cli/dbconsole.rb +0 -8
- data/bin/cli/routes.rb +0 -90
- data/lib/.DS_Store +0 -0
- data/lib/common/.DS_Store +0 -0
- data/lib/common/class_attributes.rb +0 -51
- data/lib/common/class_callbacks.rb +0 -47
- data/lib/common/free_struct.rb +0 -42
- data/lib/common/hash_with_indifferent_access.rb +0 -74
- data/lib/common/html_tag_builder.rb +0 -91
- data/lib/common/method_attr.rb +0 -69
- data/lib/common/url.rb +0 -191
- data/lib/lux/.DS_Store +0 -0
- data/lib/lux/README.md +0 -10
- data/lib/lux/cache/.DS_Store +0 -0
- data/lib/lux/cache/lib/memory.rb +0 -36
- data/lib/lux/cache/lib/null.rb +0 -21
- data/lib/lux/config/README.md +0 -63
- data/lib/lux/config/lib/plugin.rb +0 -65
- data/lib/lux/config/lib/secrets.rb +0 -48
- data/lib/lux/current/.DS_Store +0 -0
- data/lib/lux/delayed_job/.DS_Store +0 -0
- data/lib/lux/delayed_job/README.md +0 -3
- data/lib/lux/delayed_job/delayed_job.rb +0 -51
- data/lib/lux/delayed_job/lib/memory.rb +0 -16
- data/lib/lux/delayed_job/lib/nsq.rb +0 -3
- data/lib/lux/delayed_job/lib/postgre.rb +0 -6
- data/lib/lux/delayed_job/lib/redis.rb +0 -19
- data/lib/lux/event_bus/README.md +0 -36
- data/lib/lux/event_bus/event_bus.rb +0 -27
- data/lib/lux/view/README.md +0 -85
- data/lib/lux/view/cell.rb +0 -102
- data/lib/lux/view/helper.rb +0 -120
- data/lib/lux/view/lib/cell_helpers.rb +0 -29
- data/lib/lux/view/view.rb +0 -95
- data/lib/overload/it.rb +0 -29
- data/plugins/api/README.md +0 -49
- data/plugins/api/api.rb +0 -153
- data/plugins/api/lib/attr.rb +0 -31
- data/plugins/api/lib/dsl.rb +0 -52
- data/plugins/api/lib/error.rb +0 -3
- data/plugins/api/lib/model_api.rb +0 -203
- data/plugins/api/lib/response.rb +0 -85
- data/plugins/db/.DS_Store +0 -0
- data/plugins/db/README.md +0 -29
- data/plugins/db/auto_migrate/auto_migrate.rb +0 -268
- data/plugins/db/auto_migrate/db.rake +0 -15
- data/plugins/db/helpers/array_search.rb +0 -27
- data/plugins/db/helpers/before_save_filters.rb +0 -32
- data/plugins/db/helpers/composite_primary_keys.rb +0 -36
- data/plugins/db/helpers/core.rb +0 -94
- data/plugins/db/helpers/dataset_methods.rb +0 -138
- data/plugins/db/helpers/enums_plugin.rb +0 -52
- data/plugins/db/helpers/find_precache.rb +0 -31
- data/plugins/db/helpers/link_objects.rb +0 -84
- data/plugins/db/helpers/schema_checks.rb +0 -83
- data/plugins/db/helpers/typero_adapter.rb +0 -71
- data/plugins/db/logger/config.rb +0 -22
- data/plugins/db/logger/lux_response_adapter.rb +0 -10
- data/plugins/db/paginate/helper.rb +0 -32
- data/plugins/db/paginate/sequel_adapter.rb +0 -23
- data/plugins/exceptions/exceptions.rake +0 -43
- data/plugins/exceptions/simple_exception.rb +0 -64
- data/plugins/favicon/favicon.rb +0 -10
- data/plugins/html/README.md +0 -3
- data/plugins/html/html_form.rb +0 -118
- data/plugins/html/html_input.rb +0 -98
- data/plugins/html/html_menu.rb +0 -79
- data/plugins/html/input_types.rb +0 -346
- data/plugins/js_widgets/README.md +0 -5
- data/plugins/js_widgets/js/html_tag.coffee +0 -42
- data/plugins/js_widgets/js/widgets.coffee +0 -161
- data/plugins/js_widgets/js_widgets.rb +0 -15
- data/plugins/oauth/lib/facebook.rb +0 -35
- data/plugins/oauth/lib/github.rb +0 -38
- data/plugins/oauth/lib/google.rb +0 -41
- data/plugins/oauth/lib/linkedin.rb +0 -41
- data/plugins/oauth/lib/stackexchange.rb +0 -41
- data/plugins/oauth/lib/twitter.rb +0 -38
- data/plugins/oauth/oauth.rb +0 -42
- data/plugins/policy/policy.rb +0 -53
- data/tasks/nginx.rake +0 -23
- /data/lib/lux/{view/lib → mailer}/helper_modules.rb +0 -0
data/lib/lux/error/README.md
CHANGED
@@ -1,41 +1,40 @@
|
|
1
|
-
## Lux::
|
1
|
+
## Lux.error (Lux::Error)
|
2
2
|
|
3
|
-
|
3
|
+
Error handling module.
|
4
4
|
|
5
5
|
```ruby
|
6
|
-
|
7
|
-
|
6
|
+
# try to execute part of the code, log exeception if fails
|
7
|
+
Lux.error.try(name, &block)
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
# HTML render style for default Lux error
|
10
|
+
Lux.error.render(desc)
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
# show error page
|
13
|
+
Lux.error.show(desc)
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
# show inline error
|
16
|
+
Lux.error.inline(name=nil, error_object=nil)
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
# log exeption via Lux.config.log_exception_via method
|
19
|
+
Lux.error.log(error_object)
|
20
20
|
```
|
21
21
|
|
22
22
|
|
23
|
-
|
23
|
+
#### defines standard Lux errors and error generating helpers
|
24
24
|
|
25
25
|
```ruby
|
26
26
|
# 400: for bad parameter request or similar
|
27
|
-
Lux
|
27
|
+
Lux.error.forbidden foo
|
28
28
|
|
29
29
|
# 401: for unauthorized access
|
30
|
-
Lux
|
30
|
+
Lux.error.forbidden foo
|
31
31
|
|
32
32
|
# 403: for unalloed access
|
33
|
-
Lux
|
33
|
+
Lux.error.forbidden foo
|
34
34
|
|
35
35
|
# 404: for not found pages
|
36
|
-
Lux
|
36
|
+
Lux.error.not_found foo
|
37
37
|
|
38
38
|
# 503: for too many requests at the same time
|
39
|
-
Lux
|
40
|
-
|
39
|
+
Lux.error.forbidden foo
|
41
40
|
```
|
data/lib/lux/error/error.rb
CHANGED
@@ -10,184 +10,239 @@
|
|
10
10
|
# e = Lux::Error.not_found('foo')
|
11
11
|
# e.code => 404
|
12
12
|
# e.message => foo
|
13
|
-
|
14
|
-
class
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
# https://httpstatuses.com/
|
19
|
-
CODE_LIST ||= {
|
20
|
-
# 1×× Informational
|
21
|
-
100 => { name: 'Continue' },
|
22
|
-
101 => { name: 'Switching Protocols' },
|
23
|
-
102 => { name: 'Processing' },
|
24
|
-
|
25
|
-
# 2×× Success
|
26
|
-
200 => { name: 'OK' },
|
27
|
-
201 => { name: 'Created' },
|
28
|
-
202 => { name: 'Accepted' },
|
29
|
-
203 => { name: 'Non-authoritative Information' },
|
30
|
-
204 => { name: 'No Content' },
|
31
|
-
205 => { name: 'Reset Content' },
|
32
|
-
206 => { name: 'Partial Content' },
|
33
|
-
207 => { name: 'Multi-Status' },
|
34
|
-
208 => { name: 'Already Reported' },
|
35
|
-
226 => { name: 'IM Used' },
|
36
|
-
|
37
|
-
# 3×× Redirection
|
38
|
-
300 => { name: 'Multiple Choices' },
|
39
|
-
301 => { name: 'Moved Permanently' },
|
40
|
-
302 => { name: 'Found' },
|
41
|
-
303 => { name: 'See Other' },
|
42
|
-
304 => { name: 'Not Modified' },
|
43
|
-
305 => { name: 'Use Proxy' },
|
44
|
-
307 => { name: 'Temporary Redirect' },
|
45
|
-
308 => { name: 'Permanent Redirect' },
|
46
|
-
|
47
|
-
# 4×× Client Error
|
48
|
-
400 => { name: 'Bad Request', code: :bad_request },
|
49
|
-
401 => { name: 'Unauthorized', code: :unauthorized },
|
50
|
-
402 => { name: 'Payment Required', code: :payment_required },
|
51
|
-
403 => { name: 'Forbidden', code: :forbidden },
|
52
|
-
404 => { name: 'Document Not Found', code: :not_found },
|
53
|
-
405 => { name: 'Method Not Allowed', code: :method_not_allowed },
|
54
|
-
406 => { name: 'Not Acceptable', code: :not_acceptable },
|
55
|
-
407 => { name: 'Proxy Authentication Required' },
|
56
|
-
408 => { name: 'Request Timeout' },
|
57
|
-
409 => { name: 'Conflict' },
|
58
|
-
410 => { name: 'Gone' },
|
59
|
-
411 => { name: 'Length Required' },
|
60
|
-
412 => { name: 'Precondition Failed' },
|
61
|
-
413 => { name: 'Payload Too Large' },
|
62
|
-
414 => { name: 'Request-URI Too Long' },
|
63
|
-
415 => { name: 'Unsupported Media Type' },
|
64
|
-
416 => { name: 'Requested Range Not Satisfiable' },
|
65
|
-
417 => { name: 'Expectation Failed' },
|
66
|
-
418 => { name: 'I\'m a teapot' },
|
67
|
-
421 => { name: 'Misdirected Request' },
|
68
|
-
422 => { name: 'Unprocessable Entity' },
|
69
|
-
423 => { name: 'Locked' },
|
70
|
-
424 => { name: 'Failed Dependency' },
|
71
|
-
426 => { name: 'Upgrade Required' },
|
72
|
-
428 => { name: 'Precondition Required' },
|
73
|
-
429 => { name: 'Too Many Requests' },
|
74
|
-
431 => { name: 'Request Header Fields Too Large' },
|
75
|
-
444 => { name: 'Connection Closed Without Response' },
|
76
|
-
451 => { name: 'Unavailable For Legal Reasons' },
|
77
|
-
499 => { name: 'Client Closed Request' },
|
78
|
-
|
79
|
-
# 5×× Server Error
|
80
|
-
500 => { name: 'Internal Server Error', code: :internal_server_error },
|
81
|
-
501 => { name: 'Not Implemented', code: :not_implemented },
|
82
|
-
502 => { name: 'Bad Gateway' },
|
83
|
-
503 => { name: 'Service Unavailable' },
|
84
|
-
504 => { name: 'Gateway Timeout' },
|
85
|
-
505 => { name: 'HTTP Version Not Supported' },
|
86
|
-
506 => { name: 'Variant Also Negotiates' },
|
87
|
-
507 => { name: 'Insufficient Storage' },
|
88
|
-
508 => { name: 'Loop Detected' },
|
89
|
-
510 => { name: 'Not Extended' },
|
90
|
-
511 => { name: 'Network Authentication Required' },
|
91
|
-
599 => { name: 'Network Connect Timeout Error' },
|
92
|
-
}
|
93
|
-
|
94
|
-
# e = Lux::Error.not_found('foo')
|
95
|
-
CODE_LIST.each do |status, data|
|
96
|
-
if data[:code]
|
97
|
-
define_singleton_method(data[:code]) do |message=nil|
|
98
|
-
error = new status, message
|
99
|
-
raise error if Lux::Error::AutoRaise === error
|
100
|
-
error
|
101
|
-
end
|
13
|
+
module Lux
|
14
|
+
class Error < StandardError
|
15
|
+
class AutoRaise < Lux::Error
|
102
16
|
end
|
103
|
-
end
|
104
17
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
18
|
+
# https://httpstatuses.com/
|
19
|
+
CODE_LIST ||= {
|
20
|
+
# 1×× Informational
|
21
|
+
100 => { name: 'Continue' },
|
22
|
+
101 => { name: 'Switching Protocols' },
|
23
|
+
102 => { name: 'Processing' },
|
24
|
+
|
25
|
+
# 2×× Success
|
26
|
+
200 => { name: 'OK' },
|
27
|
+
201 => { name: 'Created' },
|
28
|
+
202 => { name: 'Accepted' },
|
29
|
+
203 => { name: 'Non-authoritative Information' },
|
30
|
+
204 => { name: 'No Content' },
|
31
|
+
205 => { name: 'Reset Content' },
|
32
|
+
206 => { name: 'Partial Content' },
|
33
|
+
207 => { name: 'Multi-Status' },
|
34
|
+
208 => { name: 'Already Reported' },
|
35
|
+
226 => { name: 'IM Used' },
|
36
|
+
|
37
|
+
# 3×× Redirection
|
38
|
+
300 => { name: 'Multiple Choices' },
|
39
|
+
301 => { name: 'Moved Permanently' },
|
40
|
+
302 => { name: 'Found' },
|
41
|
+
303 => { name: 'See Other' },
|
42
|
+
304 => { name: 'Not Modified' },
|
43
|
+
305 => { name: 'Use Proxy' },
|
44
|
+
307 => { name: 'Temporary Redirect' },
|
45
|
+
308 => { name: 'Permanent Redirect' },
|
46
|
+
|
47
|
+
# 4×× Client Error
|
48
|
+
400 => { name: 'Bad Request', short: :bad_request },
|
49
|
+
401 => { name: 'Unauthorized', short: :unauthorized },
|
50
|
+
402 => { name: 'Payment Required', short: :payment_required },
|
51
|
+
403 => { name: 'Forbidden', short: :forbidden },
|
52
|
+
404 => { name: 'Document Not Found', short: :not_found },
|
53
|
+
405 => { name: 'Method Not Allowed', short: :method_not_allowed },
|
54
|
+
406 => { name: 'Not Acceptable', short: :not_acceptable },
|
55
|
+
407 => { name: 'Proxy Authentication Required' },
|
56
|
+
408 => { name: 'Request Timeout' },
|
57
|
+
409 => { name: 'Conflict' },
|
58
|
+
410 => { name: 'Gone' },
|
59
|
+
411 => { name: 'Length Required' },
|
60
|
+
412 => { name: 'Precondition Failed' },
|
61
|
+
413 => { name: 'Payload Too Large' },
|
62
|
+
414 => { name: 'Request-URI Too Long' },
|
63
|
+
415 => { name: 'Unsupported Media Type' },
|
64
|
+
416 => { name: 'Requested Range Not Satisfiable' },
|
65
|
+
417 => { name: 'Expectation Failed' },
|
66
|
+
418 => { name: 'I\'m a teapot' },
|
67
|
+
421 => { name: 'Misdirected Request' },
|
68
|
+
422 => { name: 'Unprocessable Entity' },
|
69
|
+
423 => { name: 'Locked' },
|
70
|
+
424 => { name: 'Failed Dependency' },
|
71
|
+
426 => { name: 'Upgrade Required' },
|
72
|
+
428 => { name: 'Precondition Required' },
|
73
|
+
429 => { name: 'Too Many Requests' },
|
74
|
+
431 => { name: 'Request Header Fields Too Large' },
|
75
|
+
444 => { name: 'Connection Closed Without Response' },
|
76
|
+
451 => { name: 'Unavailable For Legal Reasons' },
|
77
|
+
499 => { name: 'Client Closed Request' },
|
78
|
+
|
79
|
+
# 5×× Server Error
|
80
|
+
500 => { name: 'Internal Server Error', short: :internal_server_error },
|
81
|
+
501 => { name: 'Not Implemented', short: :not_implemented },
|
82
|
+
502 => { name: 'Bad Gateway' },
|
83
|
+
503 => { name: 'Service Unavailable' },
|
84
|
+
504 => { name: 'Gateway Timeout' },
|
85
|
+
505 => { name: 'HTTP Version Not Supported' },
|
86
|
+
506 => { name: 'Variant Also Negotiates' },
|
87
|
+
507 => { name: 'Insufficient Storage' },
|
88
|
+
508 => { name: 'Loop Detected' },
|
89
|
+
510 => { name: 'Not Extended' },
|
90
|
+
511 => { name: 'Network Authentication Required' },
|
91
|
+
599 => { name: 'Network Connect Timeout Error' },
|
92
|
+
}
|
93
|
+
|
94
|
+
# e = Lux::Error.not_found('foo')
|
95
|
+
CODE_LIST.each do |status, data|
|
96
|
+
if data[:short]
|
97
|
+
define_singleton_method(data[:short]) do |message=nil|
|
98
|
+
error = Lux::Error.new status, message
|
99
|
+
|
100
|
+
if self == Lux::Error::AutoRaise
|
101
|
+
Lux.current.response.status status
|
102
|
+
Lux.log " error.#{data[:code]} in #{Lux.app_caller}"
|
103
|
+
raise error
|
104
|
+
end
|
105
|
+
|
106
|
+
error
|
107
|
+
end
|
108
|
+
end
|
111
109
|
end
|
112
110
|
|
113
|
-
|
114
|
-
|
115
|
-
|
111
|
+
class << self
|
112
|
+
# template to show full error page
|
113
|
+
def render error
|
114
|
+
error = StandardError.new(error) if error.is_a?(String)
|
115
|
+
|
116
|
+
code = error.respond_to?(:code) ? error.code : 500
|
117
|
+
Lux.current.response.status code
|
118
|
+
|
119
|
+
Lux.current.response.body(
|
120
|
+
HtmlTag.html do |n|
|
121
|
+
n.head do |n|
|
122
|
+
n.title 'Lux error'
|
123
|
+
end
|
124
|
+
n.body style: "margin: 20px 20px 20px 140px; background-color:#fdd; font-size: 14pt; font-family: sans-serif;" do |n|
|
125
|
+
n.img src: "https://i.imgur.com/Zy7DLXU.png", style: "width: 100px; position: absolute; margin-left: -120px;"
|
126
|
+
n.h4 do |n|
|
127
|
+
n.push %[HTTP Error — <a href="https://httpstatuses.com/#{code}" target="http_error">#{code}</a>]
|
128
|
+
n.push %[ ‐ #{error.name}] if error.respond_to?(:name)
|
129
|
+
end
|
130
|
+
n.push inline error
|
131
|
+
end
|
132
|
+
end
|
133
|
+
)
|
134
|
+
end
|
116
135
|
|
117
|
-
|
118
|
-
|
119
|
-
|
136
|
+
# render error inline
|
137
|
+
def inline object, msg = nil
|
138
|
+
error, message = if object.is_a?(String)
|
139
|
+
[nil, object]
|
140
|
+
else
|
141
|
+
[object, object.message]
|
142
|
+
end
|
143
|
+
|
144
|
+
error_key = error ? log(error) : nil
|
145
|
+
message = message.to_s.gsub('","',%[",\n "]).gsub('<','<')
|
146
|
+
|
147
|
+
HtmlTag.pre(class: 'lux-inline-error', style: 'background: #fff; margin-top: 10px; padding: 10px; font-size: 14px; border: 2px solid #600; line-height: 20px;') do |n|
|
148
|
+
n.h3 '%s : %s' % [error.class, message]
|
149
|
+
n.p msg if msg
|
150
|
+
n.p 'Key: %s' % error_key if error_key
|
151
|
+
n.p 'Description: %s' % error.description if error && error.respond_to?(:description) && error.description
|
152
|
+
|
153
|
+
if error && Lux.env.show_errors?
|
154
|
+
n.hr
|
155
|
+
n.push mark_backtrace(error, html: true).join("\n")
|
156
|
+
end
|
157
|
+
end
|
120
158
|
end
|
121
159
|
|
122
|
-
|
123
|
-
|
160
|
+
# clear osx screen :)
|
161
|
+
def clear_screen time = 0
|
162
|
+
last = (Thread.current[:_lux_clear_screen] ||= 1.day.ago)
|
163
|
+
if last < Time.now - time
|
164
|
+
Thread.current[:_lux_clear_screen] = Time.now
|
165
|
+
print "\e[H\e[2J\e[3J"
|
166
|
+
end
|
167
|
+
end
|
124
168
|
|
125
|
-
|
169
|
+
# prepare backtrace for better render
|
170
|
+
def split_backtrace error
|
171
|
+
# split app log rest of the log
|
172
|
+
dmp = [[error.class, error.message], [], []]
|
126
173
|
|
127
|
-
|
174
|
+
root = Lux.root.to_s
|
128
175
|
|
129
|
-
|
176
|
+
(error.backtrace || caller).each do |line|
|
177
|
+
line = line.sub(root, '.')
|
178
|
+
dmp[line[0,1] == '.' ? 1 : 2].push line
|
179
|
+
end
|
130
180
|
|
131
|
-
|
132
|
-
|
133
|
-
<b style="font-size:110%;">#{name}</b>
|
181
|
+
dmp
|
182
|
+
end
|
134
183
|
|
135
|
-
|
184
|
+
def mark_backtrace error, html: false
|
185
|
+
return ['no backtrace present'] unless error && error.backtrace
|
136
186
|
|
137
|
-
|
187
|
+
root = Lux.root.to_s
|
138
188
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
189
|
+
error
|
190
|
+
.backtrace
|
191
|
+
.map do |line|
|
192
|
+
path = line.split(':in').first
|
193
|
+
path = path.sub(/^\.\//, root+'/')
|
194
|
+
|
195
|
+
edit = html ? %[ • <a href="subl://open?url=file:/#{path}">edit</a>] : ''
|
196
|
+
line = line.sub(root, '.')
|
197
|
+
(line[0,1] != '/' ? (html ? line.tag(:b) : line) : line) + edit
|
198
|
+
end
|
199
|
+
end
|
143
200
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
201
|
+
# show in stdout
|
202
|
+
def screen error
|
203
|
+
return unless Lux.env.show_errors?
|
204
|
+
|
205
|
+
data = split_backtrace(error)
|
206
|
+
if error.class == Lux::Error
|
207
|
+
Lux.info "Lux error: #{error.message} (#{error.code}) - #{data[1][0]}"
|
208
|
+
else
|
209
|
+
data[2] = data[2][0,5]
|
210
|
+
ap data
|
211
|
+
end
|
212
|
+
end
|
149
213
|
|
150
|
-
|
151
|
-
|
214
|
+
def log err
|
215
|
+
if Lux.config.error_logger
|
216
|
+
Lux.config.error_logger.call err
|
217
|
+
end
|
218
|
+
end
|
152
219
|
end
|
153
220
|
|
154
|
-
|
155
|
-
# split app log rest of the log
|
156
|
-
dmp = [[], []]
|
221
|
+
###
|
157
222
|
|
158
|
-
|
223
|
+
attr_accessor :message
|
159
224
|
|
160
|
-
|
161
|
-
|
162
|
-
|
225
|
+
def initialize *args
|
226
|
+
if args.first.is_a?(Integer)
|
227
|
+
self.code = args.shift
|
163
228
|
end
|
164
229
|
|
165
|
-
|
230
|
+
self.message = args.shift || name
|
166
231
|
end
|
167
|
-
end
|
168
|
-
|
169
|
-
###
|
170
|
-
|
171
|
-
attr_accessor :message
|
172
|
-
|
173
|
-
def initialize code_num, message=nil
|
174
|
-
self.code = code_num
|
175
|
-
@message = message || CODE_LIST[code_num][:name]
|
176
|
-
end
|
177
232
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
233
|
+
def code
|
234
|
+
# 400 is a default
|
235
|
+
@code || 400
|
236
|
+
end
|
182
237
|
|
183
|
-
|
184
|
-
|
238
|
+
def name
|
239
|
+
CODE_LIST[code][:name]
|
240
|
+
end
|
185
241
|
|
186
|
-
|
187
|
-
|
242
|
+
def code= num
|
243
|
+
@code = num.to_i
|
188
244
|
|
189
|
-
|
190
|
-
|
245
|
+
raise 'Status code %s not found' % @code unless CODE_LIST[@code]
|
246
|
+
end
|
191
247
|
end
|
192
248
|
end
|
193
|
-
|
@@ -0,0 +1,45 @@
|
|
1
|
+
## Lux.logger
|
2
|
+
|
3
|
+
Lux logger is logging helper module.
|
4
|
+
|
5
|
+
It has 2 basic methods, get pointer to a logger `Lux.logger(:name).info msg` and log to screen `Lux.log msg`
|
6
|
+
|
7
|
+
Uses default [Ruby logger](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html)
|
8
|
+
|
9
|
+
### Options
|
10
|
+
|
11
|
+
#### Lux.config.logger_path_mask
|
12
|
+
|
13
|
+
Defaults to `./log/%s.log`.
|
14
|
+
|
15
|
+
#### Lux.config.logger_formatter
|
16
|
+
|
17
|
+
If defined it will be assigned to all logs created by `Lux#logger`
|
18
|
+
|
19
|
+
#### Lux.config.logger_default
|
20
|
+
|
21
|
+
Default system logger output location called via `Lux#log`.
|
22
|
+
|
23
|
+
Defauls to `STDOUT` in development and `nil` in production (no render output log)
|
24
|
+
|
25
|
+
#### Lux.config.logger_files_to_keep = 3
|
26
|
+
|
27
|
+
By default keep 3 log files
|
28
|
+
|
29
|
+
#### Lux.config.logger_file_max_size = 10_240_000
|
30
|
+
|
31
|
+
10 MB per file log file
|
32
|
+
|
33
|
+
### Defaults and example
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
# defaults
|
37
|
+
Lux.config.logger_path_mask = './tmp/%s.log'
|
38
|
+
Lux.config.logger_default = Lux.env.dev? ? STDOUT : nil
|
39
|
+
Lux.config.logger_files_to_keep = 3
|
40
|
+
Lux.config.logger_file_max_size = 10_240_000
|
41
|
+
|
42
|
+
# example
|
43
|
+
# by default writes in ./log/%s.log, log rotation 3 files, 10 MB each.
|
44
|
+
Lux.logger(:foo).info 'hello'
|
45
|
+
```
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Lux
|
4
|
+
LOGGER_CACHE ||= {}
|
5
|
+
|
6
|
+
# Lux.logger(:foo).warn 'bar'
|
7
|
+
def logger name = nil
|
8
|
+
raise "Logger name is required" unless name
|
9
|
+
|
10
|
+
LOGGER_CACHE[name] ||= begin
|
11
|
+
output_location = Lux.config.logger_path_mask % name
|
12
|
+
LOGGER_CACHE[name] = Logger.new output_location, Lux.config.logger_files_to_keep, Lux.config.logger_file_max_size
|
13
|
+
|
14
|
+
if Lux.config.logger_formatter
|
15
|
+
LOGGER_CACHE[name].formatter = Lux.config.logger_formatter
|
16
|
+
end
|
17
|
+
LOGGER_CACHE[name]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def log what = nil, &block
|
22
|
+
return unless Lux.env.screen_log?
|
23
|
+
# return if Lux.current.nav.format && !Lux.current.no_cache?
|
24
|
+
what = block.call if block
|
25
|
+
print what.to_s + "\n" if what
|
26
|
+
end
|
27
|
+
end
|