lamian 0.3.3 → 1.0.0alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lamian.rb +30 -6
- data/lib/lamian/config.rb +5 -1
- data/lib/lamian/engine.rb +10 -5
- data/lib/lamian/logger.rb +41 -4
- data/lib/lamian/logger_extension.rb +11 -0
- data/lib/lamian/middleware.rb +7 -0
- data/lib/lamian/version.rb +14 -1
- metadata +52 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce288b47c40d6a1f17839187b23d82035175c4af
|
4
|
+
data.tar.gz: fbc768abd2f211ba6a4ad617aa3ea74c5876a26a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '027578767295a91366fca4de695f6de44111fdce461fece1ad13fe0fb187dcaaff172988bc42dd57c60036c41f2122e861d1a153947f8a75b8a67a2185675f3c'
|
7
|
+
data.tar.gz: 3e577960fe820800fe8f2925eec5e2733b94a02c3571a7d50ed909dec45e5f44c41628928057328778c27b85f31b8a91590417451f26bfc89d91057a4ac96390
|
data/lib/lamian.rb
CHANGED
@@ -1,15 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Lamian is an in-memory logger, which content could be released
|
4
|
+
# for error messages.
|
5
|
+
# It is designed to work in pair with `exception_notification` gem inside
|
6
|
+
# rails aplications
|
3
7
|
module Lamian
|
4
|
-
autoload :VERSION,
|
5
|
-
autoload :Config,
|
6
|
-
autoload :Logger,
|
7
|
-
autoload :LoggerExtension,
|
8
|
-
autoload :Middleware,
|
8
|
+
autoload :VERSION, "lamian/version"
|
9
|
+
autoload :Config, "lamian/config"
|
10
|
+
autoload :Logger, "lamian/logger"
|
11
|
+
autoload :LoggerExtension, "lamian/logger_extension"
|
12
|
+
autoload :Middleware, "lamian/middleware"
|
9
13
|
|
10
|
-
require
|
14
|
+
require "lamian/engine"
|
11
15
|
|
12
16
|
class << self
|
17
|
+
# Yields curent configuration if block given
|
18
|
+
# @example
|
19
|
+
# Lamian.configure do |config|
|
20
|
+
# config.formatter = MyFormatter.new
|
21
|
+
# end
|
22
|
+
# @yield [config] current configuration
|
23
|
+
# @yieldparam config [Lamian::Config]
|
24
|
+
# @return [Lamian::Config] current configuration
|
13
25
|
def configure
|
14
26
|
@config ||= Config.new
|
15
27
|
yield(@config) if block_given?
|
@@ -17,18 +29,30 @@ module Lamian
|
|
17
29
|
end
|
18
30
|
alias config configure
|
19
31
|
|
32
|
+
# Extends logger instance to tee it's output to Lamian logger
|
33
|
+
# @param other_logger [Logger] logger to extend
|
20
34
|
def extend_logger(other_logger)
|
21
35
|
other_logger.extend(Lamian::LoggerExtension)
|
22
36
|
end
|
23
37
|
|
38
|
+
# @api private
|
39
|
+
# Gives access to current logger
|
40
|
+
# @return [Lamian::Logger] current logger
|
24
41
|
def logger
|
25
42
|
Lamian::Logger.current
|
26
43
|
end
|
27
44
|
|
45
|
+
# Collects logs sent inside block
|
28
46
|
def run
|
29
47
|
logger.run { yield }
|
30
48
|
end
|
31
49
|
|
50
|
+
# Dumps log collected in this run
|
51
|
+
# @option format [Symbol]
|
52
|
+
# requested format of log. At this point, returns raw log if falsey
|
53
|
+
# or log without controll sequences (such as '[23m') if truthy
|
54
|
+
# value given (for now)
|
55
|
+
# @return formatted log (String by default)
|
32
56
|
def dump(format: nil)
|
33
57
|
logger.dump(format: format)
|
34
58
|
end
|
data/lib/lamian/config.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require "logger"
|
3
4
|
|
4
5
|
module Lamian
|
6
|
+
# General lamian configuration class
|
7
|
+
# @attr formatter [Logger::Foramtter]
|
8
|
+
# formatter to use in lamian, global
|
5
9
|
Config = Struct.new(:formatter) do
|
6
10
|
def initialize
|
7
11
|
self.formatter = ::Logger::Formatter.new
|
data/lib/lamian/engine.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
2
|
+
|
3
|
+
require "rails"
|
4
|
+
require "exception_notification"
|
5
|
+
require "exception_notification/rails"
|
5
6
|
|
6
7
|
module Lamian
|
8
|
+
# Rails engine, which injects middleware and appends
|
9
|
+
# lamian views to rails library.
|
10
|
+
# Lamian views are used in exception_notifier to provide
|
11
|
+
# request_log section
|
7
12
|
class Engine < ::Rails::Engine
|
8
13
|
config.app_middleware.insert_before(
|
9
14
|
ExceptionNotification::Rack,
|
10
|
-
::Lamian::Middleware
|
15
|
+
::Lamian::Middleware,
|
11
16
|
)
|
12
17
|
|
13
|
-
paths[
|
18
|
+
paths["app/views"] << "lib/lamian/rails_views"
|
14
19
|
end
|
15
20
|
end
|
data/lib/lamian/logger.rb
CHANGED
@@ -1,9 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "logger"
|
4
4
|
|
5
5
|
module Lamian
|
6
|
+
# @api private
|
7
|
+
# Provides thread-local loggers to catch teed messages from
|
8
|
+
# regular loggers.
|
9
|
+
# Uses :__lamian_logger thread variable
|
10
|
+
# @attr level [Int]
|
11
|
+
# current log level, implicitly set to zero
|
12
|
+
# @attr logdevs [Array(StringIO)]
|
13
|
+
# stack of log devices used to store logs
|
14
|
+
# @attr formatter [Logger::Formatter]
|
15
|
+
# formatter, inherited from Lamian.config
|
6
16
|
class Logger < ::Logger
|
17
|
+
# Provides access to logger bound to curent thread
|
18
|
+
# @return [Lamian::Logger] current logger
|
7
19
|
def self.current
|
8
20
|
Thread.current[:__lamian_logger] ||= new
|
9
21
|
end
|
@@ -14,6 +26,8 @@ module Lamian
|
|
14
26
|
self.formatter = Lamian.config.formatter
|
15
27
|
end
|
16
28
|
|
29
|
+
# @see Lamian.run
|
30
|
+
# Collects logs sent inside block
|
17
31
|
def run
|
18
32
|
push_logdev(StringIO.new)
|
19
33
|
yield
|
@@ -21,10 +35,19 @@ module Lamian
|
|
21
35
|
pop_logdev
|
22
36
|
end
|
23
37
|
|
38
|
+
# Part of Logger api, entry point for all logs
|
39
|
+
# extened to run on each log device in stack
|
24
40
|
def add(*args, &block)
|
25
41
|
each_logdev { super(*args, &block) }
|
26
42
|
end
|
27
43
|
|
44
|
+
# @see Lamian.dump
|
45
|
+
# Dumps log collected in this run
|
46
|
+
# @option format [Symbol]
|
47
|
+
# requested format of log. At this point, returns raw log if falsey
|
48
|
+
# or log without controll sequences (such as '[23m') if truthy
|
49
|
+
# value given (for now)
|
50
|
+
# @return formatted log (String by default)
|
28
51
|
def dump(format: nil)
|
29
52
|
result = logdevs[-1]&.string&.dup
|
30
53
|
apply_format!(format, result)
|
@@ -35,20 +58,34 @@ module Lamian
|
|
35
58
|
|
36
59
|
attr_accessor :level, :logdevs, :formatter
|
37
60
|
|
38
|
-
|
61
|
+
# Formats string using given format
|
62
|
+
# @todo create `formatters` interface to allow real format selection
|
63
|
+
# @note
|
64
|
+
# `format` is now checked only for thruthyness. Please, use
|
65
|
+
# `:text` format to keep it same after `formatters` interface integration
|
66
|
+
# @param format [Symbol] requested format, e.g. `:text`
|
67
|
+
# @param string [String] string to be changed
|
68
|
+
# @return avoid return value usage
|
69
|
+
def apply_format!(format, string)
|
39
70
|
return unless format
|
40
|
-
return unless
|
41
|
-
|
71
|
+
return unless string
|
72
|
+
string.gsub!(/\[\d{1,2}m/, "")
|
42
73
|
end
|
43
74
|
|
75
|
+
# Pushes new logdev in the start of #run call
|
76
|
+
# @param logdev [StringIO] new StringIO
|
44
77
|
def push_logdev(logdev)
|
45
78
|
logdevs << logdev
|
46
79
|
end
|
47
80
|
|
81
|
+
# Pops logdev in the end of #run call
|
82
|
+
# @return [StringIO] logdev
|
48
83
|
def pop_logdev
|
49
84
|
logdevs.pop
|
50
85
|
end
|
51
86
|
|
87
|
+
# Runs specific block with all logdevs in stack to
|
88
|
+
# populate them all
|
52
89
|
def each_logdev
|
53
90
|
logdevs.each do |logdev|
|
54
91
|
@logdev = logdev
|
@@ -1,9 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Lamian
|
4
|
+
# Provides extension to loggers, which should be teed to lamian
|
3
5
|
module LoggerExtension
|
6
|
+
# @api stdlib
|
7
|
+
# Add is a single entry point for ::Logger.{debug,info,..}
|
4
8
|
def add(*args, &block)
|
5
9
|
Logger.current.add(*args, &block)
|
6
10
|
super
|
7
11
|
end
|
12
|
+
|
13
|
+
# @api stdlib
|
14
|
+
# log is an alis for add and should also be prepended
|
15
|
+
def log(*args, &block)
|
16
|
+
Logger.current.add(*args, &block)
|
17
|
+
super
|
18
|
+
end
|
8
19
|
end
|
9
20
|
end
|
data/lib/lamian/middleware.rb
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Lamian
|
4
|
+
# Provides rack middleware, which allows to colelct request logs
|
5
|
+
# @attr app [Proc] stored application
|
3
6
|
class Middleware
|
7
|
+
# @param app [Proc] stored application
|
4
8
|
def initialize(app)
|
5
9
|
self.app = app
|
6
10
|
end
|
7
11
|
|
12
|
+
# wraps application inside lamian context and calls it
|
13
|
+
# @param env [Hash] left intact
|
14
|
+
# @return result of app.call
|
8
15
|
def call(env)
|
9
16
|
Lamian.run { app.call(env) }
|
10
17
|
end
|
data/lib/lamian/version.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Lamian
|
3
|
-
|
4
|
+
# Current lamian vewrsion
|
5
|
+
#
|
6
|
+
# format: 'a.b.c' with possible suffixes such as alpha
|
7
|
+
# * a is for major version, it is guaranteed to be changed
|
8
|
+
# if back-compatibility of public API is broken
|
9
|
+
# * b is for minor version, it is guaranteed to be changed
|
10
|
+
# on public API changes and also if private API
|
11
|
+
# back-compatibility is broken
|
12
|
+
# * c is for incremental version, it is updated in other cases
|
13
|
+
# According to this, it is enought to specify '~> a.b'
|
14
|
+
# if private API was not used and to specify '~> a.b.c' if it was
|
15
|
+
|
16
|
+
VERSION = "1.0.0alpha"
|
4
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lamian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JelF
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -81,19 +81,19 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop
|
84
|
+
name: rubocop-config-umbrellio
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.49.1.4
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 0.49.1.4
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: pry
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +122,48 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0.8'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: yard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.9'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.9'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: launchy
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 2.4.3
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 2.4.3
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: json
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 2.1.0
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 2.1.0
|
125
167
|
description: Add logs to your error messages, using exception_notifier or smth like
|
126
168
|
it
|
127
169
|
email:
|
@@ -153,12 +195,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
195
|
version: '0'
|
154
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
197
|
requirements:
|
156
|
-
- - "
|
198
|
+
- - ">"
|
157
199
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
200
|
+
version: 1.3.1
|
159
201
|
requirements: []
|
160
202
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.
|
203
|
+
rubygems_version: 2.6.11
|
162
204
|
signing_key:
|
163
205
|
specification_version: 4
|
164
206
|
summary: Add logs to your error messages
|