brick_ftp 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brick_ftp.rb +7 -0
- data/lib/brick_ftp/configuration.rb +23 -2
- data/lib/brick_ftp/http_client.rb +15 -1
- data/lib/brick_ftp/log_formatter.rb +15 -0
- data/lib/brick_ftp/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df0a63a33d31d36f5aff9e852535dba1b01196c3
|
4
|
+
data.tar.gz: 92d3167f30a17525c8e2bc5c5300950876022ae2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54c30b2c27856a4db61e64eee37577232f016bf916ab1228a579de26bab63597269d88d11ebea059953bc1d0d4e3199528b6024ebd86c2352076487446fa8a9b
|
7
|
+
data.tar.gz: f1987fdff817e553c2822bdc6794fec1413f9e6735f6c553bf49ee08b7bc1ede358eed6e436aa81c8aabc2cbe53c890b9e83183ce8057b08a5d3a67c102f21b8
|
data/lib/brick_ftp.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'deep_hash_transform'
|
2
2
|
require "brick_ftp/version"
|
3
3
|
require 'brick_ftp/configuration'
|
4
|
+
require 'brick_ftp/log_formatter'
|
4
5
|
require 'brick_ftp/http_client'
|
5
6
|
require 'brick_ftp/client'
|
6
7
|
require 'brick_ftp/api'
|
@@ -63,4 +64,10 @@ module BrickFTP
|
|
63
64
|
def self.configure
|
64
65
|
yield(config)
|
65
66
|
end
|
67
|
+
|
68
|
+
# Return logger object.
|
69
|
+
# @return [Logger]
|
70
|
+
def self.logger
|
71
|
+
config.logger
|
72
|
+
end
|
66
73
|
end
|
@@ -14,14 +14,21 @@ module BrickFTP
|
|
14
14
|
# Logger.
|
15
15
|
# @return [Logger] logger
|
16
16
|
attr_accessor :logger
|
17
|
+
# Log level
|
18
|
+
# @return [Integer]
|
19
|
+
attr_reader :log_level
|
20
|
+
# Log formatter
|
21
|
+
# @return [Logger::Formatter]
|
22
|
+
attr_reader :log_formatter
|
17
23
|
|
18
24
|
def initialize
|
19
25
|
self.subdomain = ENV['BRICK_FTP_SUBDOMAIN']
|
20
26
|
self.api_key = ENV['BRICK_FTP_API_KEY']
|
21
27
|
self.session = nil
|
22
|
-
|
23
28
|
self.logger = Logger.new(STDOUT)
|
24
|
-
|
29
|
+
self.log_level = Logger::WARN
|
30
|
+
self.log_formatter = Logger::Formatter.new
|
31
|
+
logger.level = log_level
|
25
32
|
end
|
26
33
|
|
27
34
|
# Host name of API endpoint.
|
@@ -29,5 +36,19 @@ module BrickFTP
|
|
29
36
|
def api_host
|
30
37
|
"#{subdomain}.brickftp.com"
|
31
38
|
end
|
39
|
+
|
40
|
+
# Set log level to logger object.
|
41
|
+
# @param level [Integer] log level.
|
42
|
+
def log_level=(level)
|
43
|
+
@log_level = level
|
44
|
+
logger.level = @log_level
|
45
|
+
end
|
46
|
+
|
47
|
+
# Set log formatter to logger object.
|
48
|
+
# @param formatter [Logger::Formatter]
|
49
|
+
def log_formatter=(formatter)
|
50
|
+
@log_formatter = formatter
|
51
|
+
logger.formatter = @log_formatter
|
52
|
+
end
|
32
53
|
end
|
33
54
|
end
|
@@ -94,7 +94,21 @@ module BrickFTP
|
|
94
94
|
req["Content-Length"] = params.size
|
95
95
|
end
|
96
96
|
|
97
|
-
|
97
|
+
start = Time.now
|
98
|
+
begin
|
99
|
+
logger.debug 'Request headers: %{headers}' % { headers: req.each_capitalized.map { |k, v| "#{k}: #{v}" } }
|
100
|
+
logger.debug 'Request body: %{body}' % { body: req.body }
|
101
|
+
@conn.request(req).tap do |res|
|
102
|
+
logger.debug 'Response headers: %{headers}' % { headers: res.each_capitalized.map { |k, v| "#{k}: #{v}" } }
|
103
|
+
logger.debug 'Response body: %{body}' % { body: res.body }
|
104
|
+
end
|
105
|
+
ensure
|
106
|
+
logger.info 'Complete %{method} %{path} (%{time} ms)' % { method: method.upcase, path: path, time: (Time.now - start) * 1000 }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def logger
|
111
|
+
BrickFTP.logger
|
98
112
|
end
|
99
113
|
end
|
100
114
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BrickFTP
|
2
|
+
class LogFormatter < Logger::Formatter
|
3
|
+
FORMAT = "severity:%{severity}\tpid:%{pid}\ttime:%{time}\tmessage:%{message}\n".freeze
|
4
|
+
|
5
|
+
def call(severity, time, program_name, message)
|
6
|
+
params = {
|
7
|
+
severity: severity,
|
8
|
+
pid: Process.pid,
|
9
|
+
time: format_datetime(time),
|
10
|
+
message: msg2str(message),
|
11
|
+
}
|
12
|
+
FORMAT % params
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/brick_ftp/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brick_ftp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- koshigoe
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- lib/brick_ftp/client.rb
|
144
144
|
- lib/brick_ftp/configuration.rb
|
145
145
|
- lib/brick_ftp/http_client.rb
|
146
|
+
- lib/brick_ftp/log_formatter.rb
|
146
147
|
- lib/brick_ftp/version.rb
|
147
148
|
homepage: https://github.com/koshigoe/brick_ftp
|
148
149
|
licenses:
|