Skip to content
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

Access log common log format #96

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.lang.reflect.Field;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
Expand Down Expand Up @@ -58,8 +60,8 @@ private Map<String,Object> getValueMap() {
}

if (requestTime != null) {
String localDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(requestTime), ZoneId.systemDefault()).toString();
params.put("request-time", localDate);
String localDate = OffsetDateTime.ofInstant(Instant.ofEpochMilli(requestTime), ZoneId.systemDefault()).format(DateTimeFormatter.ISO_DATE_TIME);
params.put("requestTime", localDate);
}
params.put("thread", Thread.currentThread().getName());
if (userContext != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public void doProcessRequest(R req, RequestParams<Metadata> requestParamsInput)
accessLogContextBuilder = AccessLogContext.builder()
.requestTime(startTime)
.clientIp(requestParamsInput.getClientIp())
.resourcePath(requestParamsInput.getResourcePath());
.resourcePath(requestParamsInput.getResourcePath())
.method(requestParamsInput.getMethod());

Map<String, String> headers = requestParamsInput.getMetadata().keys().stream()
.collect(Collectors.toMap(String::toLowerCase, key ->
Expand All @@ -92,7 +93,7 @@ public void doProcessRequest(R req, RequestParams<Metadata> requestParamsInput)
}

/**
* Placeholder method for processing response headers. Currently does not perform any operations.
* Placeholder method for processing response headers. Currently, does not perform any operations.
*
* @param responseHeaders The metadata associated with the gRPC response.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ public class GrpcFilterConfig {
private boolean enableAccessLogs = true;

@JsonProperty("accessLogFormat")
private String accessLogFormat = "{clientIp} {resourcePath} {responseStatus} {contentLength} {responseTime}";
private String accessLogFormat = "{clientIp} - [{requestTime}] \"{method} {resourcePath}\" {responseStatus} {contentLength} {responseTime}";
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public class HttpFilterConfig {
private boolean enableAccessLogs = true;

@JsonProperty("accessLogFormat")
private String accessLogFormat = "{clientIp} \"{method} {resourcePath} {protocol}\" {responseStatus} {contentLength} {responseTime}";
private String accessLogFormat = "{clientIp} - [{requestTime}] \"{method} {resourcePath} {protocol}\" {responseStatus} {contentLength} {responseTime} \"{referer}\" \"{userAgent}\"";

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void invokeGrpcCall(HelloRequest req, HelloReply reply) {

@Override
@Timed // the Timed annotation for publishing JMX metrics via MBean
@MethodFilters({LoggingFilter.class, AuthFilter.class}) // Method level filters
@MethodFilters({LoggingFilter.class}) // Method level filters
@Traced(withSamplingRate = 0.0f) // Start a new Trace or participate in a Client-initiated distributed trace
public StreamObserver<Ping> pingPong(StreamObserver<Pong> responseObserver) {

Expand Down
4 changes: 2 additions & 2 deletions examples/src/main/resources/hello_world_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Grpc:
server.executorThreads : 4
filterConfig:
enableAccessLogs: true
accessLogFormat: "{clientIp} {resourcePath} {contentLength} {responseStatus} {responseTime}"
accessLogFormat: '{clientIp} - [{requestTime}] "{method} {resourcePath} GRPC" {responseStatus} {contentLength} {responseTime} "-" "-"'

Dashboard:
service.port: 9999
Expand All @@ -21,7 +21,7 @@ Api:
healthcheck.path: "/elb-healthcheck"
filterConfig:
enableAccessLogs: true
accessLogFormat: '{clientIp} - [{request-time}] "{method} {resourcePath} {protocol}" {responseStatus} {contentLength} {responseTime} "{referer}" "{userAgent}"'
accessLogFormat: '{clientIp} - [{requestTime}] "{method} {resourcePath} {protocol}" {responseStatus} {contentLength} {responseTime} "{referer}" "{userAgent}"'

Tracing:
collector.endpoint: http://localhost:9411/api/v2/spans
Expand Down
12 changes: 6 additions & 6 deletions examples/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration shutdownHook="disable">
<Properties>
<Property name="log-path">logs</Property>
<Property name="log-path">/tmp/logs</Property>
</Properties>
<Appenders>
<Console name="console-log" target="SYSTEM_OUT">
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{5} %X - %msg%n"/>
</Console>
<Console name="ACCESS-LOG" target="SYSTEM_OUT">
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{5} %X - %msg%n"/>
</Console>
<File name="access-log" fileName="${log-path}/access.log">
<PatternLayout pattern="%msg%n"/>
</File>
</Appenders>
<Loggers>
<Logger name="io.netty.channel" level="info" additivity="false">
<AppenderRef ref="ACCESS-LOG"/>
<Logger name="ACCESS-LOG" level="info" additivity="false">
<AppenderRef ref="access-log"/>
</Logger>
<Logger name="io.netty.channel" level="error" additivity="false">
<AppenderRef ref="console-log"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public void sendHeaders(final Metadata responseHeaders) {
RequestParams requestParams = RequestParams.builder()
.clientIp(getClientIp(call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR)))
.resourcePath(call.getMethodDescriptor().getFullMethodName().toLowerCase())
.method(call.getMethodDescriptor().getType().name())
.metadata(headers)
.build();

Expand Down