-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/378 request logging #379
Changes from 3 commits
bef21f7
ea70d81
e953b19
0ccaa88
7a973a3
ddb0f0b
82981f2
20a1807
4f34d2e
247006c
327e6ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,6 +159,7 @@ Main server options available. | |
| `csrf` | `KnotxCSRFConfiguration` | | Configuration of the CSRF tokens | | ||
| `defaultFlow` | `KnotxFlowConfiguration` | ✔ | Configuration of [[default Knot.X routing|KnotRouting]] | | ||
| `customFlow` | `KnotxFlowConfiguration` | | Configuration of [[Gateway Mode|GatewayMode]] | | ||
| `accessLog` | `AccessLogConfiguration` | | Configuration of the KnotxServer access log | | ||
|
||
### KnotxServerCustomHeader options | ||
Name | Type | Mandatory | Description | | ||
|
@@ -214,6 +215,15 @@ The `repositories`, `splitter` and `assembler` verticles are specific to the def | |
| `address` | `String` | ✔ | Event bus address of the **Knot** verticle | | ||
| `onTransition` | `KnotRouteEntry` | | Describes routing to addresses of other Knots based on the transition trigger returned from current Knot.<br/>`"onTransition": { "go-d": {}, "go-e": {} }` | | ||
|
||
|
||
### AccessLogConfiguration options | ||
| Name | Type | Mandatory | Description | | ||
|-------:|:-------:|:-------: |-------| | ||
| `enabled` | `boolean` | | Enable/Disable access log. Default is `true` | | ||
| `immediate` | `boolean` | | Log before request or after. Default is `false` - log after request | | ||
| `format` | `String` | | Format of the access log. Allowed valueds are `DEFAULT`, `SHORT`, `TINY`. Default tries to log in a format similar to Apache log format, while the other 2 are more suited to development mode. Default format is `DEFAULT` | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you provide here any url to documentation defining |
||
|
||
|
||
### Vert.x HTTP Server configurations | ||
|
||
Besides Knot.x specific configurations as mentioned above, the `config` field might have added Vert.x configurations related to the HTTP server. | ||
|
@@ -345,3 +355,50 @@ for eventubs requests that come from `KnotxServer`. | |
} | ||
} | ||
``` | ||
|
||
### Configure access log | ||
Knot.x uses a default Logging handler from the Vert.x web distribution that allows to log all incomming requests to the Http server. | ||
It supports three log line formats that are: | ||
- DEFAULT that tries to log in a format similar to Apache log format | ||
`127.0.0.1 - - [Tue, 23 Jan 2018 14:16:34 GMT] "GET /content/local/simple.html HTTP/1.1" 200 2963 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"` | ||
- SHORT | ||
`127.0.0.1 - GET /content/local/simple.html HTTP/1.1 200 2963 - 19 ms` | ||
- TINY | ||
`GET /content/local/simple.html 200 2963 - 24 ms` | ||
|
||
By default access log is enabled with a `DEFAULT` format. If you want to change it, just add access logging section on the KnotxServer configuration in your application.json config file : | ||
```json | ||
{ | ||
"config": { | ||
"knotx:io.knotx.KnotxServer": { | ||
"options": { | ||
"config": { | ||
"accessLog": { | ||
"format": "TINY" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
In order to log the access log to a separate file, just configure your logger in `logback.xml` file as follows | ||
```xml | ||
<appender name="access" class="ch.qos.logback.core.FileAppender"> | ||
<file>access.log</file> | ||
<append>true</append> | ||
<!-- set immediateFlush to false for much higher logging throughput --> | ||
<immediateFlush>true</immediateFlush> | ||
<encoder> | ||
<pattern>%msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="io.vertx.ext.web.handler.impl.LoggerHandlerImpl" level="INFO" additivity="false"> | ||
<appender-ref ref="access"/> | ||
</logger> | ||
``` | ||
This configures log appender as file, with the pattern being just a message. | ||
Next step, is to add logger for `io.vertx.ext.web.handler.impl.LoggerHandlerImpl` to be flushed out into your new appender. | ||
|
||
See [logback.xml](https://github.com/Cognifide/knotx/blob/master/knotx-example/knotx-example-app/src/main/resources/logback.xml) from the example app as an example. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,20 @@ | |
</encoder> | ||
</appender> | ||
|
||
<appender name="access" class="ch.qos.logback.core.FileAppender"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it is also worth to update |
||
<file>access.log</file> | ||
<append>true</append> | ||
<!-- set immediateFlush to false for much higher logging throughput --> | ||
<immediateFlush>true</immediateFlush> | ||
<encoder> | ||
<pattern>%msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="io.vertx.ext.web.handler.impl.LoggerHandlerImpl" level="INFO" additivity="false"> | ||
<appender-ref ref="access"/> | ||
</logger> | ||
|
||
<logger name="io.netty.handler.logging" level="TRACE" additivity="false"> | ||
<appender-ref ref="netty-wire"/> | ||
</logger> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (C) 2016 Cognifide Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.knotx.server.configuration; | ||
|
||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.ext.web.handler.LoggerFormat; | ||
|
||
public class AccessLogConfig { | ||
|
||
public static final boolean DEFAULT_ENABLED = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we can make those constants at least package private if not |
||
public static final boolean DEFAULT_LOGGER_IMMEDIATE = false; | ||
public static final String DEFAULT_LOGGER_FORMAT = LoggerFormat.DEFAULT.toString(); | ||
|
||
private boolean enabled; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Config properties can be final. |
||
private boolean immediate; | ||
private LoggerFormat format; | ||
|
||
public AccessLogConfig(JsonObject config) { | ||
enabled = config.getBoolean("enabled", DEFAULT_ENABLED); | ||
immediate = config.getBoolean("immediate", DEFAULT_LOGGER_IMMEDIATE); | ||
format = LoggerFormat | ||
.valueOf(config.getString("format", DEFAULT_LOGGER_FORMAT).toUpperCase()); | ||
} | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public boolean isImmediate() { | ||
return immediate; | ||
} | ||
|
||
public LoggerFormat getFormat() { | ||
return format; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,22 @@ | |
</encoder> | ||
</appender> | ||
|
||
<appender name="access" class="ch.qos.logback.core.FileAppender"> | ||
<file>access.log</file> | ||
<append>true</append> | ||
<!-- set immediateFlush to false for much higher logging throughput --> | ||
<immediateFlush>true</immediateFlush> | ||
<encoder> | ||
<pattern>%msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="io.vertx.ext.web.handler.impl.LoggerHandlerImpl" level="INFO" additivity="false"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add some comment that it logs requests :) |
||
<appender-ref ref="access"/> | ||
</logger> | ||
|
||
<logger name="io.knotx" level="INFO" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add logger for io.vertx, io.reactivex ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's do that for |
||
additivity="false"> | ||
additivity="false"> | ||
<appender-ref ref="STDOUT"/> | ||
</logger> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this property should be
mode
with values"before"
and"after"
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll keep it as it is now, as the same terminology is in the vertx access log handler used here.