logrithm 0.2.2 → 0.2.3
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 +4 -4
- data/lib/logrithm.rb +1 -0
- data/lib/logrithm/utils/airslack.rb +107 -0
- data/lib/logrithm/version.rb +1 -1
- data/logrithm.gemspec +1 -0
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19a6cbd393a80271537a01e19d935283dbb6a81b
|
4
|
+
data.tar.gz: 3705919f41dffebd5129156fcb4c3591c49067af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5f25429828c665325913a0834e3a5f924a242a2dd719321099c43ebc51d708db8b2fb1f4c8cc6f9ec249d7e35195bfea6ae96f017c28eceecaeefa985f5efe3
|
7
|
+
data.tar.gz: af291bd299bb3e7bc281a06175635302baf02711a436f0d0c18b76ccf486a727d18bc3a9f78b86d2ad97b0847862c07415881347c19185b72d1c67e477999ad9
|
data/lib/logrithm.rb
CHANGED
@@ -0,0 +1,107 @@
|
|
1
|
+
module Logrithm
|
2
|
+
module Utils
|
3
|
+
class Airslack
|
4
|
+
require 'slack-notifier'
|
5
|
+
|
6
|
+
SLACK_CHANNEL = Logrithm::Log.option :general, :slack, :channel
|
7
|
+
|
8
|
+
SETTINGS = {
|
9
|
+
dbg: { color: '#999999', preface: "Debugged error" },
|
10
|
+
wrn: { color: '#DD00DD', preface: "Expected error" },
|
11
|
+
err: { color: '#DD0000', preface: "Internal server error" },
|
12
|
+
ftl: { color: '#FF9900', preface: "Unexpected error" }
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
class << self
|
16
|
+
# rubocop:disable Metrics/MethodLength
|
17
|
+
# rubocop:disable Metrics/AbcSize
|
18
|
+
def notify(**params)
|
19
|
+
# {
|
20
|
+
# :cause => #<ZeroDivisionError: divided by 0>,
|
21
|
+
# :controller => Api::V1::CompaniesController < Api::V1::BaseController,
|
22
|
+
# :current_api_user => "#<ApiUser id: 2, login: \"api_user_1@kantox.com\", email: ...
|
23
|
+
# :current_company => "#<Profile id: 1, group_id: 1, company_name: \"usd\", elegible_for_matching: nil, ...
|
24
|
+
# :current_power_class => "Power",
|
25
|
+
# :hide_locale_switcher => "false",
|
26
|
+
# :message => "Error #200 :: “divided by 0”",
|
27
|
+
# :owner => Api::GetCompany < Mutations::Command,
|
28
|
+
# :sender => "Kantox::Herro::ReportedError",
|
29
|
+
# :wrap => #<Kantox::Herro::Reporter:0x000000057eed20 @cause=#<Kantox::Herro::ReportedError: Error #200 :: “divided by 0”>>
|
30
|
+
# }
|
31
|
+
|
32
|
+
# {
|
33
|
+
# "text": "New Help Ticket Received:",
|
34
|
+
# "attachments": [
|
35
|
+
# {
|
36
|
+
# "title": "App hangs on reboot",
|
37
|
+
# "title_link": "http://domain.com/ticket/123456",
|
38
|
+
# "text": "If I restart my computer without quitting your app, it stops the reboot sequence.\nhttp://domain.com/ticket/123456",
|
39
|
+
# }
|
40
|
+
# ]
|
41
|
+
# }
|
42
|
+
fields = params.reject do |k, _|
|
43
|
+
%i(type cause message owner sender wrap backtrace).include? k
|
44
|
+
end.map do |k, v|
|
45
|
+
value = case v
|
46
|
+
when String then [v.to_s[0...64]]
|
47
|
+
when Array then v.map(&:to_s)
|
48
|
+
when Hash
|
49
|
+
[
|
50
|
+
v[:id] ? "id=“#{v[:id]}”" : nil,
|
51
|
+
v[:reference] ? "ref=“#{v[:reference]}”" : nil,
|
52
|
+
v[:name] ? "name=“#{v[:name]}”" : nil
|
53
|
+
]
|
54
|
+
else
|
55
|
+
[
|
56
|
+
v.respond_to?(:id) ? "id=“#{v.id}”" : nil,
|
57
|
+
v.respond_to?(:reference) ? "ref=“#{v.reference}”" : nil,
|
58
|
+
v.respond_to?(:name) ? "name=“#{v.name}”" : nil
|
59
|
+
]
|
60
|
+
end.compact.join(', ')
|
61
|
+
|
62
|
+
value = v.to_s[0...64] if value.empty?
|
63
|
+
{ title: k, value: value, short: value.length <= 64 }
|
64
|
+
end
|
65
|
+
|
66
|
+
preface = SETTINGS[params[:type] || :ftl][:preface]
|
67
|
+
msg = "_#{preface}:_ #{params[:cause].try(:class)} | *#{params[:cause].try(:message)}*"
|
68
|
+
atts = [
|
69
|
+
{
|
70
|
+
fallback: "#{preface} in #{params[:owner] || '[see backtrace]'}",
|
71
|
+
color: SETTINGS[params[:type] || :ftl][:color],
|
72
|
+
title: "#{preface} in #{params[:owner] || '[see backtrace]'}",
|
73
|
+
fields: fields,
|
74
|
+
mrkdwn_in: [:text],
|
75
|
+
text: "```\n" << params[:cause].to_s << "\n```",
|
76
|
+
author_name: params[:owner].to_s
|
77
|
+
},
|
78
|
+
{
|
79
|
+
fallback: "Backtrace is available for desktop clients only",
|
80
|
+
color: '#DDDDDD',
|
81
|
+
title: "Backtrace (Rails.root related only)",
|
82
|
+
mrkdwn_in: [:text, :title],
|
83
|
+
text: "```\n" << params[:backtrace].map.with_index { |bt, i| bt =~ /#{Rails.root}/ ? "[#{i.to_s.rjust(3, '0')}] #{bt}" : nil }.compact.join($RS) << "\n```"
|
84
|
+
}
|
85
|
+
]
|
86
|
+
SLACK.ping msg, attachments: atts
|
87
|
+
rescue => e
|
88
|
+
Kantox::Rescuer.log_error(e).airbrake
|
89
|
+
end
|
90
|
+
# rubocop:enable Metrics/AbcSize
|
91
|
+
# rubocop:enable Metrics/MethodLength
|
92
|
+
|
93
|
+
def my_first_private_ipv4
|
94
|
+
ip_priv = Socket.ip_address_list.detect(&:ipv4_private?)
|
95
|
+
ip_priv && ip_priv.ip_address || 'Unknown server'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
SLACK = ::Slack::Notifier.new(
|
100
|
+
SLACK_CHANNEL[:endpoint],
|
101
|
+
channel: SLACK_CHANNEL[:channel],
|
102
|
+
icon_emoji: ':vertical_traffic_light:',
|
103
|
+
username: Airslack.my_first_private_ipv4
|
104
|
+
) if SLACK_CHANNEL.is_a?(Hash)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
data/lib/logrithm/version.rb
CHANGED
data/logrithm.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logrithm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksei Matiushkin
|
@@ -100,6 +100,20 @@ dependencies:
|
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: 0.7.5
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: slack-notifier
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.2'
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '1.2'
|
103
117
|
description: Some improvements to standard logger, such as detailed colored logger
|
104
118
|
messages etc.
|
105
119
|
email:
|
@@ -128,6 +142,7 @@ files:
|
|
128
142
|
- lib/logrithm/spitters.rb
|
129
143
|
- lib/logrithm/spitters/exception.rb
|
130
144
|
- lib/logrithm/spitters/string.rb
|
145
|
+
- lib/logrithm/utils/airslack.rb
|
131
146
|
- lib/logrithm/utils/color.rb
|
132
147
|
- lib/logrithm/utils/helpers.rb
|
133
148
|
- lib/logrithm/utils/output.rb
|