@@ -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 )
4547
4648Loga 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.
119121The 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
126138Rails 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
178222Consult the [ milestones] ( https://github.com/FundingCircle/loga/milestones ) .
0 commit comments