Search in sources :

Example 1 with TraceLogConfigurationException

use of org.ballerinalang.logging.exceptions.TraceLogConfigurationException 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 TraceLogConfigurationException

use of org.ballerinalang.logging.exceptions.TraceLogConfigurationException in project ballerina by ballerina-lang.

the class StartWebSubSubscriberServiceEndpoint method execute.

@Override
public void execute(Context context) {
    Struct subscriberServiceEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
    Struct serviceEndpoint = ConnectorSPIModelHelper.createStruct((BStruct) ((BStruct) (subscriberServiceEndpoint.getVMValue())).getRefField(1));
    ServerConnector serverConnector = getServerConnector(serviceEndpoint);
    if (isHTTPTraceLoggerEnabled()) {
        try {
            ((BLogManager) BLogManager.getLogManager()).setHttpTraceLogHandler();
        } catch (IOException e) {
            throw new BallerinaConnectorException("Invalid HTTP trace log parameters found.", e);
        } catch (TraceLogConfigurationException e) {
            throw new BallerinaConnectorException("Unsupported HTTP trace log configuration. " + e.getMessage(), e);
        }
    }
    ServerConnectorFuture serverConnectorFuture = serverConnector.start();
    WebSubServicesRegistry webSubServicesRegistry = (WebSubServicesRegistry) serviceEndpoint.getNativeData(WebSubSubscriberConstants.WEBSUB_SERVICE_REGISTRY);
    HashSet<FilterHolder> filterHolder = getFilters(serviceEndpoint);
    serverConnectorFuture.setHttpConnectorListener(new BallerinaWebSubConnectionListener(webSubServicesRegistry, filterHolder));
    serverConnectorFuture.setPortBindingEventListener(new HttpConnectorPortBindingListener());
    context.setReturnValues();
}
Also used : BLogManager(org.ballerinalang.logging.BLogManager) BStruct(org.ballerinalang.model.values.BStruct) BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) FilterHolder(org.ballerinalang.net.http.serviceendpoint.FilterHolder) HttpConnectorPortBindingListener(org.ballerinalang.net.http.HttpConnectorPortBindingListener) ServerConnectorFuture(org.wso2.transport.http.netty.contract.ServerConnectorFuture) BallerinaWebSubConnectionListener(org.ballerinalang.net.websub.BallerinaWebSubConnectionListener) IOException(java.io.IOException) BStruct(org.ballerinalang.model.values.BStruct) Struct(org.ballerinalang.connector.api.Struct) ServerConnector(org.wso2.transport.http.netty.contract.ServerConnector) TraceLogConfigurationException(org.ballerinalang.logging.exceptions.TraceLogConfigurationException) WebSubServicesRegistry(org.ballerinalang.net.websub.WebSubServicesRegistry)

Aggregations

TraceLogConfigurationException (org.ballerinalang.logging.exceptions.TraceLogConfigurationException)2 IOException (java.io.IOException)1 ConsoleHandler (java.util.logging.ConsoleHandler)1 FileHandler (java.util.logging.FileHandler)1 Handler (java.util.logging.Handler)1 SocketHandler (java.util.logging.SocketHandler)1 BallerinaConnectorException (org.ballerinalang.connector.api.BallerinaConnectorException)1 Struct (org.ballerinalang.connector.api.Struct)1 BLogManager (org.ballerinalang.logging.BLogManager)1 HTTPTraceLogFormatter (org.ballerinalang.logging.formatters.HTTPTraceLogFormatter)1 JsonLogFormatter (org.ballerinalang.logging.formatters.JsonLogFormatter)1 BStruct (org.ballerinalang.model.values.BStruct)1 HttpConnectorPortBindingListener (org.ballerinalang.net.http.HttpConnectorPortBindingListener)1 FilterHolder (org.ballerinalang.net.http.serviceendpoint.FilterHolder)1 BallerinaWebSubConnectionListener (org.ballerinalang.net.websub.BallerinaWebSubConnectionListener)1 WebSubServicesRegistry (org.ballerinalang.net.websub.WebSubServicesRegistry)1 ServerConnector (org.wso2.transport.http.netty.contract.ServerConnector)1 ServerConnectorFuture (org.wso2.transport.http.netty.contract.ServerConnectorFuture)1