Java Code Examples for org.apache.log4j.Level

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project big-data-plugin, under directory /src/org/pentaho/di/job/.

Source file: JobEntryUtils.java

  18 
vote

public static void attachAppenderTo(Appender appender,LogLevel logLevel,Map<String,Level> logLevelCache,String... logNames){
  for (  String logName : logNames) {
    Logger logger=findLogger(logName);
    logger.addAppender(appender);
    Level level=org.pentaho.di.core.logging.KettleLogChannelAppender.LOG_LEVEL_MAP.get(logLevel);
    if (level != null) {
      logLevelCache.put(logger.getName(),logger.getLevel());
      logger.setLevel(level);
    }
  }
}
 

Example 2

From project des, under directory /daemon/lib/apache-log4j-1.2.16/src/main/java/org/apache/log4j/jmx/.

Source file: HierarchyDynamicMBean.java

  18 
vote

public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
  if (attribute == null) {
    throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"),"Cannot invoke a setter of " + dClassName + " with null attribute");
  }
  String name=attribute.getName();
  Object value=attribute.getValue();
  if (name == null) {
    throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null"),"Cannot invoke the setter of " + dClassName + " with null attribute name");
  }
  if (name.equals(THRESHOLD)) {
    Level l=OptionConverter.toLevel((String)value,hierarchy.getThreshold());
    hierarchy.setThreshold(l);
  }
}
 

Example 3

From project ISAvalidator-ISAconverter-BIImanager, under directory /import_layer/src/test/java/org/isatools/isatab/isaconfigurator/.

Source file: ISAConfigurationBatchTest.java

  18 
vote

protected Set<String> getValidatorReport(List<TabLoggingEventWrapper> logResult){
  Set<String> messages=new HashSet<String>();
  for (  TabLoggingEventWrapper tlew : logResult) {
    Level eventLevel=tlew.getLogEvent().getLevel();
    if (eventLevel.equals(Level.ERROR)) {
      messages.add(tlew.getFormattedMessage());
    }
  }
  return messages;
}
 

Example 4

From project Amoeba-for-Aladdin, under directory /src/java/com/meidusa/amoeba/net/.

Source file: ServerableConnectionManager.java

  17 
vote

protected void willStart(){
  super.willStart();
  try {
    ssocket=ServerSocketChannel.open();
    ssocket.configureBlocking(false);
    InetSocketAddress isa=null;
    if (ipAddress != null) {
      isa=new InetSocketAddress(ipAddress,port);
    }
 else {
      isa=new InetSocketAddress(port);
    }
    ssocket.socket().bind(isa);
    registerServerChannel(ssocket);
    Level level=log.getLevel();
    log.setLevel(Level.INFO);
    log.info("Server listening on " + isa + ".");
    log.setLevel(level);
  }
 catch (  IOException ioe) {
    log.error("Failure listening to socket on port '" + port + "'.",ioe);
    System.exit(-1);
  }
}
 

Example 5

From project artimate, under directory /artimate-model/src/main/java/fr/loria/parole/artimate/model/.

Source file: PosConcatenator.java

  17 
vote

/** 
 * Concatenate all <tt>*.pos</tt> files in directory <code>arg[0]</code> to a single target <tt>.pos</tt> file <code>args[1]</code>.
 * @param args source directory, target file
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
  String inputDirectoryName=args[0];
  String outputFileName=args[1];
  String logFormat=System.getProperty("log.format");
  String logLevel=System.getProperty("log.level");
  if (logFormat == null || logFormat.isEmpty()) {
    logFormat="[%c{1}] [%p] %m%n";
  }
  ConsoleAppender consoleAppender=new ConsoleAppender(new PatternLayout(logFormat));
  BasicConfigurator.configure(consoleAppender);
  Level level=Level.toLevel(logLevel);
  Logger.getRootLogger().setLevel(level);
  File inputDirectory=new File(inputDirectoryName);
  PatternFilenameFilter posFileFilter=new PatternFilenameFilter(".*\\.pos");
  File[] inputFiles=inputDirectory.listFiles(posFileFilter);
  if (inputFiles == null) {
    logger.error("Could not find input *.pos files in " + inputDirectoryName);
    throw new IOException();
  }
  logger.debug("Found " + inputFiles.length + " input files");
  File outputFile=new File(outputFileName);
  Files.createParentDirs(outputFile);
  FileOutputStream output=Files.newOutputStreamSupplier(outputFile).getOutput();
  logger.info("Appending to " + outputFileName);
  for (  File input : inputFiles) {
    Files.copy(input,output);
    logger.debug("Appended " + input.getName());
  }
}
 

Example 6

From project beanmill_1, under directory /src/main/java/com/traxel/lumbermill/event/.

Source file: Log4jEvent.java

  17 
vote

/** 
 * --------------------------------------------- Class API --------------------------------------------
 * @param observed  DOCUMENT ME!
 * @return  DOCUMENT ME!
 */
