Search in sources :

Example 1 with JsonLogFormatter

use of org.ballerinalang.logging.formatters.JsonLogFormatter in project ballerina by ballerina-lang.

the class BLogManager method populateTraceHandlerConfiguration.

private Handler populateTraceHandlerConfiguration(String logToString) throws IOException, TraceLogConfigurationException {
    Handler handler = null;
    if (logToString.equalsIgnoreCase(LOG_TO_CONSOLE)) {
        handler = new ConsoleHandler();
        handler.setFormatter(new HTTPTraceLogFormatter());
    } else if (logToString.contains(Constants.LOG_TO_SOCKET)) {
        String socketAddressString = logToString.substring(logToString.indexOf(";") + 1);
        String host = socketAddressString.substring(0, socketAddressString.indexOf(":")).trim();
        host = (!host.isEmpty()) ? host : Constants.LOG_PUBLISH_DEFAULT_HOST;
        String portString = socketAddressString.substring(socketAddressString.indexOf(":") + 1).trim();
        int port = (!portString.isEmpty()) ? Integer.parseInt(portString) : Constants.LOG_PUBLISH_DEFAULT_PORT;
        handler = new SocketHandler(host, port);
        handler.setFormatter(new JsonLogFormatter());
    } else {
        throw new TraceLogConfigurationException(logToString + " is unsupported logto value in Http trace logging configuration.");
    }
    handler.setLevel(Level.FINEST);
    return handler;
}
Also used : TraceLogConfigurationException(org.ballerinalang.logging.exceptions.TraceLogConfigurationException) SocketHandler(java.util.logging.SocketHandler) FileHandler(java.util.logging.FileHandler) SocketHandler(java.util.logging.SocketHandler) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) HTTPTraceLogFormatter(org.ballerinalang.logging.formatters.HTTPTraceLogFormatter) JsonLogFormatter(org.ballerinalang.logging.formatters.JsonLogFormatter) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 2 with JsonLogFormatter

use of org.ballerinalang.logging.formatters.JsonLogFormatter in project ballerina by ballerina-lang.

the class JsonLogFormatterTest method setUp.

@BeforeClass(description = "Initialize variables required for test.")
protected void setUp() throws Exception {
    jsonLogFormatter = new JsonLogFormatter();
    logRecord = new LogRecord(Level.FINEST, traceLogMessage);
}
Also used : LogRecord(java.util.logging.LogRecord) JsonLogFormatter(org.ballerinalang.logging.formatters.JsonLogFormatter) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

JsonLogFormatter (org.ballerinalang.logging.formatters.JsonLogFormatter)2 ConsoleHandler (java.util.logging.ConsoleHandler)1 FileHandler (java.util.logging.FileHandler)1 Handler (java.util.logging.Handler)1 LogRecord (java.util.logging.LogRecord)1 SocketHandler (java.util.logging.SocketHandler)1 TraceLogConfigurationException (org.ballerinalang.logging.exceptions.TraceLogConfigurationException)1 HTTPTraceLogFormatter (org.ballerinalang.logging.formatters.HTTPTraceLogFormatter)1 BeforeClass (org.testng.annotations.BeforeClass)1