org.apache.log4j.Priority Java Examples

The following examples show how to use org.apache.log4j.Priority. 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: SpliceLevel2OptimizerImpl.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
@SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT",justification = "Intentional")
public void trace(TraceLevel level, String traceString){

    Priority prio = Level.INFO;
    switch(level){
        case TRACE:
            prio =  Level.TRACE;
            break;
        case DEBUG:
            prio =  Level.DEBUG;
            break;
        case WARN:
            prio =  Level.WARN;
            break;
        case ERROR:
            prio =  Level.ERROR;
            break;
    }

    if (TRACE_LOGGER.isTraceEnabled()) {
        TRACE_LOGGER.log(prio,traceString);
    }
}
 
Example #2
Source File: ANSIConsoleAppender.java    From restcommander with Apache License 2.0 6 votes vote down vote up
/**
 * Get the appropriate control characters to change
 * the colour for the specified logging level.
 */
private String getColour(org.apache.log4j.Level level) {
    switch (level.toInt()) {
        case Priority.FATAL_INT:
            return FATAL_COLOUR;
        case Priority.ERROR_INT:
            return ERROR_COLOUR;
        case Priority.WARN_INT:
            return WARN_COLOUR;
        case Priority.INFO_INT:
            return INFO_COLOUR;
        case Priority.DEBUG_INT:
            return DEBUG_COLOUR;
        default:
            return TRACE_COLOUR;
    }
}
 
Example #3
Source File: EclipseLogAppender.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private int mapLevel(Level level) {
	switch (level.toInt()) {
	case Priority.DEBUG_INT:
	case Priority.INFO_INT:
		return IStatus.INFO;

	case Priority.WARN_INT:
		return IStatus.WARNING;

	case Priority.ERROR_INT:
	case Priority.FATAL_INT:
		return IStatus.ERROR;

	default:
		return IStatus.INFO;
	}
}
 
Example #4
Source File: JListView.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public
   void run() {

     while(true) {
synchronized(this) {
  try {
    this.wait();
  } catch(Exception e) {
  }
}
for(int i = 0; i < burst; i++) {
  LoggingEvent event = new LoggingEvent("x", cat, Priority.DEBUG, 
					"Message "+counter, null);

  event.getThreadName();    
  if(counter % 50 == 0) {
    //event.throwable = new Exception("hello "+counter);
  }
  counter++;
  view.add(event);
}
     }
   }
 
Example #5
Source File: LoggingEventTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
   * Tests LoggingEvent.getLocationInfo() when no FQCN is specified.
   * See bug 41186.
   */
public void testLocationInfoNoFQCN() {
    Category root = Logger.getRootLogger();
 Priority level = Level.INFO;
    LoggingEvent event =
      new LoggingEvent(
        null, root, 0L,  level, "Hello, world.", null);
    LocationInfo info = event.getLocationInformation();
 //
 //  log4j 1.2 returns an object, its layout doesn't check for nulls.
 //  log4j 1.3 returns a null.
 //
 assertNotNull(info);
 if (info != null) {
    assertEquals("?", info.getLineNumber());
 assertEquals("?", info.getClassName());
 assertEquals("?", info.getFileName());
 assertEquals("?", info.getMethodName());
 }
}
 
Example #6
Source File: EclipseLogAppender.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private int mapLevel(Level level) {
	switch (level.toInt()) {
		case Priority.DEBUG_INT:
		case Priority.INFO_INT:
			return IStatus.INFO;

		case Priority.WARN_INT:
			return IStatus.WARNING;

		case Priority.ERROR_INT:
		case Priority.FATAL_INT:
			return IStatus.ERROR;

		default:
			return IStatus.INFO;
	}
}
 
Example #7
Source File: ThreadLocalAwareLogger.java    From olat with Apache License 2.0 6 votes vote down vote up
@Override
public void l7dlog(Priority priority, String key, Object[] params, Throwable t) {
    if (isForcedToLog(priority)) {
        // from super.l7dlog:
        String pattern = getResourceBundleString(key);
        String msg;
        if (pattern == null)
            msg = key;
        else
            msg = java.text.MessageFormat.format(pattern, params);

        final Appender forcedAppender = getForcedAppender();

        // force the logging and modify the log message (the latter might return the original message)
        if (forcedAppender != null) {
            // only call the forced appender
            forcedAppender.doAppend(new LoggingEvent(FQCN, this, priority, modifyLogMessage(msg), t));
        } else {
            // go via the normal appenders
            forcedLog(FQCN, priority, modifyLogMessage(msg), t);
        }

    } else {
        super.l7dlog(priority, key, params, t);
    }
}
 
Example #8
Source File: ThreadLocalAwareLogger.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * Logger worker method - does the actual checks whether the given message should be logged at the given priority - taking into account this logger's loglevel plus
 * the threadLocalLogLevel.
 * 
 * @param priority
 *            the priority at which the given message should be logged
 * @param message
 *            the message which should be logged (or not, depending on levels)
 */
private final void threadLocalAwareLog(String fQCN, Priority priority, Object message, Throwable t) {
    if (isForcedToLog(priority)) {

        final Appender forcedAppender = getForcedAppender();

        // force the logging and modify the log message (the latter might return the original message)
        if (forcedAppender != null) {
            // only call the forced appender
            forcedAppender.doAppend(new LoggingEvent(fQCN, this, priority, modifyLogMessage(message), t));
        } else {
            // go via the normal appenders
            forcedLog(fQCN, priority, modifyLogMessage(message), t);
        }

    } else {

        // else not forced to log - use default behaviour
        super.log(fQCN, priority, message, t);

    }
}
 
Example #9
Source File: ExpandCompositeTerms.java    From datawave with Apache License 2.0 5 votes vote down vote up
private void printJexlNode(JexlNode queryTree, String message, Priority priority) {
    if (log.isEnabledFor(priority)) {
        log.log(priority, message);
        for (String line : PrintingVisitor.formattedQueryStringList(queryTree)) {
            log.log(priority, line);
        }
    }
}
 
Example #10
Source File: MyLogger.java    From AlgoTrader with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialises the timestamp to Esper-Time
 */
protected void forcedLog(String fqcn, Priority level, Object message, Throwable t) {

	long time = System.currentTimeMillis();
	try {
		String strategyName = StrategyUtil.getStartedStrategyName();
		RuleService ruleService = ServiceLocator.commonInstance().getRuleService();
		if (ruleService.isInitialized(strategyName) && !ruleService.isInternalClock(strategyName)) {
			time = ruleService.getCurrentTime(strategyName);
		}
	} catch (Exception e) {
		// do nothing spring services are probably not initialized yet
	}
	callAppenders(new LoggingEvent(fqcn, this, time, level, message, t));
}
 
Example #11
Source File: PropertySetter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Convert <code>val</code> a String parameter to an object of a
 * given type.
 */
protected Object convertArg(String val, Class type) {
    if (val == null) {
        return null;
    }

    String v = val.trim();
    if (String.class.isAssignableFrom(type)) {
        return val;
    } else if (Integer.TYPE.isAssignableFrom(type)) {
        return Integer.parseInt(v);
    } else if (Long.TYPE.isAssignableFrom(type)) {
        return Long.parseLong(v);
    } else if (Boolean.TYPE.isAssignableFrom(type)) {
        if ("true".equalsIgnoreCase(v)) {
            return Boolean.TRUE;
        } else if ("false".equalsIgnoreCase(v)) {
            return Boolean.FALSE;
        }
    } else if (Priority.class.isAssignableFrom(type)) {
        return org.apache.log4j.helpers.OptionConverter.toLevel(v, Level.DEBUG);
    } else if (ErrorHandler.class.isAssignableFrom(type)) {
        return OptionConverter.instantiateByClassName(v,
                ErrorHandler.class, null);
    }
    return null;
}
 
Example #12
Source File: AssociationHandler.java    From sctp with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public  HandlerResult handleNotification(PeerAddressChangeNotification notification, AssociationImpl associtaion) {
	//associtaion.peerSocketAddress = notification.address();
	if(logger.isEnabledFor(Priority.WARN)){
		logger.warn(String.format("Peer Address changed to=%s for Association=%s", notification.address(), associtaion.getName()));
	}
	return HandlerResult.CONTINUE;
}
 
Example #13
Source File: PropertySetter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Convert <code>val</code> a String parameter to an object of a
 * given type.
 * @param val The value to convert.
 * @param type The type of the value to convert to.
 * @return The result of the conversion.
 */
protected Object convertArg(String val, Class<?> type) {
    if (val == null) {
        return null;
    }

    String v = val.trim();
    if (String.class.isAssignableFrom(type)) {
        return val;
    } else if (Integer.TYPE.isAssignableFrom(type)) {
        return Integer.parseInt(v);
    } else if (Long.TYPE.isAssignableFrom(type)) {
        return Long.parseLong(v);
    } else if (Boolean.TYPE.isAssignableFrom(type)) {
        if ("true".equalsIgnoreCase(v)) {
            return Boolean.TRUE;
        } else if ("false".equalsIgnoreCase(v)) {
            return Boolean.FALSE;
        }
    } else if (Priority.class.isAssignableFrom(type)) {
        return org.apache.log4j.helpers.OptionConverter.toLevel(v, Level.DEBUG);
    } else if (ErrorHandler.class.isAssignableFrom(type)) {
        return OptionConverter.instantiateByClassName(v,
                ErrorHandler.class, null);
    }
    return null;
}
 
Example #14
Source File: ThreadLocalAwareLogger.java    From olat with Apache License 2.0 5 votes vote down vote up
@Override
public void l7dlog(Priority priority, String key, Throwable t) {
    if (isForcedToLog(priority)) {
        // from super.l7dlog:

        String msg = getResourceBundleString(key);
        // if message corresponding to 'key' could not be found in the
        // resource bundle, then default to 'key'.
        if (msg == null) {
            msg = key;
        }

        final Appender forcedAppender = getForcedAppender();

        // force the logging and modify the log message (the latter might return the original message)
        if (forcedAppender != null) {
            // only call the forced appender
            forcedAppender.doAppend(new LoggingEvent(FQCN, this, priority, modifyLogMessage(msg), t));
        } else {
            // go via the normal appenders
            forcedLog(FQCN, priority, modifyLogMessage(msg), t);
        }

    } else {
        super.l7dlog(priority, key, t);
    }
}
 
Example #15
Source File: BasicTest.java    From cassandra-log4j-appender with Apache License 2.0 5 votes vote down vote up
@Test
public void testThrowableSuccess() throws Exception
{
    CassandraAppender appender = new CassandraAppender();
    LoggingEvent event = new LoggingEvent(BasicTest.class.getName(),
                                          Category.getInstance(BasicTest.class),
                                          Priority.WARN,
                                          "test 12",
                                          new Exception("boom"));
    appender.doAppend(event);
}
 
Example #16
Source File: BasicTest.java    From cassandra-log4j-appender with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoThrowableSuccess() throws Exception
{
    CassandraAppender appender = new CassandraAppender();
    LoggingEvent event = new LoggingEvent(BasicTest.class.getName(),
                                          Category.getInstance(BasicTest.class),
                                          Priority.WARN,
                                          "test 12",
                                          null);
    appender.doAppend(event);
}
 
Example #17
Source File: TestTaskLogAppender.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
* test TaskLogAppender 
*/
 @SuppressWarnings("deprecation")
 @Test (timeout=5000)
 public void testTaskLogAppender(){
   TaskLogAppender appender= new TaskLogAppender();
   
   System.setProperty(TaskLogAppender.TASKID_PROPERTY,"attempt_01_02_m03_04_001");
   System.setProperty(TaskLogAppender.LOGSIZE_PROPERTY, "1003");
   appender.activateOptions();
   assertEquals(appender.getTaskId(), "attempt_01_02_m03_04_001");
   assertEquals(appender.getTotalLogFileSize(),1000);
   assertEquals(appender.getIsCleanup(),false);
   
   // test writer   
   Writer writer= new StringWriter();
   appender.setWriter(writer);
   Layout layout =  new PatternLayout("%-5p [%t]: %m%n");
   appender.setLayout(layout);
   Category logger= Logger.getLogger(getClass().getName());
   LoggingEvent event = new LoggingEvent("fqnOfCategoryClass", logger, Priority.INFO, "message", new Throwable());
   appender.append(event);
   appender.flush() ;
   appender.close();
   assertTrue(writer.toString().length()>0);
   
   // test cleanup should not changed 
   appender= new TaskLogAppender();
   appender.setIsCleanup(true);
   appender.activateOptions();
   assertEquals(appender.getIsCleanup(),true);

 
 }
 
Example #18
Source File: Synch.java    From pegasus with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a AWSJob Queue corresponding to the description in the JSON file conforming to AWS
 * Batch HTTP specification
 *
 * @param json the file
 * @param computeEnvironmentArn the CE ARN to assign if it does not exist
 * @param name the name to assign if does not exist
 * @return job queue ARN
 */
public String createQueue(File json, String computeEnvironmentArn, String name) {
    // CreateJobQueueRequest jobQueueRequest =getTestJobQueueRequest( mPrefix ,
    // JOB_QUEUE_SUFFIX, computeEnvironmentArn );
    CreateJobQueueRequest jobQueueRequest =
            new JobQueue().createJobQueueRequestFromHTTPSpec(json, computeEnvironmentArn, name);
    CreateJobQueueResponse jobQueueResponse = mBatchClient.createJobQueue(jobQueueRequest);
    String arn = jobQueueResponse.jobQueueArn();

    mLogger.info("Created Job Queue " + arn);
    mLogger.debug("Created Job Queue " + jobQueueResponse);

    boolean valid = false;
    int retry = 0;
    long sleepTime = 2 * 1000;
    while (!valid && retry < 3) {
        // query to see if it has been enabled
        DescribeJobQueuesRequest describeJobQueue =
                DescribeJobQueuesRequest.builder().jobQueues(arn).build();
        DescribeJobQueuesResponse describeJQResponse =
                mBatchClient.describeJobQueues(describeJobQueue);
        for (JobQueueDetail detail : describeJQResponse.jobQueues()) {
            mLogger.debug(detail.jobQueueArn() + "," + detail.state() + "," + detail.status());
            valid = detail.status().equals(JQStatus.VALID.toString());
        }
        try {
            Thread.sleep(sleepTime);
        } catch (InterruptedException ex) {
            mLogger.log(Priority.ERROR, null, ex);
        }
    }
    if (!valid) {
        throw new RuntimeException("Job Queue still not valid after 3 retries " + arn);
    }

    return arn;
}
 
Example #19
Source File: TestTaskLogAppender.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
* test TaskLogAppender 
*/
 @SuppressWarnings("deprecation")
 @Test (timeout=5000)
 public void testTaskLogAppender(){
   TaskLogAppender appender= new TaskLogAppender();
   
   System.setProperty(TaskLogAppender.TASKID_PROPERTY,"attempt_01_02_m03_04_001");
   System.setProperty(TaskLogAppender.LOGSIZE_PROPERTY, "1003");
   appender.activateOptions();
   assertEquals(appender.getTaskId(), "attempt_01_02_m03_04_001");
   assertEquals(appender.getTotalLogFileSize(),1000);
   assertEquals(appender.getIsCleanup(),false);
   
   // test writer   
   Writer writer= new StringWriter();
   appender.setWriter(writer);
   Layout layout =  new PatternLayout("%-5p [%t]: %m%n");
   appender.setLayout(layout);
   Category logger= Logger.getLogger(getClass().getName());
   LoggingEvent event = new LoggingEvent("fqnOfCategoryClass", logger, Priority.INFO, "message", new Throwable());
   appender.append(event);
   appender.flush() ;
   appender.close();
   assertTrue(writer.toString().length()>0);
   
   // test cleanup should not changed 
   appender= new TaskLogAppender();
   appender.setIsCleanup(true);
   appender.activateOptions();
   assertEquals(appender.getIsCleanup(),true);

 
 }
 
Example #20
Source File: PropertyGetter.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected
boolean isHandledType(Class type) {
  return String.class.isAssignableFrom(type) ||
    Integer.TYPE.isAssignableFrom(type) ||
    Long.TYPE.isAssignableFrom(type)    ||
    Boolean.TYPE.isAssignableFrom(type) ||
    Priority.class.isAssignableFrom(type);
}
 
Example #21
Source File: MyTableModel.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Sets the priority to filter events on. Only events of equal or higher
 * property are now displayed.
 *
 * @param aPriority the priority to filter on
 */
public void setPriorityFilter(Priority aPriority) {
    synchronized (mLock) {
        mPriorityFilter = aPriority;
        updateFilteredEvents(false);
    }
}
 
Example #22
Source File: RequestBasedLogLevelManager.java    From olat with Apache License 2.0 5 votes vote down vote up
/** internal helper method which takes care of the actual modifying of the ip to loglevel/appender map **/
private void setLogLevelAndAppenderForRemoteAddr(String remoteAddr, Priority level, Appender appender) {
    if (level == null) {
        remoteAddrs2LogConfigs.remove(remoteAddr);
    } else {
        remoteAddrs2LogConfigs.put(remoteAddr, new LogConfig(level, appender));
    }
}
 
Example #23
Source File: LoggerUtilTest.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void teardown()
{
  for (Map.Entry<AppenderSkeleton, Priority> e : appenderLevelMap.entrySet()) {
    e.getKey().setThreshold(e.getValue());
  }
}
 
Example #24
Source File: JTableAppender.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public
void actionPerformed(ActionEvent e) {
  System.out.println("Action occured");

  LoggingEvent event = new LoggingEvent("x", cat, Priority.DEBUG, 
			    "Message "+j, null);
  
  if(j % 5 == 0) {
    //event.throwable = new Exception("hello "+j);
  }
  j++;
  appender.add(event);
}
 
Example #25
Source File: LogNumberPatternConverter.java    From olat with Apache License 2.0 5 votes vote down vote up
public String convert(LoggingEvent event) {
    if (event.getLevel().toInt() == Priority.ERROR_INT) {
        return "N" + Tracing.nodeId + "-E" + String.valueOf(errorCounter.incrementAndGet());
    } else if (event.getLevel().toInt() == Priority.WARN_INT) {
        return "N" + Tracing.nodeId + "-W" + String.valueOf(warnCounter.incrementAndGet());
    } else if (event.getLevel().toInt() == Priority.INFO_INT) {
        return "N" + Tracing.nodeId + "-I" + String.valueOf(infoCounter.incrementAndGet());
    } else if (event.getLevel().toInt() == Priority.DEBUG_INT) {
        return "N" + Tracing.nodeId + "-D" + String.valueOf(debugCounter.incrementAndGet());
    }

    return "n/a";
}
 
Example #26
Source File: LoggingEventTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
   * Tests LoggingEvent.level.
   * @deprecated
   */
public void testLevel() {
    Category root = Logger.getRootLogger();
    Priority info = Level.INFO;
    String catName = Logger.class.toString();
    LoggingEvent event =
      new LoggingEvent(
        catName, root, 0L,  info, "Hello, world.", null);
    Priority error = Level.ERROR;
    event.level = error;
    assertEquals(Level.ERROR, event.level);
}
 
Example #27
Source File: Synch.java    From pegasus with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a compute environment corresponding to the description in the JSON file conforming to
 * AWS Batch HTTP specification
 *
 * @param json the file
 * @param name the name to assign if does not exist
 * @return compute environment ARN
 */
public String createComputeEnvironment(File json, String name) {
    // CreateComputeEnvironmentRequest computeEnvRequest = getTestComputeEnvironmentRequest(
    // mPrefix , COMPUTE_ENV_SUFFIX);
    CreateComputeEnvironmentRequest computeEnvRequest =
            new ComputeEnvironment().createComputeEnvironmentRequestFromHTTPSpec(json, name);
    CreateComputeEnvironmentResponse computeEnvResponse =
            mBatchClient.createComputeEnvironment(computeEnvRequest);
    String arn = computeEnvResponse.computeEnvironmentArn();
    mLogger.debug("Created Compute Environment " + computeEnvResponse);
    boolean valid = false;
    int retry = 0;
    long sleepTime = 2 * 1000;
    while (!valid && retry < 3) {
        // query to see if it has been enabled
        DescribeComputeEnvironmentsRequest describeComputeEnv =
                DescribeComputeEnvironmentsRequest.builder().computeEnvironments(arn).build();
        DescribeComputeEnvironmentsResponse describeCEResponse =
                mBatchClient.describeComputeEnvironments(describeComputeEnv);
        for (ComputeEnvironmentDetail detail : describeCEResponse.computeEnvironments()) {
            mLogger.debug(
                    detail.computeEnvironmentArn()
                            + ","
                            + detail.state()
                            + ","
                            + detail.status());
            valid = detail.status().equals(CEStatus.VALID.toString());
        }
        try {
            Thread.sleep(sleepTime);
        } catch (InterruptedException ex) {
            mLogger.log(Priority.ERROR, null, ex);
        }
        sleepTime += sleepTime;
    }
    if (!valid) {
        throw new RuntimeException(
                "Compute Environment still not valid after 3 retries " + arn);
    }
    mLogger.info("Compute Environment Enabled " + arn);
    return arn;
}
 
Example #28
Source File: NOPLogger.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/** {@inheritDoc} */
public boolean isEnabledFor(final Priority level) {
  return false;
}
 
Example #29
Source File: NOPLogger.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/** {@inheritDoc} */
public void l7dlog(final Priority priority, final String key, final Throwable t) {
}
 
Example #30
Source File: NOPLogger.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/** {@inheritDoc} */
public void l7dlog(final Priority priority, final String key,  final Object[] params, final Throwable t) {
}