lamian 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c25553f88b3b5fc9b4a29a6e851f099e3c8384d
4
+ data.tar.gz: 033dbf2949a2b4a495311756fed3c4acbefceac3
5
+ SHA512:
6
+ metadata.gz: 037040f26b0fda2927d85b2351b7b944b7fa4b404fee7e4a9792bfaf039cffa44380d37e0297f98446fbbb000a9894c657a19ae161d87b6ea04ef54506f7df2b
7
+ data.tar.gz: 6155210a40ccbfb2764186d1fb36b2d96d73dcb9f09082ef95b75212fc8b79a71ca55f514a931039adcee36e587305ad188a10aef99345e300cd6657b9303ba0
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lamian
4
+ autoload :VERSION, 'lamian/version'
5
+ autoload :Config, 'lamian/config'
6
+ autoload :Logger, 'lamian/logger'
7
+ autoload :LoggerExtension, 'lamian/logger_extension'
8
+ autoload :Middleware, 'lamian/middleware'
9
+
10
+ require 'lamian/engine'
11
+
12
+ class << self
13
+ def configure
14
+ @config ||= Config.new
15
+ yield(@config) if block_given?
16
+ @config
17
+ end
18
+ alias config configure
19
+
20
+ def extend_logger(other_logger)
21
+ other_logger.extend(Lamian::LoggerExtension)
22
+ end
23
+
24
+ def logger
25
+ Lamian::Logger.current
26
+ end
27
+
28
+ def start(&block)
29
+ logger.start(&block)
30
+ end
31
+
32
+ def reset
33
+ logger.reset
34
+ end
35
+
36
+ def dump(*args, &block)
37
+ logger.dump(*args, &block)
38
+ end
39
+
40
+ def stop
41
+ logger.stop
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,9 @@
1
+ require 'logger'
2
+
3
+ module Lamian
4
+ Config = Struct.new(:formatter) do
5
+ def initialize
6
+ self.formatter = ::Logger::Formatter.new
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails'
2
+ require 'exception_notification'
3
+ require 'exception_notification/rails'
4
+
5
+ module Lamian
6
+ class Engine < ::Rails::Engine
7
+ config.app_middleware.insert_before(
8
+ ExceptionNotification::Rack,
9
+ ::Lamian::Middleware
10
+ )
11
+
12
+ paths['app/views'] << 'lib/lamian/rails_views'
13
+ end
14
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ module Lamian
6
+ class Logger < ::Logger
7
+ def self.current
8
+ Thread.current[:__lamian_logger] ||= new
9
+ end
10
+
11
+ def initialize(running = false)
12
+ self.running = running
13
+ self.level = 0
14
+ reset
15
+ end
16
+
17
+ def start
18
+ if block_given?
19
+ run_with_separate_logdev { yield }
20
+ else
21
+ reset
22
+ self.running = true
23
+ end
24
+ end
25
+
26
+ def reset
27
+ self.logdev = StringIO.new
28
+ end
29
+
30
+ def dump(format: nil)
31
+ result = block_given? ? run_with_separate_logdev { yield } : logdev.string.dup
32
+ format ? prepare_output(format, result) : result
33
+ end
34
+
35
+ def stop
36
+ self.running = false
37
+ dump
38
+ end
39
+
40
+ def add(*)
41
+ return unless running?
42
+ self.formatter = Lamian.config.formatter
43
+ super
44
+ end
45
+
46
+ private
47
+
48
+ def prepare_output(_format, text)
49
+ text.gsub!(/\[\d{1,2}m/, '')
50
+ text
51
+ end
52
+
53
+ attr_accessor :running, :logdev, :level, :formatter
54
+ alias running? running
55
+
56
+ def run_with_separate_logdev
57
+ old_logdev = logdev
58
+ old_running = running?
59
+ start
60
+ yield
61
+ stop
62
+ ensure
63
+ self.logdev = old_logdev
64
+ self.running = old_running
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ module Lamian
3
+ module LoggerExtension
4
+ def add(*args, &block)
5
+ Logger.current.add(*args, &block)
6
+ super
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module Lamian
2
+ class Middleware
3
+ def initialize(app)
4
+ self.app = app
5
+ end
6
+
7
+ def call(env)
8
+ result = []
9
+ Lamian.start { result = app.call(env) }
10
+ result
11
+ end
12
+
13
+ private
14
+
15
+ attr_accessor :app
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ <strong> Request log: <strong>
2
+ <pre> <%= Lamian.dump(format: :html) %> </pre>
@@ -0,0 +1 @@
1
+ <%= Lamian.dump(format: :txt) %>
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module Lamian
3
+ VERSION = '0.2.0'
4
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lamian
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - JelF
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-21 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: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: exception_notification
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.41'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.41'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.10'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.10'
111
+ description: Add logs to your error messages, using exception_notifier or smth like
112
+ it
113
+ email:
114
+ - begdory4+lamian@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - lib/lamian.rb
120
+ - lib/lamian/config.rb
121
+ - lib/lamian/engine.rb
122
+ - lib/lamian/logger.rb
123
+ - lib/lamian/logger_extension.rb
124
+ - lib/lamian/middleware.rb
125
+ - lib/lamian/rails_views/exception_notifier/_request_log.html.erb
126
+ - lib/lamian/rails_views/exception_notifier/_request_log.text.erb
127
+ - lib/lamian/version.rb
128
+ homepage: https://github.com/JelF/lamian
129
+ licenses: []
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.5.1
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Add logs to your error messages
151
+ test_files: []
152
+ has_rdoc: