Skip to content
Snippets Groups Projects
Commit 727d865e authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

Merge branch 'f-response-log-format' into 'dev'

F response log format

See merge request !97
parents 309b04bc 1021a182
No related branches found
No related tags found
2 merge requests!103Release 0.11.0,!97F response log format
Pipeline #39230 passed
...@@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### ### Added ###
* Configuration options `REST_RESPONSE_LOG_FORMAT` and
`GRPC_RESPONSE_LOG_FORMAT` which control the format and information included
in the log message of any response of the respective API. See
`conf/core/server.conf` for more information.
### Changed ### ### Changed ###
### Deprecated ### ### Deprecated ###
......
...@@ -8,6 +8,10 @@ verbose = true ...@@ -8,6 +8,10 @@ verbose = true
property.LOG_DIR = log property.LOG_DIR = log
property.REQUEST_TIME_LOGGER_LEVEL = OFF property.REQUEST_TIME_LOGGER_LEVEL = OFF
# the root logger has level "WARN" but we want to log the GRPC traffic in INFO level:
logger.grpc_response_log.name = org.caosdb.server.grpc.LoggingInterceptor
logger.grpc_response_log.level = INFO
## appenders ## appenders
# stderr # stderr
appender.stderr.type = Console appender.stderr.type = Console
......
...@@ -100,6 +100,21 @@ GRPC_SERVER_PORT_HTTPS=8443 ...@@ -100,6 +100,21 @@ GRPC_SERVER_PORT_HTTPS=8443
# HTTP port of the grpc end-point # HTTP port of the grpc end-point
GRPC_SERVER_PORT_HTTP= GRPC_SERVER_PORT_HTTP=
# --------------------------------------------------
# Response Log formatting (this cannot be configured by the logging frame work
# and thus has to be configured here).
# --------------------------------------------------
# Logging format of the GRPC API.
# Known keys: user-agent, local-address, remote-address, method.
# 'OFF' turns off the logging.
GRPC_RESPONSE_LOG_FORMAT={method} {local-address} {remote-address} {user-agent}
# Logging format of the REST API.
# Known keys: see column "Variable name" at https://javadocs.restlet.talend.com/2.4/jse/api/index.html?org/restlet/util/Resolver.html
# 'OFF' turns off the logging.
# Leaving this empty means using restlet's default settings.
REST_RESPONSE_LOG_FORMAT=
# -------------------------------------------------- # --------------------------------------------------
# HTTPS options # HTTPS options
# -------------------------------------------------- # --------------------------------------------------
......
...@@ -894,6 +894,13 @@ class CaosDBComponent extends Component { ...@@ -894,6 +894,13 @@ class CaosDBComponent extends Component {
public CaosDBComponent() { public CaosDBComponent() {
super(); super();
String responseLogFormat =
CaosDBServer.getServerProperty(ServerProperties.KEY_REST_RESPONSE_LOG_FORMAT);
if ("OFF".equalsIgnoreCase(responseLogFormat)) {
getLogService().setEnabled(false);
} else if (responseLogFormat != null && !responseLogFormat.isEmpty()) {
getLogService().setResponseLogFormat(responseLogFormat);
}
setName(CaosDBServer.getServerProperty(ServerProperties.KEY_SERVER_NAME)); setName(CaosDBServer.getServerProperty(ServerProperties.KEY_SERVER_NAME));
setOwner(CaosDBServer.getServerProperty(ServerProperties.KEY_SERVER_OWNER)); setOwner(CaosDBServer.getServerProperty(ServerProperties.KEY_SERVER_OWNER));
} }
......
...@@ -150,6 +150,8 @@ public class ServerProperties extends Properties implements Observable { ...@@ -150,6 +150,8 @@ public class ServerProperties extends Properties implements Observable {
public static final String KEY_PASSWORD_STRENGTH_REGEX = "PASSWORD_VALID_REGEX"; public static final String KEY_PASSWORD_STRENGTH_REGEX = "PASSWORD_VALID_REGEX";
public static final String KEY_PASSWORD_WEAK_MESSAGE = "PASSWORD_INVALID_MESSAGE"; public static final String KEY_PASSWORD_WEAK_MESSAGE = "PASSWORD_INVALID_MESSAGE";
public static final String KEY_REST_RESPONSE_LOG_FORMAT = "REST_RESPONSE_LOG_FORMAT";
public static final String KEY_GRPC_RESPONSE_LOG_FORMAT = "GRPC_RESPONSE_LOG_FORMAT";
/** /**
* Read the config files and initialize the server properties. * Read the config files and initialize the server properties.
......
package org.caosdb.server.grpc; package org.caosdb.server.grpc;
import io.grpc.Attributes.Key;
import io.grpc.Context; import io.grpc.Context;
import io.grpc.Contexts; import io.grpc.Contexts;
import io.grpc.Metadata; import io.grpc.Metadata;
...@@ -7,18 +8,70 @@ import io.grpc.ServerCall; ...@@ -7,18 +8,70 @@ import io.grpc.ServerCall;
import io.grpc.ServerCall.Listener; import io.grpc.ServerCall.Listener;
import io.grpc.ServerCallHandler; import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor; import io.grpc.ServerInterceptor;
import java.net.SocketAddress;
import org.caosdb.server.CaosDBServer;
import org.caosdb.server.ServerProperties;
import org.restlet.routing.Template;
import org.restlet.util.Resolver;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
class CallResolver<ReqT, RespT> extends Resolver<String> {
private ServerCall<ReqT, RespT> call;
private Metadata headers;
public static final Metadata.Key<String> KEY_USER_AGENT =
Metadata.Key.of("user-agent", Metadata.ASCII_STRING_MARSHALLER);
public static final Key<SocketAddress> KEY_LOCAL_ADDRESS = io.grpc.Grpc.TRANSPORT_ATTR_LOCAL_ADDR;
public static final Key<SocketAddress> KEY_REMOTE_ADDRESS =
io.grpc.Grpc.TRANSPORT_ATTR_REMOTE_ADDR;
public CallResolver(
ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
this.call = call;
this.headers = headers;
}
@Override
public String resolve(String name) {
switch (name) {
case "user-agent":
return headers.get(KEY_USER_AGENT);
case "remote-address":
return call.getAttributes().get(KEY_REMOTE_ADDRESS).toString();
case "local-address":
return call.getAttributes().get(KEY_LOCAL_ADDRESS).toString();
case "method":
return call.getMethodDescriptor().getFullMethodName();
default:
break;
}
return null;
}
}
public class LoggingInterceptor implements ServerInterceptor { public class LoggingInterceptor implements ServerInterceptor {
private Template template;
public LoggingInterceptor() {
String format = CaosDBServer.getServerProperty(ServerProperties.KEY_GRPC_RESPONSE_LOG_FORMAT);
if ("OFF".equalsIgnoreCase(format)) {
this.template = null;
} else if (format != null) {
this.template = new Template(format);
}
}
private static final Logger logger = LoggerFactory.getLogger(LoggingInterceptor.class.getName()); private static final Logger logger = LoggerFactory.getLogger(LoggingInterceptor.class.getName());
@Override @Override
public <ReqT, RespT> Listener<ReqT> interceptCall( public <ReqT, RespT> Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) { ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
if (template != null) {
logger.info(call.getMethodDescriptor().getFullMethodName() + " - " + call.getAttributes()); logger.info(template.format(new CallResolver<ReqT, RespT>(call, headers, next)));
}
return Contexts.interceptCall(Context.current(), call, headers, next); return Contexts.interceptCall(Context.current(), call, headers, next);
} }
} }
...@@ -54,7 +54,7 @@ public class CustomConfigurationFactory extends PropertiesConfigurationFactory { ...@@ -54,7 +54,7 @@ public class CustomConfigurationFactory extends PropertiesConfigurationFactory {
LOGGER.debug("Reconfiguration is done by {}", getClass().toString()); LOGGER.debug("Reconfiguration is done by {}", getClass().toString());
List<String> sources = getConfigFiles(); List<String> sources = getConfigFiles();
if (sources.size() > 1) { if (sources.size() > 0) {
final List<AbstractConfiguration> configs = new ArrayList<>(); final List<AbstractConfiguration> configs = new ArrayList<>();
for (final String sourceLocation : sources) { for (final String sourceLocation : sources) {
LOGGER.debug("Reconfigure with {}", sourceLocation); LOGGER.debug("Reconfigure with {}", sourceLocation);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment