loga 1.0.0
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 +7 -0
- data/.gitignore +25 -0
- data/.rspec +2 -0
- data/.rubocop.yml +19 -0
- data/.rubocop_todo.yml +33 -0
- data/Appraisals +14 -0
- data/Gemfile +8 -0
- data/README.md +147 -0
- data/Rakefile +9 -0
- data/circle.yml +23 -0
- data/gemfiles/rails32.gemfile +11 -0
- data/gemfiles/rails40.gemfile +11 -0
- data/gemfiles/sinatra14.gemfile +11 -0
- data/gemfiles/unit.gemfile +9 -0
- data/lib/loga.rb +33 -0
- data/lib/loga/configuration.rb +96 -0
- data/lib/loga/event.rb +21 -0
- data/lib/loga/ext/rails/rack/logger3.rb +21 -0
- data/lib/loga/ext/rails/rack/logger4.rb +13 -0
- data/lib/loga/formatter.rb +104 -0
- data/lib/loga/parameter_filter.rb +65 -0
- data/lib/loga/rack/logger.rb +102 -0
- data/lib/loga/rack/request.rb +77 -0
- data/lib/loga/rack/request_id.rb +44 -0
- data/lib/loga/railtie.rb +139 -0
- data/lib/loga/tagged_logging.rb +76 -0
- data/lib/loga/utilities.rb +7 -0
- data/lib/loga/version.rb +3 -0
- data/loga.gemspec +31 -0
- data/spec/fixtures/README.md +8 -0
- data/spec/fixtures/rails32/Rakefile +7 -0
- data/spec/fixtures/rails32/app/controllers/application_controller.rb +28 -0
- data/spec/fixtures/rails32/app/helpers/application_helper.rb +2 -0
- data/spec/fixtures/rails32/app/views/layouts/application.html.erb +14 -0
- data/spec/fixtures/rails32/app/views/user.html.erb +1 -0
- data/spec/fixtures/rails32/config.ru +4 -0
- data/spec/fixtures/rails32/config/application.rb +71 -0
- data/spec/fixtures/rails32/config/boot.rb +6 -0
- data/spec/fixtures/rails32/config/environment.rb +5 -0
- data/spec/fixtures/rails32/config/environments/development.rb +26 -0
- data/spec/fixtures/rails32/config/environments/production.rb +50 -0
- data/spec/fixtures/rails32/config/environments/test.rb +35 -0
- data/spec/fixtures/rails32/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/fixtures/rails32/config/initializers/inflections.rb +15 -0
- data/spec/fixtures/rails32/config/initializers/mime_types.rb +5 -0
- data/spec/fixtures/rails32/config/initializers/secret_token.rb +7 -0
- data/spec/fixtures/rails32/config/initializers/session_store.rb +8 -0
- data/spec/fixtures/rails32/config/initializers/wrap_parameters.rb +10 -0
- data/spec/fixtures/rails32/config/locales/en.yml +5 -0
- data/spec/fixtures/rails32/config/routes.rb +64 -0
- data/spec/fixtures/rails32/public/404.html +26 -0
- data/spec/fixtures/rails32/public/422.html +26 -0
- data/spec/fixtures/rails32/public/500.html +25 -0
- data/spec/fixtures/rails32/public/favicon.ico +0 -0
- data/spec/fixtures/rails32/public/index.html +241 -0
- data/spec/fixtures/rails32/public/robots.txt +5 -0
- data/spec/fixtures/rails32/script/rails +6 -0
- data/spec/fixtures/rails40/Rakefile +6 -0
- data/spec/fixtures/rails40/app/controllers/application_controller.rb +30 -0
- data/spec/fixtures/rails40/app/helpers/application_helper.rb +2 -0
- data/spec/fixtures/rails40/app/views/layouts/application.html.erb +14 -0
- data/spec/fixtures/rails40/app/views/user.html.erb +1 -0
- data/spec/fixtures/rails40/bin/bundle +3 -0
- data/spec/fixtures/rails40/bin/rails +4 -0
- data/spec/fixtures/rails40/bin/rake +4 -0
- data/spec/fixtures/rails40/config.ru +4 -0
- data/spec/fixtures/rails40/config/application.rb +37 -0
- data/spec/fixtures/rails40/config/boot.rb +4 -0
- data/spec/fixtures/rails40/config/environment.rb +5 -0
- data/spec/fixtures/rails40/config/environments/development.rb +24 -0
- data/spec/fixtures/rails40/config/environments/production.rb +65 -0
- data/spec/fixtures/rails40/config/environments/test.rb +39 -0
- data/spec/fixtures/rails40/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/fixtures/rails40/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/fixtures/rails40/config/initializers/inflections.rb +16 -0
- data/spec/fixtures/rails40/config/initializers/mime_types.rb +5 -0
- data/spec/fixtures/rails40/config/initializers/secret_token.rb +12 -0
- data/spec/fixtures/rails40/config/initializers/session_store.rb +3 -0
- data/spec/fixtures/rails40/config/initializers/wrap_parameters.rb +9 -0
- data/spec/fixtures/rails40/config/locales/en.yml +23 -0
- data/spec/fixtures/rails40/config/routes.rb +62 -0
- data/spec/fixtures/rails40/public/404.html +58 -0
- data/spec/fixtures/rails40/public/422.html +58 -0
- data/spec/fixtures/rails40/public/500.html +57 -0
- data/spec/fixtures/rails40/public/favicon.ico +0 -0
- data/spec/fixtures/rails40/public/robots.txt +5 -0
- data/spec/integration/rails/railtie_spec.rb +64 -0
- data/spec/integration/rails/request_spec.rb +42 -0
- data/spec/integration/sinatra_spec.rb +54 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/support/helpers.rb +16 -0
- data/spec/support/request_spec.rb +183 -0
- data/spec/support/timecop_shared.rb +7 -0
- data/spec/unit/loga/configuration_spec.rb +123 -0
- data/spec/unit/loga/event_spec.rb +20 -0
- data/spec/unit/loga/formatter_spec.rb +186 -0
- data/spec/unit/loga/parameter_filter_spec.rb +76 -0
- data/spec/unit/loga/rack/logger_spec.rb +114 -0
- data/spec/unit/loga/rack/request_spec.rb +70 -0
- data/spec/unit/loga/utilities_spec.rb +16 -0
- data/spec/unit/loga_spec.rb +41 -0
- metadata +357 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: feb7e0fc4418e6763bb4cbe7cd0a381e8f0edf09
|
|
4
|
+
data.tar.gz: 7ee939ed4ba16283823ca2ca8f77bd9148e145b3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 71a379ec8c9659592d58dc1c0fae6096d00c6ed457368d26013970108ee4957141a5323620d931824768c2304ff04d95a1b707d90e893f3a2c0c3751054cb725
|
|
7
|
+
data.tar.gz: 3d71749a93556d196ea112fefa59cf26544a5b883dbda8044238ee759dde6dee71956ff74c4cbf1caaa06a088fd514de7f584ffdef6cc4699e7ae7984e661578
|
data/.gitignore
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
.bundle
|
|
4
|
+
.config
|
|
5
|
+
.yardoc
|
|
6
|
+
Gemfile.lock
|
|
7
|
+
InstalledFiles
|
|
8
|
+
_yardoc
|
|
9
|
+
coverage
|
|
10
|
+
doc/
|
|
11
|
+
lib/bundler/man
|
|
12
|
+
pkg
|
|
13
|
+
rdoc
|
|
14
|
+
spec/reports
|
|
15
|
+
test/tmp
|
|
16
|
+
test/version_tmp
|
|
17
|
+
tmp
|
|
18
|
+
*.bundle
|
|
19
|
+
*.so
|
|
20
|
+
*.o
|
|
21
|
+
*.a
|
|
22
|
+
*.gem
|
|
23
|
+
mkmf.log
|
|
24
|
+
spec/fixtures/**/*.log
|
|
25
|
+
gemfiles/*.lock
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
|
2
|
+
|
|
3
|
+
AllCops:
|
|
4
|
+
Exclude:
|
|
5
|
+
- 'spec/fixtures/**/*'
|
|
6
|
+
- '*.gemspec'
|
|
7
|
+
|
|
8
|
+
Style/TrailingComma:
|
|
9
|
+
Enabled: true
|
|
10
|
+
EnforcedStyleForMultiline: comma
|
|
11
|
+
|
|
12
|
+
Style/BlockDelimiters:
|
|
13
|
+
Enabled: false
|
|
14
|
+
|
|
15
|
+
Style/FormatString:
|
|
16
|
+
Enabled: false
|
|
17
|
+
|
|
18
|
+
Style/PerlBackrefs:
|
|
19
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
|
2
|
+
# on 2015-06-18 23:19:09 +0100 using RuboCop version 0.30.1.
|
|
3
|
+
# The point is for the user to remove these configuration records
|
|
4
|
+
# one by one as the offenses are removed from the code base.
|
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
|
7
|
+
|
|
8
|
+
# Offense count: 2
|
|
9
|
+
Lint/HandleExceptions:
|
|
10
|
+
Enabled: false
|
|
11
|
+
|
|
12
|
+
# Offense count: 2
|
|
13
|
+
Lint/RescueException:
|
|
14
|
+
Enabled: false
|
|
15
|
+
|
|
16
|
+
# Offense count: 4
|
|
17
|
+
Metrics/AbcSize:
|
|
18
|
+
Max: 29
|
|
19
|
+
|
|
20
|
+
# Offense count: 16
|
|
21
|
+
# Configuration parameters: AllowURI, URISchemes.
|
|
22
|
+
Metrics/LineLength:
|
|
23
|
+
Max: 93
|
|
24
|
+
|
|
25
|
+
# Offense count: 8
|
|
26
|
+
# Configuration parameters: CountComments.
|
|
27
|
+
Metrics/MethodLength:
|
|
28
|
+
Max: 22
|
|
29
|
+
|
|
30
|
+
# Offense count: 14
|
|
31
|
+
Style/Documentation:
|
|
32
|
+
Enabled: false
|
|
33
|
+
|
data/Appraisals
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Loga [](https://circleci.com/gh/FundingCircle/loga/tree/master) [](https://codeclimate.com/repos/5563694f6956805723005d2f/feed) [](https://codeclimate.com/repos/5563694f6956805723005d2f/coverage)
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
Loga defines a single log format, logger and middleware logger
|
|
6
|
+
to faciliate log aggregation.
|
|
7
|
+
|
|
8
|
+
It provides:
|
|
9
|
+
- Rack logger middleware to log HTTP requests
|
|
10
|
+
- Ruby logger
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Add this line to your application's Gemfile:
|
|
15
|
+
|
|
16
|
+
gem 'loga', git: 'git@github.com:FundingCircle/loga.git'
|
|
17
|
+
|
|
18
|
+
And then execute:
|
|
19
|
+
|
|
20
|
+
$ bundle
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
Loga integrates well with Rails and Sinatra frameworks. It also works in projects
|
|
25
|
+
using plain Ruby.
|
|
26
|
+
|
|
27
|
+
### Rails applications
|
|
28
|
+
|
|
29
|
+
In Rails applications initialization and middleware insertion is catered by
|
|
30
|
+
the Railtie.
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
# config/environments/production.rb
|
|
34
|
+
...
|
|
35
|
+
config.loga.configure do |loga|
|
|
36
|
+
# See configuration section
|
|
37
|
+
end
|
|
38
|
+
...
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Ruby and Sinatra/Rack applications
|
|
42
|
+
|
|
43
|
+
In Ruby applications Loga must be required and configured.
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
# .../initializers/loga.rb
|
|
47
|
+
require 'loga'
|
|
48
|
+
|
|
49
|
+
Loga.configure do |loga|
|
|
50
|
+
# See configuration section
|
|
51
|
+
end
|
|
52
|
+
Loga.initialize!
|
|
53
|
+
```
|
|
54
|
+
Log requests in Rack applications with Loga middleware.
|
|
55
|
+
|
|
56
|
+
`RequestId` and `Logger` must be inserted early in the middleware chain.
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
# config.ru
|
|
60
|
+
use Loga::Rack::RequestId
|
|
61
|
+
use Loga::Rack::Logger, Loga.logger
|
|
62
|
+
|
|
63
|
+
user Marketplace
|
|
64
|
+
run Sinatra::Application
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Configuration
|
|
68
|
+
|
|
69
|
+
| Option | Type | Default | Description |
|
|
70
|
+
|-----------------|---------------|---------|----------------------------------------------------------------------------------------------------|
|
|
71
|
+
| host | String | nil | Service hostname. When nil the hostname is computed with `Socket.gethostname` |
|
|
72
|
+
| service_version | String/Symbol | :git | Service version is embedded in every message. When Symbol the version is computed with a strategy. |
|
|
73
|
+
| service_name | String | nil | Service name is embedded in every message |
|
|
74
|
+
| device | IO | nil | The device the logger writes to |
|
|
75
|
+
| sync | Boolean | true | Sync IO |
|
|
76
|
+
| level | Symbol | :info | The level to logger logs at |
|
|
77
|
+
| enabled | Boolean | true | Enable/Disable Loga in Rails |
|
|
78
|
+
|
|
79
|
+
## Sample output
|
|
80
|
+
|
|
81
|
+
```ruby
|
|
82
|
+
# Anywhere in your application
|
|
83
|
+
Loga.logger.info('Hello World')
|
|
84
|
+
```
|
|
85
|
+
```json
|
|
86
|
+
//GELF Output
|
|
87
|
+
{
|
|
88
|
+
"version": "1.1",
|
|
89
|
+
"host": "example.com",
|
|
90
|
+
"short_message": "Hello World",
|
|
91
|
+
"timestamp": 1450150205.123,
|
|
92
|
+
"level": 6,
|
|
93
|
+
"_service.name": "marketplace",
|
|
94
|
+
"_service.version": "v1.0.0",
|
|
95
|
+
"_tags": []
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Event types
|
|
100
|
+
|
|
101
|
+
Middleware augment payload with the `type` key to label events.
|
|
102
|
+
|
|
103
|
+
| event type | description | middleware |
|
|
104
|
+
|-------------------|-----------------------------------|-------------------------|
|
|
105
|
+
| request | HTTP request and response | Rack |
|
|
106
|
+
|
|
107
|
+
## Caveat
|
|
108
|
+
|
|
109
|
+
- Loga formats timestamps in seconds since UNIX epoch with 3 decimal places
|
|
110
|
+
for milliseconds. Which is in accordance with GELF 1.1 specification.
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
## Road Map
|
|
114
|
+
|
|
115
|
+
Consult the [milestones](https://github.com/FundingCircle/loga/milestones).
|
|
116
|
+
|
|
117
|
+
## Contributing
|
|
118
|
+
|
|
119
|
+
### Overview
|
|
120
|
+
|
|
121
|
+
1. Fork it ( https://github.com/FundingCircle/loga/fork )
|
|
122
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
123
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
124
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
125
|
+
5. Create a new Pull Request
|
|
126
|
+
|
|
127
|
+
### Running tests
|
|
128
|
+
|
|
129
|
+
This project uses [`appraisal`](https://github.com/thoughtbot/appraisal/tree/v2.0.2) to run tests against different versions of dependencies (e.g. Rails, Sinatra).
|
|
130
|
+
|
|
131
|
+
Once you have run bundle, you can install the test dependencies with `bundle exec appraisal install`.
|
|
132
|
+
|
|
133
|
+
Run all tests with `bundle exec appraisal rspec`.
|
|
134
|
+
|
|
135
|
+
You can run tests for one appraisal with `bundle exec appraisal appraisal-name rspec`.
|
|
136
|
+
|
|
137
|
+
With Rack applications prepend RACK\_ENV to switch between environments `RACK_ENV=production bundle exec appraisal rspec`
|
|
138
|
+
|
|
139
|
+
Refer to the [Appraisals](https://github.com/FundingCircle/loga/blob/master/Appraisals) file for a complete lists of appraisals.
|
|
140
|
+
|
|
141
|
+
## Credits
|
|
142
|
+
|
|
143
|
+
- [LogStashLogger](https://github.com/dwbutler/logstash-logger)
|
|
144
|
+
- [Rails](https://github.com/rails/rails)
|
|
145
|
+
- [RackLogstasher](https://github.com/alphagov/rack-logstasher)
|
|
146
|
+
|
|
147
|
+
Copyright (c) 2015 Funding Circle. All rights reserved.
|
data/Rakefile
ADDED
data/circle.yml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
dependencies:
|
|
2
|
+
override:
|
|
3
|
+
- rvm-exec 1.9.3-p392 bundle install -j 4
|
|
4
|
+
- rvm-exec 1.9.3-p392 bundle exec appraisal install -j 4
|
|
5
|
+
- rvm-exec 2.0.0-p353 bundle install -j 4
|
|
6
|
+
- rvm-exec 2.0.0-p353 bundle exec appraisal install -j 4
|
|
7
|
+
- rvm-exec 2.2.2 bundle install -j 4
|
|
8
|
+
- rvm-exec 2.2.2 bundle exec appraisal install -j 4
|
|
9
|
+
test:
|
|
10
|
+
override:
|
|
11
|
+
- RACK_ENV=development rvm-exec 1.9.3-p392 bundle exec appraisal rspec
|
|
12
|
+
- RACK_ENV=production rvm-exec 1.9.3-p392 bundle exec appraisal rspec
|
|
13
|
+
- RACK_ENV=development rvm-exec 2.0.0-p353 bundle exec appraisal rspec
|
|
14
|
+
- RACK_ENV=production rvm-exec 2.0.0-p353 bundle exec appraisal rspec
|
|
15
|
+
- RACK_ENV=development rvm-exec 2.2.2 bundle exec appraisal rspec
|
|
16
|
+
- RACK_ENV=production rvm-exec 2.2.2 bundle exec appraisal rspec
|
|
17
|
+
- rvm-exec 2.2.2 bundle exec rubocop
|
|
18
|
+
deployment:
|
|
19
|
+
gemfury:
|
|
20
|
+
tag: /.*/
|
|
21
|
+
commands:
|
|
22
|
+
- "gem build loga.gemspec"
|
|
23
|
+
- "curl -F package=@$(ls -t1 loga-*.gem | head -1) ${GEMFURY_PUSH_URI}"
|
data/lib/loga.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'loga/version'
|
|
2
|
+
require 'loga/tagged_logging'
|
|
3
|
+
require 'loga/configuration'
|
|
4
|
+
require 'loga/utilities'
|
|
5
|
+
require 'loga/event'
|
|
6
|
+
require 'loga/formatter'
|
|
7
|
+
require 'loga/parameter_filter'
|
|
8
|
+
require 'loga/rack/logger'
|
|
9
|
+
require 'loga/rack/request'
|
|
10
|
+
require 'loga/rack/request_id'
|
|
11
|
+
require 'loga/railtie' if defined?(Rails)
|
|
12
|
+
|
|
13
|
+
module Loga
|
|
14
|
+
def self.configuration
|
|
15
|
+
@configuration ||= Configuration.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.configure
|
|
19
|
+
yield configuration
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.initialize!
|
|
23
|
+
configuration.initialize!
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.logger
|
|
27
|
+
configuration.logger
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.reset
|
|
31
|
+
@configuration = nil
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require 'logger'
|
|
2
|
+
require 'socket'
|
|
3
|
+
require 'active_support'
|
|
4
|
+
require 'active_support/core_ext/object/blank'
|
|
5
|
+
|
|
6
|
+
module Loga
|
|
7
|
+
class Configuration
|
|
8
|
+
attr_accessor :service_name,
|
|
9
|
+
:service_version,
|
|
10
|
+
:device,
|
|
11
|
+
:sync,
|
|
12
|
+
:filter_parameters,
|
|
13
|
+
:level,
|
|
14
|
+
:host,
|
|
15
|
+
:enabled,
|
|
16
|
+
:silence_rails_rack_logger
|
|
17
|
+
|
|
18
|
+
attr_reader :logger
|
|
19
|
+
|
|
20
|
+
def initialize
|
|
21
|
+
@host = gethostname
|
|
22
|
+
@device = nil
|
|
23
|
+
@sync = true
|
|
24
|
+
@level = :info
|
|
25
|
+
@filter_parameters = []
|
|
26
|
+
@service_version = :git
|
|
27
|
+
|
|
28
|
+
# Rails specific configuration
|
|
29
|
+
@enabled = true
|
|
30
|
+
@silence_rails_rack_logger = true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def initialize!
|
|
34
|
+
@service_name.to_s.strip!
|
|
35
|
+
@service_version = compute_service_version
|
|
36
|
+
|
|
37
|
+
initialize_logger
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def configure
|
|
41
|
+
yield self
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
class GitRevisionStrategy
|
|
47
|
+
DEFAULT_REVISION = 'unknown.sha'.freeze
|
|
48
|
+
|
|
49
|
+
def self.call
|
|
50
|
+
revision = fetch_revision if binary_available?
|
|
51
|
+
revision = DEFAULT_REVISION if revision.blank?
|
|
52
|
+
revision
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.binary_available?
|
|
56
|
+
system 'which git'
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def self.fetch_revision
|
|
60
|
+
`git rev-parse HEAD`.strip
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def compute_service_version
|
|
65
|
+
service_version == :git ? GitRevisionStrategy.call : service_version.strip
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def initialize_logger
|
|
69
|
+
device.sync = sync
|
|
70
|
+
|
|
71
|
+
logger = Logger.new(device)
|
|
72
|
+
logger.formatter = Formatter.new(
|
|
73
|
+
service_name: service_name,
|
|
74
|
+
service_version: service_version,
|
|
75
|
+
host: host,
|
|
76
|
+
)
|
|
77
|
+
logger.level = constantized_log_level
|
|
78
|
+
rescue
|
|
79
|
+
logger = Logger.new(STDERR)
|
|
80
|
+
logger.level = Logger::ERROR
|
|
81
|
+
logger.error 'Loga could not be initialized'
|
|
82
|
+
ensure
|
|
83
|
+
@logger = TaggedLogging.new(logger)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def constantized_log_level
|
|
87
|
+
Logger.const_get(level.to_s.upcase)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def gethostname
|
|
91
|
+
Socket.gethostname
|
|
92
|
+
rescue Exception
|
|
93
|
+
'unknown.host'
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|