org.apache.logging.log4j.Marker Java Examples

The following examples show how to use org.apache.logging.log4j.Marker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlSetupContextInitializer.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
public void setupModule(final SetupContext context, final boolean includeStacktrace,
        final boolean stacktraceAsString) {
    // JRE classes: we cannot edit those with Jackson annotations
    context.setMixInAnnotations(StackTraceElement.class, StackTraceElementXmlMixIn.class);
    // Log4j API classes: we do not want to edit those with Jackson annotations because the API module should not
    // depend on Jackson.
    context.setMixInAnnotations(Marker.class, MarkerXmlMixIn.class);
    context.setMixInAnnotations(Level.class, LevelMixIn.class);
    context.setMixInAnnotations(Instant.class, InstantXmlMixIn.class);
    context.setMixInAnnotations(LogEvent.class, LogEventWithContextListXmlMixIn.class);
    // Log4j Core classes: we do not want to bring in Jackson at runtime if we do not have to.
    context.setMixInAnnotations(ExtendedStackTraceElement.class, ExtendedStackTraceElementXmlMixIn.class);
    context.setMixInAnnotations(ThrowableProxy.class, includeStacktrace
            ? (stacktraceAsString ? ThrowableProxyWithStacktraceAsStringXmlMixIn.class : ThrowableProxyXmlMixIn.class)
            : ThrowableProxyWithoutStacktraceXmlMixIn.class);
}
 
Example #2
Source File: MarkerAttributeConverterTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvert01() {
    final Marker marker = MarkerManager.getMarker("testConvert01");

    final String converted = this.converter.convertToDatabaseColumn(marker);

    assertNotNull("The converted value should not be null.", converted);
    assertEquals("The converted value is not correct.", "testConvert01", converted);

    final Marker reversed = this.converter.convertToEntityAttribute(converted);

    assertNotNull("The reversed value should not be null.", reversed);
    assertEquals("The reversed value is not correct.", "testConvert01", marker.getName());
}
 
Example #3
Source File: XYZHubRESTVerticle.java    From xyz-hub with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and sends an error response to the client.
 */
public static void sendErrorResponse(final RoutingContext context, final Throwable exception) {
  ErrorMessage error;

  try {
    final Marker marker = Api.Context.getMarker(context);

    error = new ErrorMessage(context, exception);
    if (error.statusCode == 500) {
      error.message = null;
      logger.error(marker, "Sending error response: {} {} {}", error.statusCode, error.reasonPhrase, exception);
    }
    else {
      logger.warn(marker, "Sending error response: {} {} {}", error.statusCode, error.reasonPhrase, exception);
    }
  } catch (Exception e) {
    logger.error("Error {} while preparing error response {}", e, exception);
    error = new ErrorMessage();
  }

  context.response()
      .putHeader(CONTENT_TYPE, APPLICATION_JSON)
      .setStatusCode(error.statusCode)
      .setStatusMessage(error.reasonPhrase)
      .end(Json.encode(error));
}
 
Example #4
Source File: RingBufferLogEventTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetLevelReturnsOffIfNullLevelSet() {
    final RingBufferLogEvent evt = new RingBufferLogEvent();
    final String loggerName = null;
    final Marker marker = null;
    final String fqcn = null;
    final Level level = null;
    final Message data = null;
    final Throwable t = null;
    final ContextStack contextStack = null;
    final String threadName = null;
    final StackTraceElement location = null;
    evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(),
            contextStack, -1, threadName, -1, location, new FixedPreciseClock(), new DummyNanoClock(1));
    assertEquals(Level.OFF, evt.getLevel());
}
 
Example #5
Source File: SLF4JLogger.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private org.slf4j.Marker getMarker(final Marker marker) {
    if (marker == null) {
        return null;
    }
    final org.slf4j.Marker slf4jMarker = MarkerFactory.getMarker(marker.getName());
    final Marker[] parents = marker.getParents();
    if (parents != null) {
        for (final Marker parent : parents) {
            final org.slf4j.Marker slf4jParent = getMarker(parent);
            if (!slf4jMarker.contains(slf4jParent)) {
                slf4jMarker.add(slf4jParent);
            }
        }
    }
    return slf4jMarker;
}
 
Example #6
Source File: RemoteFunctionClient.java    From xyz-hub with Apache License 2.0 6 votes vote down vote up
private void enqueue(final Marker marker, byte[] bytes, boolean fireAndForget, final Handler<AsyncResult<byte[]>> callback) {
  FunctionCall fc = new FunctionCall(marker, bytes, fireAndForget, callback);

  /*if (Service.currentTimeMillis() > lastSizeAdjustment.get() + SIZE_ADJUSTMENT_INTERVAL
      && fc.getByteSize() + queue.getByteSize() > queue.getMaxByteSize()) {
    //Element won't fit into queue so we try to enlarge it
    adjustQueueByteSizes();
  }*/

  //In any case add the element to the queue
  queue.add(fc)
      //Send timeout for discarded (old) calls
      .forEach(timeoutFc ->
          timeoutFc.callback
              .handle(Future.failedFuture(new HttpException(TOO_MANY_REQUESTS, "Remote function is busy or cannot be invoked."))));
}
 
Example #7
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@PerformanceSensitive
// NOTE: This is a hot method. Current implementation compiles to 27 bytes of byte code.
// This is within the 35 byte MaxInlineSize threshold. Modify with care!
private void tryLogMessage(final String fqcn,
                           final StackTraceElement location,
                           final Level level,
                           final Marker marker,
                           final Message msg,
                           final Throwable throwable) {
    try {
        log(level, marker, fqcn, location, msg, throwable);
    } catch (final Exception e) {
        // LOG4J2-1990 Log4j2 suppresses all exceptions that occur once application called the logger
        handleLogMessageException(e, fqcn, msg);
    }
}
 
Example #8
Source File: SpaceConfigClient.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
public void delete(Marker marker, String spaceId, Handler<AsyncResult<Space>> handler) {
  deleteSpace(marker, spaceId, ar -> {
    if (ar.succeeded()) {
      invalidateCache(spaceId);
      logger.info(marker, "space[{}]: Deleted space", spaceId);
      handler.handle(Future.succeededFuture(ar.result()));
    } else {
      logger.error(marker, "space[{}]: Failed deleting the space", spaceId, ar.cause());
      handler.handle(Future.failedFuture(ar.cause()));
    }
  });
}
 
Example #9
Source File: MapFilter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final String msg,
        final Object p0, final Object p1, final Object p2, final Object p3,
        final Object p4, final Object p5, final Object p6,
        final Object p7, final Object p8) {
    return Result.NEUTRAL;
}
 
Example #10
Source File: ThresholdFilter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final String msg,
        final Object p0, final Object p1, final Object p2, final Object p3,
        final Object p4, final Object p5, final Object p6,
        final Object p7) {
    return filter(level);
}
 
Example #11
Source File: MapFilter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final String msg,
        final Object p0, final Object p1, final Object p2, final Object p3,
        final Object p4, final Object p5, final Object p6,
        final Object p7, final Object p8, final Object p9) {
    return Result.NEUTRAL;
}
 
Example #12
Source File: MarkerSimpleNamePatternConverter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void format(final LogEvent event, final StringBuilder toAppendTo) {
    final Marker marker = event.getMarker();
    if (marker != null) {
        toAppendTo.append(marker.getName());
    }
}
 
Example #13
Source File: StringMatchFilter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final String msg,
        final Object p0, final Object p1, final Object p2, final Object p3,
        final Object p4, final Object p5, final Object p6,
        final Object p7) {
    return filter(logger.getMessageFactory().newMessage(msg, p0, p1, p2, p3, p4, p5, p6, p7).getFormattedMessage());
}
 
Example #14
Source File: LambdaFunctionClient.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
/**
 * Invokes the remote lambda function and returns the decompressed response as bytes.
 */
@Override
protected void invoke(final Marker marker, byte[] bytes, boolean fireAndForget, final Handler<AsyncResult<byte[]>> callback) {
  final RemoteFunctionConfig remoteFunction = getConnectorConfig().remoteFunction;
  logger.debug(marker, "Invoking remote lambda function with id '{}' Event size is: {}", remoteFunction.id, bytes.length);

  InvokeRequest invokeReq = new InvokeRequest()
      .withFunctionName(((AWSLambda) remoteFunction).lambdaARN)
      .withPayload(ByteBuffer.wrap(bytes))
      .withInvocationType(fireAndForget ? InvocationType.Event : InvocationType.RequestResponse);

  asyncClient.invokeAsync(invokeReq, new AsyncHandler<InvokeRequest, InvokeResult>() {
    @Override
    public void onError(Exception exception) {
      if (callback == null) {
        logger.error(marker, "Error sending event to remote lambda function", exception);
      }
      else {
        callback.handle(Future.failedFuture(getWHttpException(marker, exception)));
      }
    }

    @Override
    public void onSuccess(InvokeRequest request, InvokeResult result) {
      byte[] responseBytes = new byte[result.getPayload().remaining()];
      result.getPayload().get(responseBytes);
      callback.handle(Future.succeededFuture(responseBytes));
    }
  });
}
 
Example #15
Source File: BurstFilter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final String msg,
        final Object p0, final Object p1, final Object p2, final Object p3,
        final Object p4, final Object p5, final Object p6,
        final Object p7, final Object p8) {
    return filter(level);
}
 
