Skip to content

Commit 3ab25d2

Browse files
committed
🔰 Update README with SimpleFormatter
1 parent a75baf4 commit 3ab25d2

3 files changed

Lines changed: 60 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7-
## [2.0.0]
7+
## [2.1.0.pre.1]
8+
### Changed
9+
- Replace `ActiveSupport::Logger::SimpleFormatter` with `Loga::Formatters::SimpleFormatter`
10+
when using simple format. The formatter adds level, timestamp, pid and tags prepended to the message
11+
12+
## [2.0.0] - 2016-10-27
813
## [2.0.0.pre.3]
914
## [2.0.0.pre.2]
1015
## [2.0.0.pre1]
@@ -42,6 +47,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4247
### Changed
4348
- Silence ActionDispatch::DebugExceptions' logger
4449

50+
[2.1.0.pre.1]: https://github.com/FundingCircle/loga/compare/v2.0.0...v2.1.0.pre.1
4551
[2.0.0]: https://github.com/FundingCircle/loga/compare/v2.0.0.pre.3...v2.0.0
4652
[2.0.0.pre.3]: https://github.com/FundingCircle/loga/compare/v2.0.0.pre.2...v2.0.0.pre.3
4753
[2.0.0.pre.2]: https://github.com/FundingCircle/loga/compare/v2.0.0.pre1...v2.0.0.pre.2

README.md

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ Includes:
1717
- [Reduced logs](#reduced-logs)
1818
- [Request log tags](#request-log-tags)
1919
- [Sinatra](#sinatra)
20-
- [GELF Output example](#gelf-output-example)
20+
- [Output example](#output-example)
21+
- [GELF Format](#gelf-format)
22+
- [Simple Format](#simple-format)
2123
- [Road map](#road-map)
2224
- [Contributing](#contributing)
2325
- [Running tests](#running-tests)
@@ -45,7 +47,7 @@ end
4547

4648
Loga hooks into the Rails logger initialization process and defines its own logger for all environments.
4749

48-
The logger configuration adjusts based on the environment:
50+
The logger configuration is adjusted based on the environment:
4951

5052
| | Production | Test | Development | Others |
5153
|--------|------------|--------------|-------------|--------|
@@ -119,29 +121,39 @@ You can now use `Loga.logger` or assign it to your existing logger.
119121
The above configuration also inserts two middleware:
120122

121123
- `Loga::Rack::RequestId` makes the request id available to the request logger
122-
- `Loga::Rack::Logger` logs requests
124+
- `Loga::Rack::Logger` logs requests
123125

124-
## GELF Output Example
126+
You can easily switch between formats by using the `LOGA_FORMAT`
127+
environment variable. The `format` key in the options takes precedence over the
128+
environment variable therefore it must be removed.
129+
130+
```
131+
LOGA_FORMAT=simple rackup
132+
```
133+
134+
## Output Example
135+
136+
### GELF Format
125137

126138
Rails request logger: (includes controller/action name):
127139

128-
`GET /ok`
140+
`curl localhost:3000/ok -X GET -H "X-Request-Id: 12345"`
129141

130142
```json
131143
{
132144
"_request.status": 200,
133145
"_request.method": "GET",
134146
"_request.path": "/ok",
135147
"_request.params": {},
136-
"_request.request_id": "2b99e3d3-3ee2-4781-972b-782682f57648",
148+
"_request.request_id": "12345",
137149
"_request.request_ip": "127.0.0.1",
138150
"_request.user_agent": null,
139151
"_request.controller": "ApplicationController#ok",
140152
"_request.duration": 0,
141153
"_type": "request",
142154
"_service.name": "my_app",
143155
"_service.version": "1.0",
144-
"_tags": "2b99e3d3-3ee2-4781-972b-782682f57648",
156+
"_tags": "12345",
145157
"short_message": "GET /ok 200 in 0ms",
146158
"timestamp": 1450150205.123,
147159
"host": "example.com",
@@ -164,7 +176,7 @@ Loga.logger.info('I love Loga')
164176
{
165177
"_service.name": "my_app",
166178
"_service.version": "v1.0.0",
167-
"_tags": "",
179+
"_tags": "12345",
168180
"host": "example.com",
169181
"level": 6,
170182
"short_message": "I love Loga",
@@ -173,6 +185,38 @@ Loga.logger.info('I love Loga')
173185
}
174186
```
175187

188+
### Simple Format
189+
190+
Request logger:
191+
192+
`curl localhost:3000/ok -X GET -H "X-Request-Id: 12345"`
193+
194+
Rails
195+
196+
```
197+
I, [2016-11-15T16:05:03.614081+00:00 #1][12345] Started GET "/ok" for ::1 at 2016-11-15 16:05:03 +0000
198+
I, [2016-11-15T16:05:03.620176+00:00 #1][12345] Processing by ApplicationController#ok as HTML
199+
I, [2016-11-15T16:05:03.624807+00:00 #1][12345] Rendering text template
200+
I, [2016-11-15T16:05:03.624952+00:00 #1][12345] Rendered text template (0.0ms)
201+
I, [2016-11-15T16:05:03.625137+00:00 #1][12345] Completed 200 OK in 5ms (Views: 4.7ms)
202+
```
203+
204+
Sinatra
205+
206+
```
207+
I, [2016-11-15T16:10:08.645521+00:00 #1][12345] GET /ok 200 in 0ms type=request data={:request=>{"status"=>200, "method"=>"GET", "path"=>"/ok", "params"=>{}, "request_id"=>"12345", "request_ip"=>"127.0.0.1", "user_agent"=>nil, "duration"=>0}}
208+
```
209+
210+
Logger output:
211+
212+
```ruby
213+
Loga.logger.info('I love Loga')
214+
```
215+
216+
```
217+
I, [2015-12-15T09:30:05.123000+06:00 #999] I love Loga
218+
```
219+
176220
## Road map
177221

178222
Consult the [milestones](https://github.com/FundingCircle/loga/milestones).

lib/loga/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Loga
2-
VERSION = '2.0.0'.freeze
2+
VERSION = '2.1.0.pre.1'.freeze
33
end

0 commit comments

Comments
 (0)