private static Severity estimateSeverity(final Level observed){
  final Iterator it;
  Level known;
  Level estimated;
  Severity severity;
  boolean moreThanObserved;
  boolean lessThanEstimated;
  estimated=Level.FATAL;
  it=SEVERITY_MAP.keySet().iterator();
  while (it.hasNext()) {
    known=(Level)it.next();
    if (estimated == null) {
      estimated=known;
    }
 else {
      moreThanObserved=known.toInt() > observed.toInt();
      lessThanEstimated=known.toInt() < estimated.toInt();
      if (moreThanObserved && lessThanEstimated) {
        estimated=known;
      }
    }
  }
  severity=(Severity)SEVERITY_MAP.get(estimated);
  if (severity == null) {
    severity=Severity.LEVEL_8;
  }
  return severity;
}
 

Example 7

From project flyway, under directory /flyway-ant/src/main/java/com/googlecode/flyway/ant/.

Source file: AntLogAppender.java

  17 
vote

protected void append(LoggingEvent event){
  if (antProject == null) {
    return;
  }
  Level level=event.getLevel();
  String text=this.layout.format(event);
  Throwable throwable=null;
  if (event.getThrowableInformation() != null) {
    throwable=event.getThrowableInformation().getThrowable();
  }
  Task task=antProject.getThreadTask(Thread.currentThread());
  if (Level.TRACE.equals(level)) {
    antProject.log(task,text,throwable,Project.MSG_DEBUG);
  }
 else   if (Level.DEBUG.equals(level)) {
    antProject.log(task,text,throwable,Project.MSG_VERBOSE);
  }
 else   if (Level.INFO.equals(level)) {
    antProject.log(task,text,throwable,Project.MSG_INFO);
  }
 else   if (Level.WARN.equals(level)) {
    antProject.log(task,text,throwable,Project.MSG_WARN);
  }
 else   if (Level.ERROR.equals(level) || Level.FATAL.equals(level)) {
    antProject.log(task,text,throwable,Project.MSG_ERR);
  }
 else {
    antProject.log(task,text,throwable,Project.MSG_ERR);
  }
}
 

Example 8

From project ALP, under directory /workspace/alp-selenium/src/main/java/com/lohika/alp/selenium/.

Source file: AlpWebDriverFactory.java

  15 
vote

/** 
 * Create WebDriver object wrapped with ALP logging that allow implements autologging
 * @param SeleniumUrl - represent target Selenium standalone server for WebDriver that will be created 
 * @param capabilities - DesiredCapabilities for WebDriver that will be created  
 * @return created WebDriver instance 
 * @throws MalformedURLException the malformed url exception
 */
public static WebDriver getDriver(String SeleniumUrl,DesiredCapabilities capabilities) throws MalformedURLException {
  Logger alpSeleniumLogger=Logger.getLogger("com.lohika.alp.selenium");
  if (alpSeleniumLogger.getLevel() == null)   alpSeleniumLogger.setLevel(Level.DEBUG);
  URL remoteAddress=new URL(SeleniumUrl);
  CommandExecutor commandExecutor=new HttpCommandExecutor(remoteAddress);
  WebDriver driver;
  String name=capabilities.getBrowserName();
  WebDriverConfigurator webDriverConfigurator=new WebDriverConfigurator(name);
  capabilities=webDriverConfigurator.configure(capabilities);
  driver=new RemoteWebDriverTakeScreenshotFix(commandExecutor,capabilities);
  LogElementsSeleniumFactory logObjectsFactory=new LogElementsSeleniumFactoryJAXB();
  LogElementsSeleniumFactory elementsFactory=new LogElementsSeleniumFactoryJAXB();
  WebDriverEventListener listener=new LoggingWebDriverListener(elementsFactory);
  driver=new EventFiringWebDriver(driver);
  ((EventFiringWebDriver)driver).register(listener);
  driver=new LoggingWebDriver(driver,name,logObjectsFactory);
  Logger seleniumLogger=Logger.getLogger("selenium-logging");
  if (seleniumLogger != null)   try {
    String levelStr=seleniumLogger.getLevel().toString();
    log.debug("java.util.logging.Level for selenium: " + levelStr);
    java.util.logging.Level level=java.util.logging.Level.parse(levelStr);
    RemoteWebDriverTakeScreenshotFix.setLogLevel(level);
  }
 catch (  IllegalArgumentException e) {
    log.warn("Unable turn off native selenium logging");
  }
catch (  NullPointerException e) {
    log.warn("Unable to get log level for native selenium logging");
  }
  return driver;
}
 

Example 9

From project asterisk-java, under directory /src/main/java/org/asteriskjava/util/internal/.

Source file: Log4JLogger.java

  15 
vote

/** 
 * Log a message to the Log4j Logger with <code>TRACE</code> priority. Currently logs to <code>DEBUG</code> level in Log4J.
 */
public void trace(Object message){
  if (IS12) {
    getLogger().log(FQCN,(Priority)Level.DEBUG,message,null);
  }
 else {
    getLogger().log(FQCN,Level.DEBUG,message,null);
  }
}
 

Example 10

From project atlas, under directory /src/main/java/com/ning/atlas/logging/.

Source file: ColorizedAppender.java

  15 
vote

@Override protected void append(LoggingEvent event){
  final String line;
switch (event.getLevel().toInt()) {
case Level.ERROR_INT:
    line=format(error,event);
  break;
case Level.WARN_INT:
line=format(warn,event);
break;
case Level.INFO_INT:
line=format(info,event);
break;
case Level.DEBUG_INT:
line=format(debug,event);
break;
default :
line=format(NO_OP,event);
break;
}
writer.write(line);
writer.flush();
}
 