Example #16
Source File: LevelMatchFilter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final String msg,
        final Object p0, final Object p1, final Object p2, final Object p3,
        final Object p4, final Object p5, final Object p6,
        final Object p7, final Object p8, final Object p9) {
    return filter(level);
}
 
Example #17
Source File: DynamoConnectorConfigClient.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
@Override
protected void getAllConnectors(Marker marker, Handler<AsyncResult<List<Connector>>> handler) {
  final List<Connector> result = new ArrayList<>();
  try {
    connectors.scan().pages().forEach(p -> p.forEach(i -> {
      final Connector connector = Json.decodeValue(i.toJSON(), Connector.class);
      result.add(connector);
    }));
    handler.handle(Future.succeededFuture(result));
  }
  catch (Exception e) {
    handler.handle(Future.failedFuture(new RuntimeException("Error retrieving all connectors.", e)));
  }
}
 
Example #18
Source File: InMemSpaceConfigClient.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
@Override
public void storeSpace(Marker marker, Space space, Handler<AsyncResult<Space>> handler) {
  if (space.getId() == null) {
    space.setId(RandomStringUtils.randomAlphanumeric(10));
  }
  spaceMap.put(space.getId(), space);
  handler.handle(Future.succeededFuture(space));
}
 
Example #19
Source File: Log4j2xMarkerIT.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@Override
public void transactionMarker() {
    logger.debug((Marker) null, "bcd_t", new IllegalStateException("234"));
    logger.info((Marker) null, "cde_t", new IllegalStateException("345"));
    logger.warn((Marker) null, "def_t", new IllegalStateException("456"));
    logger.error((Marker) null, "efg_t", new IllegalStateException("567"));
}
 
Example #20
Source File: BurstFilter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final String msg,
        final Object p0, final Object p1, final Object p2, final Object p3,
        final Object p4, final Object p5, final Object p6,
        final Object p7, final Object p8, final Object p9) {
    return filter(level);
}
 
Example #21
Source File: ScriptFilter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final Message msg,
                     final Throwable t) {
    final SimpleBindings bindings = new SimpleBindings();
    bindings.put("logger", logger);
    bindings.put("level", level);
    bindings.put("marker", marker);
    bindings.put("message", msg);
    bindings.put("parameters", null);
    bindings.put("throwable", t);
    bindings.putAll(configuration.getProperties());
    bindings.put("substitutor", configuration.getStrSubstitutor());
    final Object object = configuration.getScriptManager().execute(script.getName(), bindings);
    return object == null || !Boolean.TRUE.equals(object) ? onMismatch : onMatch;
}
 
Example #22
Source File: MarkerFilter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final String msg,
        final Object p0, final Object p1, final Object p2, final Object p3,
        final Object p4, final Object p5, final Object p6,
        final Object p7) {
    return filter(marker);
}
 
Example #23
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public void debug(final Marker marker, final Object message) {
    logIfEnabled(FQCN, Level.DEBUG, marker, message, null);
}
 
Example #24
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message,
        final Object... params) {
    final Message msg = messageFactory.newMessage(message, params);
    logMessageSafely(fqcn, level, marker, msg, msg.getThrowable());
}
 
Example #25
Source File: MarkerFilter.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final String msg,
        final Object p0, final Object p1, final Object p2, final Object p3,
        final Object p4, final Object p5) {
    return filter(marker);
}
 
Example #26
Source File: StatusLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isEnabled(final Level level, final Marker marker, final Message message, final Throwable t) {
    return isEnabled(level, marker);
}
 
Example #27
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public void trace(final Marker marker, final String message, final Object p0, final Object p1, final Object p2,
        final Object p3, final Object p4, final Object p5,
        final Object p6, final Object p7, final Object p8) {
    logIfEnabled(FQCN, Level.TRACE, marker, message, p0, p1, p2, p3, p4, p5, p6, p7, p8);
}
 
Example #28
Source File: MarkerFilter.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final String msg,
        final Object p0, final Object p1) {
    return filter(marker);
}
 
Example #29
Source File: AbstractLogger.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public void trace(final Marker marker, final String message, final Object p0, final Object p1, final Object p2) {
    logIfEnabled(FQCN, Level.TRACE, marker, message, p0, p1, p2);
}
 
Example #30
Source File: SpaceConfigClient.java    From xyz-hub with Apache License 2.0 4 votes vote down vote up
protected abstract void getSelectedSpaces(Marker marker, SpaceAuthorizationCondition authorizedCondition,
SpaceSelectionCondition selectedCondition, Handler<AsyncResult<List<Space>>> handler);