@Override public ContextLogger build() { return new TraceeContextLogger(createGsonLogBuilder(), contextLoggerConfiguration); }
@Override public void logJsonWithPrefixedMessage(String prefixedMessage, Object... instancesToLog) { this.connectorsWrapper.sendErrorReportToConnectors(prefixedMessage, createJson(instancesToLog)); }
private void handleHttpServletRequest( HttpServletRequest servletRequest, HttpServletResponse servletResponse, Exception e) { TraceeContextLogger.createDefault().logJsonWithPrefixedMessage("TRACEE SERVLET ERROR CONTEXT LOGGING LISTENER : ", ImplicitContext.COMMON, ImplicitContext.TRACEE, servletRequest, servletResponse, e); }
/** * Creates a TraceeGsonContextLogBuilder instance which can be used for creating the log message. * * @return An instance of TraceeGsonContextLogBuilder */ private TraceeGsonContextLogBuilder createGsonLogBuilder() { TraceeGsonContextLogBuilder tmpTraceeGsonContextLogBuilder = new TraceeGsonContextLogBuilder(); tmpTraceeGsonContextLogBuilder.setWrapperClasses(contextLoggerConfiguration.getWrapperClasses()); tmpTraceeGsonContextLogBuilder.setManualContextOverrides(configBuilder.getManualContextOverrides()); tmpTraceeGsonContextLogBuilder.setProfile(this.configBuilder.getProfile()); return tmpTraceeGsonContextLogBuilder; } }
return createInstance(contextLoggerConfiguration.getImplicitContextClassMap().get(instance)); Class knownWrapperType = contextLoggerConfiguration.getClassToWrapperMap().get(instance.getClass()); if (knownWrapperType != null) { Object wrappedInstance = createInstance(knownWrapperType); if (WrappedContextData.class.isAssignableFrom(knownWrapperType)) { ((WrappedContextData) wrappedInstance).setContextData(instance); for (TypeToWrapper wrapper : contextLoggerConfiguration.getWrapperList()) { if (wrapper.getWrappedInstanceType().isAssignableFrom(instance.getClass())) { try { WrappedContextData wrapperInstance = (WrappedContextData) createInstance(wrapper.getWrapperType()); wrapperInstance.setContextData(instance);
/** * Initializes all available connectors. */ private void initConnectors() { // first get all connector configuration Names Set<String> connectorConfigurationNames = this.getConnectorConfigurationNames(); for (String connectorConfigurationName : connectorConfigurationNames) { Connector connector = this.createConnector(connectorConfigurationName); if (connector != null) { this.connectorMap.put(connectorConfigurationName, connector); } } // Add mandatory logger if (!isConnectorConfigured(LogConnector.class)) { Connector logConnector = new LogConnector(); this.connectorMap.put("LOGGER", logConnector); } }
public static ContextLoggerBuilder create() { return new ContextLoggerBuilderImpl(ContextLoggerConfiguration.getOrCreateContextLoggerConfiguration()); }
@Override public ConfigBuilder enable(String... contexts) { fillManualContextOverrideMap(contexts, true); return this; }
TraceeContextLogger(TraceeContextLogBuilder traceeGsonContextLogBuilder, ContextLoggerConfiguration contextLoggerConfiguration) { this.contextLoggerConfiguration = contextLoggerConfiguration; this.traceeGsonContextLogBuilder = traceeGsonContextLogBuilder; initConnectors(); }
public static ContextLoggerConfiguration getOrCreateContextLoggerConfiguration() { if (contextLoggerConfiguration == null) { contextLoggerConfiguration = new ContextLoggerConfiguration(); } return contextLoggerConfiguration; }
@Override public String createJson(Object... instancesToLog) { return propagateToContextLogBuilder(instancesToLog); }
/** * Initializes all available connectors. */ private void initConnectors() { connectorsWrapper = new ConnectorFactory(); }
ConnectorFactory() { initConnectors(); }
@Override public void logJson(Object... instancesToLog) { this.logJsonWithPrefixedMessage(null, instancesToLog); }
/** * This method handles the wrapping of the incoming object and passes them to the context toJson builder implementation. * * @param instancesToLog an array of objects to wrap * @return the contextual toJson information as a String */ String propagateToContextLogBuilder(Object[] instancesToLog) { Object[] propagateArray = null; if (instancesToLog != null) { propagateArray = new Object[instancesToLog.length]; for (int i = 0; i < instancesToLog.length; i++) { propagateArray[i] = wrapInstance(instancesToLog[i]); } } return traceeGsonContextLogBuilder.logPassedContext(new PassedDataContextProvider(propagateArray)); }
/** * Tries to create a Connector for a given connector configuration name. * * @param connectorConfigurationName the name of the connector configuration * @return the connector if it could be created and initialized without error, otherwise null */ final Connector createConnector(final String connectorConfigurationName) { Map<String, String> propertyMap = this.getPropertiesForConnectorConfigurationName(connectorConfigurationName); String type = propertyMap.get(TraceeContextLoggerConstants.SYSTEM_PROPERTY_CONTEXT_LOGGER_CONNECTOR_TYPE); // get canonical class name for well known connectors if (WELL_KNOW_CONNECTOR_MAPPINGS.containsKey(type)) { type = WELL_KNOW_CONNECTOR_MAPPINGS.get(type); } try { // try to create connector instance Connector connector = (Connector) Class.forName(type).newInstance(); // now try to call init method connector.init(propertyMap); return connector; } catch (Exception e) { LOGGER.error("An error occurred while creating connector with name '" + connectorConfigurationName + "' of type '" + type + "'", e); } return null; }
@AroundInvoke public Object intercept(InvocationContext ctx) throws Exception { try { return ctx.proceed(); } catch (Exception e) { // now log context informations TraceeContextLogger.createDefault().logJsonWithPrefixedMessage("TRACEE EJB INTERCEPTOR CONTEXT LOGGING LISTENER : ", ImplicitContext.COMMON, ImplicitContext.TRACEE, ctx, e); throw e; } }
@Override public ConfigBuilder disable(String... contexts) { fillManualContextOverrideMap(contexts, false); return this; }