Example 11

From project aws-tasks, under directory /src/it/java/datameer/awstasks/aws/emr/.

Source file: EmrClusterTest.java

  15 
vote

@Before public void before(){
  Logger.getLogger("datameer.awstasks").setLevel(Level.DEBUG);
  _s3Service=_ec2Conf.createS3Service();
  _s3Bucket=_s3Service.createBucket(S3BucketTest.AWS_TEST_BUCKET);
  List<S3ObjectSummary> s3Objects=_s3Service.listObjects(_s3Bucket.getName()).getObjectSummaries();
  for (  S3ObjectSummary s3ObjectSummary : s3Objects) {
    _s3Service.deleteObject(_s3Bucket.getName(),s3ObjectSummary.getKey());
  }
  _emrCluster=createEmrCluster();
}
 

Example 12

From project azkaban, under directory /azkaban/src/java/azkaban/jobs/builtin/.

Source file: ProcessJob.java

  15 
vote

private void logMessage(final String message){
  if (message.startsWith(Level.DEBUG.toString())) {
    String newMsg=message.substring(Level.DEBUG.toString().length());
    getLog().debug(newMsg);
  }
 else   if (message.startsWith(Level.ERROR.toString())) {
    String newMsg=message.substring(Level.ERROR.toString().length());
    getLog().error(newMsg);
  }
 else   if (message.startsWith(Level.INFO.toString())) {
    String newMsg=message.substring(Level.INFO.toString().length());
    getLog().info(newMsg);
  }
 else   if (message.startsWith(Level.WARN.toString())) {
    String newMsg=message.substring(Level.WARN.toString().length());
    getLog().warn(newMsg);
  }
 else   if (message.startsWith(Level.FATAL.toString())) {
    String newMsg=message.substring(Level.FATAL.toString().length());
    getLog().fatal(newMsg);
  }
 else   if (message.startsWith(Level.TRACE.toString())) {
    String newMsg=message.substring(Level.TRACE.toString().length());
    getLog().trace(newMsg);
  }
 else {
    getLog().log(_loggingLevel,message);
  }
}
 

Example 13

From project bpelunit, under directory /net.bpelunit.framework.client.ant/src/main/java/net/bpelunit/framework/ui/ant/.

Source file: BPELUnitAntRunner.java

  15 
vote

@Override public void configureLogging() throws ConfigurationException {
  Logger.getRootLogger().removeAllAppenders();
  for (  Logging log : fLoggers) {
    log.initialize();
    Logger.getRootLogger().addAppender(new WriterAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN),log.getOutputStream()));
    Logger.getRootLogger().setLevel(Level.toLevel(log.getLevel()));
  }
  if (fLoggers.isEmpty()) {
    Logger.getRootLogger().addAppender(new NullAppender());
  }
}
 

Example 14

From project candlepin, under directory /src/main/java/org/candlepin/config/.

Source file: LoggingConfig.java

  15 
vote

public void configure(Config config){
  Map<String,String> logLevels=config.configurationWithPrefix(PREFIX);
  for (  Entry<String,String> entry : logLevels.entrySet()) {
    String key=entry.getKey().replace(PREFIX,"");
    Logger.getLogger(key).setLevel(Level.toLevel(entry.getValue()));
  }
}
 

Example 15

From project Carolina-Digital-Repository, under directory /admin/src/main/java/edu/unc/lib/dl/util/.

Source file: Log4JManager.java

  15 
vote

/** 
 * Handles setting of logger levels by name, refusing to create logger if it doesn't already exist.
 * @param loggerName the name of the logger
 * @param level the level to be set.
 */
private void setLoggerLevel(String loggerName,Level level){
  Logger l=LogManager.getLoggerRepository().exists(loggerName);
  if (l != null) {
    l.setLevel(level);
  }
}
 

Example 16

From project cascading, under directory /src/hadoop/cascading/flow/hadoop/util/.

Source file: HadoopUtil.java

  15 
vote

public static void initLog4j(JobConf jobConf){
  String values=jobConf.get("log4j.logger",null);
  if (values == null || values.length() == 0)   return;
  String[] elements=values.split(",");
  for (  String element : elements) {
    String[] logger=element.split("=");
    Logger.getLogger(logger[0]).setLevel(Level.toLevel(logger[1]));
  }
}
 

Example 17

From project caseconductor-platform, under directory /utest-portal-webapp/src/main/java/com/utest/portal/log/.

Source file: RepositorySelector.java

  15 
vote

public static synchronized void init(final ServletContext servletContext) throws ServletException {
  if (!initialized) {
    defaultRepository=LogManager.getLoggerRepository();
    final RepositorySelector theSelector=new RepositorySelector();
    LogManager.setRepositorySelector(theSelector,guard);
    initialized=true;
  }
  final Hierarchy hierarchy=new Hierarchy(new RootLogger(Level.DEBUG));
  loadLog4JConfig(servletContext,hierarchy);
  final ClassLoader loader=Thread.currentThread().getContextClassLoader();
  repositories.put(loader,hierarchy);
}
 

