Search in sources :

Example 6 with ActionLog

use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.

the class HTTPServerHandler method handle.

private void handle(String path, HttpServerExchange exchange) {
    ActionLog actionLog = logManager.begin("=== http transaction begin ===");
    RequestImpl request = new RequestImpl(exchange, requestBeanMapper);
    try {
        // initialize webContext at beginning, the customerErrorHandler in errorHandler may use it if any exception
        webContext.initialize(request);
        requestParser.parse(request, exchange, actionLog);
        request.session = sessionManager.load(request);
        HeaderMap headers = exchange.getRequestHeaders();
        String client = headers.getFirst(HTTPServerHandler.HEADER_CLIENT);
        if (client != null)
            actionLog.context("client", client);
        actionLog.refId(headers.getFirst(HTTPServerHandler.HEADER_REF_ID));
        ControllerHolder controller = route.get(path, request.method(), request.pathParams, actionLog);
        actionLog.action(controller.action);
        actionLog.context("controller", controller.controllerInfo);
        logger.debug("controllerClass={}", controller.controller.getClass().getCanonicalName());
        // trigger trace after action is determined due to trace log use action as part of path, is there better way?
        if ("true".equals(headers.getFirst(HEADER_TRACE))) {
            actionLog.trace = true;
        }
        Response response = new InvocationImpl(controller, interceptors, request, webContext).proceed();
        sessionManager.save(request, response);
        responseHandler.render((ResponseImpl) response, exchange, actionLog);
    } catch (Throwable e) {
        logManager.logError(e);
        errorHandler.handleError(e, exchange, request, actionLog);
    } finally {
        webContext.cleanup();
        logManager.end("=== http transaction end ===");
    }
}
Also used : Response(core.framework.web.Response) HeaderMap(io.undertow.util.HeaderMap) HttpString(io.undertow.util.HttpString) ActionLog(core.framework.impl.log.ActionLog) RequestImpl(core.framework.impl.web.request.RequestImpl)

Example 7 with ActionLog

use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.

the class KafkaMessagePublisher method linkContext.

private void linkContext(Headers headers) {
    ActionLog actionLog = logManager.currentActionLog();
    if (actionLog == null)
        return;
    headers.add(KafkaHeaders.HEADER_REF_ID, Strings.bytes(actionLog.refId()));
    if (actionLog.trace)
        headers.add(KafkaHeaders.HEADER_TRACE, Strings.bytes("true"));
}
Also used : ActionLog(core.framework.impl.log.ActionLog)

Example 8 with ActionLog

use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.

the class ExecutorImpl method submit.

@Override
public <T> Future<T> submit(String action, Callable<T> task) {
    ActionLog parentActionLog = logManager.currentActionLog();
    String taskAction = parentActionLog.action + ":" + action;
    String refId = parentActionLog.refId();
    boolean trace = parentActionLog.trace;
    return executor.submit(() -> {
        try {
            ActionLog actionLog = logManager.begin("=== task execution begin ===");
            actionLog.refId(refId);
            actionLog.action(taskAction);
            if (trace) {
                actionLog.trace = true;
            }
            return task.call();
        } catch (Throwable e) {
            logManager.logError(e);
            throw e;
        } finally {
            logManager.end("=== task execution end ===");
        }
    });
}
Also used : ActionLog(core.framework.impl.log.ActionLog)

Example 9 with ActionLog

use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.

the class ActionLogContext method get.

public static Optional<String> get(String key) {
    LogManager logManager = logManager();
    ActionLog actionLog = logManager.currentActionLog();
    if (actionLog == null)
        return Optional.empty();
    return actionLog.context(key);
}
Also used : LogManager(core.framework.impl.log.LogManager) ActionLog(core.framework.impl.log.ActionLog)

Example 10 with ActionLog

use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.

the class ActionLogContext method stat.

// used to collect business metrics, and can be aggregated by Elasticsearch/Kibana
public static void stat(String key, Number value) {
    LogManager logManager = logManager();
    ActionLog actionLog = logManager.currentActionLog();
    if (actionLog != null) {
        actionLog.stat(key, value);
    }
}
Also used : LogManager(core.framework.impl.log.LogManager) ActionLog(core.framework.impl.log.ActionLog)

Aggregations

ActionLog (core.framework.impl.log.ActionLog)12 LogManager (core.framework.impl.log.LogManager)5 BytesParam (core.framework.impl.log.filter.BytesParam)1 RequestImpl (core.framework.impl.web.request.RequestImpl)1 Message (core.framework.kafka.Message)1 Job (core.framework.scheduler.Job)1 Response (core.framework.web.Response)1 HeaderMap (io.undertow.util.HeaderMap)1 HttpString (io.undertow.util.HttpString)1 ArrayList (java.util.ArrayList)1 Headers (org.apache.kafka.common.header.Headers)1