Example 18

From project Chess_1, under directory /src/main/java/com/es/engines/.

Source file: UciEngine.java

  15 
vote

public void visit(EngineDebugCommand command){
  LOG.info("Engine Debug Command: debug={} toggle={}",command.debug,command.toggle);
  GuiInformationCommand infoCommand=new GuiInformationCommand();
  if (LOG.isDebugEnabled()) {
    infoCommand.setString("Turning off debugging mode");
    LogManager.getLogger(UciEngine.class).setLevel(Level.INFO);
  }
 else {
    infoCommand.setString("Turning on debugging mode");
    LogManager.getLogger(UciEngine.class).setLevel(Level.DEBUG);
  }
  this.communication.send(infoCommand);
}
 

Example 19

From project chililog-server, under directory /src/test/java/org/chililog/server/engine/.

Source file: InternalLog4JAppenderTest.java

  15 
vote

/** 
 * Test directory calling appender
 * @throws Exception
 */
@Test public void testDirect() throws Exception {
  InternalLog4JAppender appender=new InternalLog4JAppender();
  Date now=new Date();
  String msg="debug message";
  Logger logger=Logger.getLogger(InternalLog4JAppenderTest.class);
  LoggingEvent event=new LoggingEvent("com.chililog.server.engine",logger,now.getTime(),Level.DEBUG,msg,Thread.currentThread().getName(),null,null,null,null);
  appender.append(event);
  DBCollection coll=_db.getCollection(InternalLog4JAppender.MONGODB_COLLECTION_NAME);
  assertEquals(1,coll.find().count());
  DBObject dbObject=coll.findOne();
  assertNotNull(dbObject.get(RepositoryEntryBO.TIMESTAMP_FIELD_NAME));
  assertEquals("ChiliLogServer",dbObject.get(RepositoryEntryBO.SOURCE_FIELD_NAME));
  assertEquals(_machineName,dbObject.get(RepositoryEntryBO.HOST_FIELD_NAME));
  assertEquals(Severity.Debug.toCode(),dbObject.get(RepositoryEntryBO.SEVERITY_FIELD_NAME));
  assertEquals(msg,dbObject.get(RepositoryEntryBO.MESSAGE_FIELD_NAME));
  assertEquals((long)1,dbObject.get(BO.DOCUMENT_VERSION_FIELD_NAME));
  assertEquals(InternalLog4JAppenderTest.class.getName(),dbObject.get(InternalLog4JAppender.CATEGORY_FIELD_NAME));
  assertEquals(Thread.currentThread().getName(),dbObject.get(InternalLog4JAppender.THREAD_FIELD_NAME));
  return;
}
 

Example 20

From project cider, under directory /src/net/yacy/cider/util/.

Source file: Log.java

  15 
vote

private final static void enQueueLog(final Logger logger,final Level level,final String message){
  if (logRunnerThread == null || !logRunnerThread.isAlive()) {
    logger.log(level,message);
  }
 else {
    try {
      logQueue.put(new logEntry(logger,level,message));
    }
 catch (    InterruptedException e) {
      logger.log(level,message);
    }
  }
}
 

Example 21

From project Cinch, under directory /example/com/palantir/ptoss/cinch/example/.

Source file: Examples.java

  15 
vote

public static void initializeLogging(){
  Logger.getRootLogger().setLevel(Level.INFO);
  ConsoleAppender console=new ConsoleAppender();
  console.setWriter(new PrintWriter(System.out));
  console.setLayout(new PatternLayout("%d{ISO8601} %d %p [%t] %c - %m%n"));
  Logger.getRootLogger().addAppender(console);
}
 

Example 22

From project Cloud9, under directory /src/dist/edu/umd/hooka/.

Source file: CorpusVocabNormalizerAndNumberizer.java

  15 
vote

public void configure(JobConf job){
  sLogger.setLevel(Level.OFF);
  src=Language.languageForISO639_1(job.get(SRC_LANG));
  tgt=Language.languageForISO639_1(job.get(TGT_LANG));
  sLogger.debug("Source language: " + src.code());
  sLogger.debug("Target language: " + tgt.code());
  boolean useVocabServer=false;
  if (!useVocabServer) {
    if (vocE == null)     vocE=new VocabularyWritable();
    if (vocF == null)     vocF=new VocabularyWritable();
  }
 else {
    try {
      vocE=new VocabServerClient(job.get("ha.vocabserver.host"),Integer.parseInt(job.get("ha.vocabserver.port1")));
      vocF=new VocabServerClient(job.get("ha.vocabserver.host"),Integer.parseInt(job.get("ha.vocabserver.port2")));
    }
 catch (    IOException e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }
  lp=LanguagePair.languageForISO639_1Pair(src.code() + "-" + tgt.code());
  if (job.getBoolean("ha.trunc.use",true)) {
    sawp=AlignmentWordPreprocessor.CreatePreprocessor(lp,src,job);
    tawp=AlignmentWordPreprocessor.CreatePreprocessor(lp,tgt,job);
  }
 else {
    sawp=AlignmentWordPreprocessor.CreatePreprocessor(null,null,job);
    tawp=AlignmentWordPreprocessor.CreatePreprocessor(null,null,job);
  }
  job_=job;
}
 

Example 23

From project cloudify, under directory /USM/src/test/java/org/openspaces/usm/.

Source file: USMRollingFileAppenderTailerTest.java

  15 
vote

@Before public void before() throws Exception {
  final File logDir=new File(logsDirectory);
  FileSystemUtils.deleteRecursively(logDir);
  logDir.mkdirs();
  final File logFile=new File(logDir,String.format("%s%s",System.getProperty("file.separator"),LOG_FILENAME));
  final PatternLayout pl=new PatternLayout(LOG_PATTERN);
  rfp=new RollingFileAppender(pl,logFile.getCanonicalPath(),true);
  rfp.setImmediateFlush(true);
  rfp.setBufferedIO(false);
  rfp.setBufferSize(LOG_IO_BUFFER_SIZE_BYTES);
  rfp.setMaxBackupIndex(MAX_LOG_BACKUP_FILES);
  rfp.setMaxFileSize(MAX_LOG_FILE_SIZE);
  logger.setLevel(Level.INFO);
  logger.addAppender(rfp);
  logger.getAllAppenders();
  logger.info("Log directory: " + logDir.getAbsolutePath());
}
 

Example 24

From project commons-logging, under directory /src/test/org/apache/commons/logging/log4j/log4j12/.

Source file: Log4j12StandardTests.java

  15 
vote

public void setUpTestAppender(List logEvents){
  TestAppender appender=new TestAppender(logEvents);
  Logger rootLogger=Logger.getRootLogger();
  rootLogger.removeAllAppenders();
  rootLogger.addAppender(appender);
  rootLogger.setLevel(Level.INFO);
}
 

Example 25

From project components-ness-logging, under directory /src/test/java/com/nesscomputing/logging/.

Source file: TestDebugLogging.java

  15 
vote

@Test public void testSimple(){
  final String msg="Hello";
  log.trace(msg);
  Assert.assertThat(recordingAppender.getContents(),is(""));
  Assert.assertThat(recordingAppender.getLevel(),is(nullValue()));
  Assert.assertThat(recordingAppender.getThrowable(),is(nullValue()));
  recordingAppender.clear();
  log.debug(msg);
  Assert.assertThat(recordingAppender.getContents(),is(msg + "\n"));
  Assert.assertThat(recordingAppender.getLevel(),is(Level.DEBUG));
  Assert.assertThat(recordingAppender.getThrowable(),is(nullValue()));
  recordingAppender.clear();
  log.info(msg);
  Assert.assertThat(recordingAppender.getContents(),is(msg + "\n"));
  Assert.assertThat(recordingAppender.getLevel(),is(Level.INFO));
  Assert.assertThat(recordingAppender.getThrowable(),is(nullValue()));
  recordingAppender.clear();
  log.warn(msg);
  Assert.assertThat(recordingAppender.getContents(),is(msg + "\n"));
  Assert.assertThat(recordingAppender.getLevel(),is(Level.WARN));
  Assert.assertThat(recordingAppender.getThrowable(),is(nullValue()));
  recordingAppender.clear();
  log.error(msg);
  Assert.assertThat(recordingAppender.getContents(),is(msg + "\n"));
  Assert.assertThat(recordingAppender.getLevel(),is(Level.ERROR));
  Assert.assertThat(recordingAppender.getThrowable(),is(nullValue()));
}
 

Example 26

From project components-ness-tracking, under directory /src/test/java/com/nesscomputing/tracking/.

Source file: TestLogging.java

  15 
vote

@Override protected void service(HttpServletRequest filterReq,HttpServletResponse filterRes) throws ServletException, IOException {
  Assert.assertThat(trackingTokenProvider.get().getValue(),is(value));
  recordingAppender.clear();
  log.info("Hello, World");
  Assert.assertThat(recordingAppender.getContents(),is(value.toString() + " - Hello, World\n"));
  Assert.assertThat(recordingAppender.getLevel(),is(Level.INFO));
  Assert.assertThat(recordingAppender.getThrowable(),is(nullValue()));
}
 

Example 27

From project core_1, under directory /common/src/main/java/org/switchyard/common/version/.

Source file: Versions.java

  15 
vote

/** 
 * Logs each Version returned by  {@link #getSwitchYardVersions()}.
 * @param logger the Logger to log to
 * @param level the Level to log at
 */
public static void logSwitchYardVersions(Logger logger,Level level){
  if (logger.isEnabledFor(level)) {
    for (    Version version : getSwitchYardVersions()) {
      logger.log(level,version);
    }
  }
}
 

Example 28

From project crammer, under directory /src/main/java/uk/ac/ebi/ena/sra/cram/encoding/.

Source file: ArithCodec.java

  15 
vote

@Override public long write(BitOutputStream bos,byte[] object) throws IOException {
  this.baos.reset();
  curBit=0;
  curByte=0;
  min=0;
  max=1;
  localMin=0;
  localMax=1;
  this.bitCount=0;
  try {
    for (int i=0; i < object.length; i++)     encodeCharacter(bos,this.map[object[i] & 0xFF]);
    encodeCharacter(bos,this.map[this.TERMINATOR]);
    encodeCharacter(bos,this.map[this.TERMINATOR]);
    flush(bos);
  }
 catch (  Exception ex) {
    Logger.getLogger(ArithCodec.class.getName()).log(Level.FATAL,null,ex);
  }
  return this.bitCount;
}
 

Example 29

From project crunch, under directory /crunch/src/main/java/org/apache/crunch/impl/mr/.

Source file: MRPipeline.java

  15 
vote

@Override public void enableDebug(){
  getConfiguration().setBoolean(RuntimeParameters.DEBUG,true);
  Logger crunchInfoLogger=LogManager.getLogger("org.apache.crunch");
  Appender console=crunchInfoLogger.getAppender("A");
  if (console != null) {
    Logger hadoopLogger=LogManager.getLogger("org.apache.hadoop");
    hadoopLogger.setLevel(Level.WARN);
    hadoopLogger.addAppender(console);
  }
 else {
    LOG.warn("Could not find console appender named 'A' for writing Hadoop warning logs");
  }
}
 

Example 30

From project EMF-IncQuery, under directory /plugins/org.eclipse.viatra2.patternlanguage.emf.ui/src/org/eclipse/viatra2/patternlanguage/ui/.

Source file: EclipseLogAppender.java

  15 
vote

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 31

From project empire-db, under directory /empire-db-maven-plugin/src/main/java/org/apache/empire/db/maven/.

Source file: CodeGenMojo.java

  15 
vote

@Override protected void append(LoggingEvent event){
  if (Level.INFO.equals(event.getLevel())) {
    mojo.getLog().info(String.valueOf(event.getMessage()));
  }
 else   if (Level.ERROR.equals(event.getLevel())) {
    mojo.getLog().error(String.valueOf(event.getMessage()));
  }
 else   if (Level.WARN.equals(event.getLevel())) {
    mojo.getLog().warn(String.valueOf(event.getMessage()));
  }
}
 

Example 32

From project fairy, under directory /fairy-core/src/main/java/com/mewmew/fairy/v1/book/.

Source file: Dsh.java

  15 
vote

@Override public void before(){
  super.before();
  log.setLevel(Level.INFO);
  try {
    initializeSshKey();
  }
 catch (  JSchException e) {
    log.error("Unable to find ssh key",e);
  }
}
 

Example 33

From project flume, under directory /flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/.

Source file: TestLog4jAppender.java

  15 
vote

@Test public void testLog4jAppender() throws IOException {
  File TESTFILE=new File(TestLog4jAppender.class.getClassLoader().getResource("flume-log4jtest.properties").getFile());
  FileReader reader=new FileReader(TESTFILE);
  Properties props=new Properties();
  props.load(reader);
  PropertyConfigurator.configure(props);
  Logger logger=LogManager.getLogger(TestLog4jAppender.class);
  for (int count=0; count <= 1000; count++) {
    int level=count % 5;
    String msg="This is log message number" + String.valueOf(count);
    logger.log(Level.toLevel(level),msg);
    Transaction transaction=ch.getTransaction();
    transaction.begin();
    Event event=ch.take();
    Assert.assertNotNull(event);
    Assert.assertEquals(new String(event.getBody(),"UTF8"),msg);
    Map<String,String> hdrs=event.getHeaders();
    Assert.assertNotNull(hdrs.get(Log4jAvroHeaders.TIMESTAMP.toString()));
    Assert.assertEquals(Level.toLevel(level),Level.toLevel(hdrs.get(Log4jAvroHeaders.LOG_LEVEL.toString())));
    Assert.assertEquals(logger.getName(),hdrs.get(Log4jAvroHeaders.LOGGER_NAME.toString()));
    Assert.assertEquals("UTF8",hdrs.get(Log4jAvroHeaders.MESSAGE_ENCODING.toString()));
    System.out.println("Got body: " + new String(event.getBody(),"UTF8"));
    transaction.commit();
    transaction.close();
  }
}
 

Example 34

From project Flume-Hive, under directory /src/java/com/cloudera/flume/handlers/log4j/.

Source file: Log4JEventAdaptor.java

  15 
vote

public static Priority level2prio(Level l){
  if (l == Level.DEBUG)   return Priority.DEBUG;
  if (l == Level.INFO)   return Priority.INFO;
  if (l == Level.WARN)   return Priority.WARN;
  if (l == Level.ERROR)   return Priority.ERROR;
  if (l == Level.FATAL)   return Priority.FATAL;
  return Priority.INFO;
}
 

Example 35

From project flume_1, under directory /flume-core/src/main/java/com/cloudera/flume/handlers/log4j/.

Source file: Log4JEventAdaptor.java

  15 
vote

public static Priority level2prio(Level l){
  if (l == Level.DEBUG)   return Priority.DEBUG;
  if (l == Level.INFO)   return Priority.INFO;
  if (l == Level.WARN)   return Priority.WARN;
  if (l == Level.ERROR)   return Priority.ERROR;
  if (l == Level.FATAL)   return Priority.FATAL;
  return Priority.INFO;
}
 

Example 36

From project GeoBI, under directory /print/src/main/java/org/mapfish/print/config/.

Source file: Config.java

  15 
vote

/** 
 * Get or create the http client to be used to fetch all the map data.
 */
public HttpClient getHttpClient(URI uri){
  MultiThreadedHttpConnectionManager connectionManager=getConnectionManager();
  HttpClient httpClient=new HttpClient(connectionManager);
  Logger.getLogger(HttpMethodBase.class).setLevel(Level.ERROR);
  ProxySelector selector=ProxySelector.getDefault();
  List<Proxy> proxyList=selector.select(uri);
  Proxy proxy=proxyList.get(0);
  if (!proxy.equals(Proxy.NO_PROXY)) {
    InetSocketAddress socketAddress=(InetSocketAddress)proxy.address();
    String hostName=socketAddress.getHostName();
    int port=socketAddress.getPort();
    httpClient.getHostConfiguration().setProxy(hostName,port);
  }
  return httpClient;
}
 

Example 37

From project giraph, under directory /src/main/java/org/apache/giraph/.

Source file: GiraphRunner.java

  15 
vote

/** 
 * Prints description of algorithms annotated with  {@link Algorithm}
 */
private void printSupportedAlgorithms(){
  Logger.getLogger(ZooKeeper.class).setLevel(Level.OFF);
  List<Class<?>> classes=AnnotationUtils.getAnnotatedClasses(Algorithm.class,"org.apache.giraph");
  System.out.print("  Supported algorithms:\n");
  for (  Class<?> clazz : classes) {
    if (Vertex.class.isAssignableFrom(clazz)) {
      Algorithm algorithm=clazz.getAnnotation(Algorithm.class);
      StringBuilder sb=new StringBuilder();
      sb.append(algorithm.name()).append(" - ").append(clazz.getName()).append("\n");
      if (!algorithm.description().equals("")) {
        sb.append("    ").append(algorithm.description()).append("\n");
      }
      System.out.print(sb.toString());
    }
  }
}
 

Example 38

From project gnip4j, under directory /core/src/test/java/com/zaubersoftware/gnip4j/http/.

Source file: ReconnectionTest.java

  15 
vote

/** 
 * test 
 */
@Test public void testReConnection() throws Exception {
  final Logger root=Logger.getRootLogger();
  root.setLevel(Level.OFF);
  final AtomicInteger count=new AtomicInteger(0);
  final DefaultGnipStream stream=new DefaultGnipStream(new MockRemoteResourceProvider(),"account","stream",new MockExecutorService(),uriStrategy);
  final StringBuilder out=new StringBuilder();
  final StreamNotification n=new StreamNotification(){
    @Override public void notifyReConnectionError(    final GnipException e){
      out.append(String.format("ReConnectionError: %s\n",e.getMessage()));
    }
    @Override public void notifyReConnectionAttempt(    final int attempt,    final long waitTime){
      out.append(String.format("Connection attempt %d wait time %d\n",attempt,waitTime));
    }
    @Override public void notifyConnectionError(    final TransportGnipException e){
      out.append(String.format("ConnectionError: %s\n",e.getMessage()));
    }
    @Override public void notify(    final Activity activity,    final GnipStream stream){
      out.append(activity.getBody() + "\n");
      if (count.incrementAndGet() >= 4) {
        stream.close();
      }
    }
  }
;
  stream.open(n);
  stream.await();
  final String s=out.toString();
  final String expected=IOUtils.toString(getClass().getClassLoader().getResourceAsStream("reconnectlog.txt"));
  Assert.assertEquals(expected,s);
  Assert.assertEquals("transferedBytes = 8000\ntransferedActivities = 4\n" + "numberOfSucessfulReconnections = 1\nnumberOfReconnections = 4",stream.getStreamStats().toString());
}
 

Example 39

From project griffon, under directory /subprojects/griffon-rt/src/main/groovy/org/codehaus/griffon/runtime/logging/.

Source file: GriffonApplicationEventAppender.java

  15 
vote

private void fireApplicationEvent(Level level,String message,Throwable throwable){
  GriffonApplication app=ApplicationHolder.getApplication();
  if (app != null) {
    app.eventAsync(EVENT_NAME,Arrays.asList(level.toString(),message,throwable));
  }
}
 

Example 40

From project hank, under directory /src/java/com/rapleaf/hank/ui/.

Source file: WebUiServer.java

  15 
vote

public static void main(String[] args) throws Exception {
  CommandLineChecker.check(args,new String[]{"web_ui_configuration_file_path","monitor_configuration_file_path","port"},WebUiServer.class);
  Logger.getLogger("com.rapleaf.hank").setLevel(Level.INFO);
  String clientConfigPath=args[0];
  String monitorConfigPath=args[1];
  int port=Integer.parseInt(args[2]);
  ClientConfigurator webUiConfigurator=new YamlClientConfigurator(clientConfigPath);
  Coordinator coordinator=webUiConfigurator.createCoordinator();
  new Monitor(coordinator,new YamlMonitorConfigurator(monitorConfigPath));
  new WebUiServer(coordinator,new ClientCache(coordinator),port).run();
}
 

Example 41

From project harmony, under directory /harmony.common.utils/src/main/java/org/opennaas/core/utils/.

Source file: Log4JTriggerEvaluator.java

  15 
vote

/** 
 * checking if an event should be logged or not
 */
public boolean isTriggeringEvent(LoggingEvent event){
  if (event.getLevel() == Level.FATAL) {
    this.errorCounter++;
    if (this.timeLastLogEvent == 0) {
      this.timeLastLogEvent=event.timeStamp;
    }
    if (((event.timeStamp - this.timeLastLogEvent) < this.timeBetweenFatals) && this.errorCounter > this.maxErrorRate) {
      return false;
    }
 else     if ((event.timeStamp - this.timeLastLogEvent) > this.timeBetweenFatals) {
      this.timeLastLogEvent=event.timeStamp;
      this.errorCounter=1;
    }
  }
  return true;
}
 

Example 42

From project hiho, under directory /test/co/nubetech/hiho/common/.

Source file: HihoTestCase.java

  15 
vote

public static void setupDefaultSystemPropertiesIf(){
  if (System.getProperty("hadoop.log.dir") == null) {
    System.setProperty("hadoop.log.dir",System.getProperty("java.io.tmpdir","."));
  }
  if (System.getProperty("hadoop.log.file") == null) {
    System.setProperty("hadoop.log.file","hadoop.log");
  }
  if (System.getProperty("hadoop.root.logger") == null) {
    System.setProperty("hadoop.root.logger","DEBUG,console");
  }
  LogManager.getRootLogger().setLevel(Level.toLevel("DEBUG"));
  LogManager.getLogger("org.mortbay").setLevel(Level.toLevel("WARN"));
  LogManager.getLogger("co.nubetech").setLevel(Level.toLevel("DEBUG"));
}
 

Example 43

From project Hphoto, under directory /src/test/org/apache/hadoop/hbase/.

Source file: TestHBaseCluster.java

  15 
vote

/** 
 * constructor 
 */
public TestHBaseCluster(){
  super(true);
  this.desc=null;
  this.admin=null;
  this.table=null;
  Logger.getRootLogger().setLevel(Level.INFO);
  conf.setInt("hbase.master.lease.period",10 * 1000);
  conf.setInt("hbase.master.lease.thread.wakefrequency",5 * 1000);
  conf.setLong("hbase.client.pause",15 * 1000);
}
 

Example 44

From project httpobjects, under directory /demo/src/main/java/org/httpobjects/demo/.

Source file: Demo.java

  15 
vote

public static void main(String[] args) throws Exception {
  BasicConfigurator.configure();
  Logger.getRootLogger().setLevel(Level.INFO);
  final boolean useJetty=true;
  HttpObject[] objects={new CMSResources(new File(System.getProperty("user.dir"))),new PersonResource(),new Favicon()};
  if (useJetty) {
    serveViaJettyHandler(objects);
  }
 else {
    serveViaServletFilter(objects);
  }
}
 

Example 45

From project incubator-s4, under directory /subprojects/s4-tools/src/main/java/org/apache/s4/tools/.

Source file: Tools.java

  15 
vote

public static void main(String[] args){
  BasicConfigurator.configure();
  org.apache.log4j.Logger.getLogger("org.apache.zookeeper").setLevel(Level.ERROR);
  org.apache.log4j.Logger.getLogger("org.I0Itec").setLevel(Level.ERROR);
  if (!(args.length > 1)) {
    List<String> taskNames=getTaskNames();
    System.err.println("please specify a task name and proper arguments. Available tasks are: " + Arrays.toString(taskNames.toArray(new String[]{})));
    System.exit(1);
  }
  Task task=null;
  try {
    task=Task.valueOf(args[1]);
  }
 catch (  IllegalArgumentException e) {
    System.err.println("please specify a task name and proper arguments. Available tasks are: " + Arrays.toString(getTaskNames().toArray(new String[]{})));
    System.exit(1);
  }
  List<String> taskArgs=new ArrayList<String>();
  if (!task.name().equals("node")) {
    taskArgs.add(args[0]);
  }
  if (args.length > 1) {
    taskArgs.addAll(Arrays.asList(Arrays.copyOfRange(args,2,args.length)));
  }
  task.dispatch(taskArgs.toArray(new String[]{}));
}
 

Example 46

From project ISAcreator, under directory /src/main/java/org/isatools/isacreator/validateconvert/ui/.

Source file: ValidateUI.java

  15 
vote

private Map<String,List<ErrorMessage>> getErrorMessages(List<TabLoggingEventWrapper> logEvents){
  Map<String,List<ErrorMessage>> fileToErrors=new HashMap<String,List<ErrorMessage>>();
  for (  TabLoggingEventWrapper event : logEvents) {
    String fileName=ErrorUtils.extractFileInformation(event.getLogEvent());
    if (fileName != null) {
      if (event.getLogEvent().getLevel().toInt() >= Level.WARN_INT) {
        if (!fileToErrors.containsKey(fileName)) {
          fileToErrors.put(fileName,new ArrayList<ErrorMessage>());
        }
        fileToErrors.get(fileName).add(new ErrorMessage(event.getLogEvent().getLevel() == Level.WARN ? ErrorLevel.WARNING : ErrorLevel.ERROR,event.getLogEvent().getMessage().toString()));
      }
    }
  }
  return fileToErrors;
}