static { new SystemEnvironment().setProperty(GoConstants.USE_COMPRESSED_JAVASCRIPT, "false"); Logger rootLogger = Logger.getRootLogger(); rootLogger.setLevel(Level.INFO); try { Filter filter = new Filter() { @Override public int decide(LoggingEvent loggingEvent) { return loggingEvent.getLoggerName().startsWith("com.thoughtworks.go.util.PerfTimer") || loggingEvent .getLoggerName() .startsWith( "com.thoughtworks.go.server.service.PipelineConfigServicePerformanceTest") ? 0 : -1; } }; ConsoleAppender consoleAppender = new ConsoleAppender(new PatternLayout("%d [%p|%c|%C{1}] %m%n")); consoleAppender.addFilter(filter); consoleAppender.setName(consoleAppenderForPerformanceTest); RollingFileAppender rollingFileAppender = new RollingFileAppender( new PatternLayout("%d [%p|%c|%C{1}] %m%n"), "/tmp/config-save-perf.log", false); rollingFileAppender.addFilter(filter); rollingFileAppender.setName(rollingFileAppenderForPerformanceTest); rootLogger.addAppender(rollingFileAppender); rootLogger.addAppender(consoleAppender); } catch (IOException e) { e.printStackTrace(); } }
@BeforeClass public static void setUpClass() throws Exception { final ConsoleAppender consoleAppender = new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)); consoleAppender.setThreshold(Level.INFO); Logger.getRootLogger().addAppender(consoleAppender); }
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); }
/** * Configures the Logger (log4j) class used by the entire library to log what happens at run time. * * @param logToConsole determines if log4j engine should log to the standard output or not. * @return a Logger class used to log events and functional meanings of the application. */ public Logger configure(boolean logToConsole) { Logger log = Logger.getLogger(clazz); boolean loadDefaults = false; String logPath = null; PatternLayout layout = null; Strings str = Strings.getOne(); String logLevel = "", logConsoleLevel = "", logFileLevel = ""; try { Constants c = Constants.getOne(clazz); Properties log4j = c.getLog4j(); loadDefaults = log4j.isEmpty(); if (!loadDefaults) { PropertyConfigurator.configure(log4j); } else { logLevel = c.getConstant("log.level"); logConsoleLevel = c.getConstant("log.console.level"); logFileLevel = c.getConstant("log.file.level"); logPath = str.safeConcatPaths(c.getConstant("log.dir"), c.getConstant("log.file")); if (!str.checkPathExistence(logPath)) { str.createPath(logPath); new File(logPath).createNewFile(); } layout = new PatternLayout(c.getConstant("log.pattern")); } } catch (Throwable e) { logPath = str.safeConcatPaths(Constants.USER_HOME, "." + Constants.FPM_DIR); if (!str.checkPathExistence(logPath)) { str.createPath(logPath); } logPath = str.safeConcatPaths(logPath, Constants.MAIN_LOG_FILE); layout = new PatternLayout(Constants.DEFAULT_LOG_PATTERN); loadDefaults = true; } if (loadDefaults) { log.setLevel(Level.toLevel(logLevel)); if (logToConsole) { ConsoleAppender consapp = new ConsoleAppender(layout); consapp.setTarget("System.out"); consapp.setThreshold(Level.toLevel(logConsoleLevel)); log.addAppender(consapp); } FileAppender fileapp; try { fileapp = new FileAppender(layout, logPath); fileapp.setThreshold(Level.toLevel(logFileLevel)); log.addAppender(fileapp); } catch (IOException e) { log.warn("FileAppender not initialized! ".concat(e.getMessage())); } } log.trace("Logger initialized!"); return log; }
public void init() { ConsoleAppender console = new ConsoleAppender(); // create appender // configure the appender String PATTERN = "%d [%p|%c|%C{1}] %m%n"; console.setLayout(new PatternLayout(PATTERN)); console.setThreshold(Level.DEBUG); console.activateOptions(); // add appender to any Logger (here is root) Logger.getRootLogger().addAppender(console); SipFactory sipFactory = null; sipStack = null; sipFactory = SipFactory.getInstance(); sipFactory.setPathName("gov.nist"); Properties properties = new Properties(); properties.setProperty("javax.sip.STACK_NAME", "shootme"); // You need 16 for logging traces. 32 for debug + traces. // Your code will limp at 32 but it is best for debugging. properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "LOG4J"); properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "shootmedebug.txt"); properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "shootmelog.txt"); properties.setProperty( "gov.nist.javax.sip.MESSAGE_PROCESSOR_FACTORY", NioMessageProcessorFactory.class.getName()); try { // Create SipStack object sipStack = sipFactory.createSipStack(properties); System.out.println("sipStack = " + sipStack); } catch (PeerUnavailableException e) { // could not find // gov.nist.jain.protocol.ip.sip.SipStackImpl // in the classpath e.printStackTrace(); System.err.println(e.getMessage()); if (e.getCause() != null) e.getCause().printStackTrace(); System.exit(0); } try { headerFactory = sipFactory.createHeaderFactory(); addressFactory = sipFactory.createAddressFactory(); messageFactory = sipFactory.createMessageFactory(); this.listeningPoint = sipStack.createListeningPoint("127.0.0.1", myPort, transport); B2BUA listener = this; sipProvider = sipStack.createSipProvider(listeningPoint); System.out.println("ws provider " + sipProvider); sipProvider.addSipListener(listener); } catch (Exception ex) { System.out.println(ex.getMessage()); ex.printStackTrace(); } }
public static void main(final String[] args) { // Disable log system, we want full control over what is sent to console. final ConsoleAppender consoleAppender = new ConsoleAppender(); consoleAppender.activateOptions(); consoleAppender.setLayout(new PatternLayout("%p %t %C:%M %m%n")); consoleAppender.setThreshold(Level.OFF); BasicConfigurator.configure(consoleAppender); // Parse the flags. Flags flags = new Flags().loadOpts(ZkTool.class).parse(args); // Check if we wish to print out help text if (flags.helpFlagged()) { flags.printHelp(System.out); System.out.println("Must specify one of the following options:"); System.out.println(actionSelectingFlagNames); return; } checkArgumentCombinationValid(flags); ZkCloudname.Builder builder = new ZkCloudname.Builder(); if (zooKeeperFlag == null) { builder.setDefaultConnectString(); } else { builder.setConnectString(zooKeeperFlag); } try { cloudname = builder.build().connect(); } catch (CloudnameException e) { System.err.println("Could not connect to zookeeper " + e.getMessage()); return; } try { if (filePath != null) { handleFilepath(); } else if (coordinateFlag != null) { handleCoordinateOperation(); } else if (resolverExpression != null) { handleResolverExpression(); } else if (listFlag) { listCoordinates(); } else { System.err.println("No action specified"); } } catch (Exception e) { System.err.println("An error occurred: " + e.getMessage()); e.printStackTrace(); } finally { cloudname.close(); } }
private void appendAll() { printNow = true; try { for (LoggingEvent event : eventsList) { super.append(event); } } finally { // Make sure we always free up memory eventsList.clear(); } printNow = false; }
private SystemLogger() { systemLogger = Logger.getLogger("System"); /* System verbosity (Standard Out) */ consoleAppender = new ConsoleAppender(new PatternLayout("%m"), ConsoleAppender.SYSTEM_ERR); consoleAppender.setEncoding("UTF-16"); systemLogger.addAppender(consoleAppender); if (System.getProperty("Malt.verbosity") != null) { setSystemVerbosityLevel(System.getProperty("Malt.verbosity").toUpperCase()); } else { setSystemVerbosityLevel("INFO"); } }
/* Configure the log4j appenders */ static void configureLogger() { ConsoleAppender console = new ConsoleAppender(); // create appender // configure the appender console.setLayout(new PatternLayout(PATTERN)); console.setThreshold(Level.ALL); console.activateOptions(); // add appender to any Logger (here is root) log.addAppender(console); // This is for the rmi_server log file FileAppender fa = new FileAppender(); fa.setName("FileLogger"); fa.setFile("log/_rmi_server.log"); fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n")); fa.setThreshold(Level.ALL); fa.setAppend(true); fa.activateOptions(); // add appender to any Logger (here is root) log.addAppender(fa); log.setAdditivity(false); // repeat with all other desired appenders }
protected BaseTestCase() { TEST_ROOT = "/tmp/cascading_ext_" + this.getClass().getSimpleName() + "_AUTOGEN"; org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger(); rootLogger.setLevel(Level.ALL); org.apache.log4j.Logger.getLogger("org.apache.hadoop").setLevel(Level.INFO); org.apache.log4j.Logger.getLogger("cascading").setLevel(Level.INFO); org.apache.log4j.Logger.getLogger("org.eclipse.jetty").setLevel(Level.ERROR); org.apache.log4j.Logger.getLogger("com.liveramp.hank").setLevel(Level.DEBUG); // Reconfigure the logger to ensure things are working ConsoleAppender consoleAppender = new ConsoleAppender( new PatternLayout("%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n"), ConsoleAppender.SYSTEM_ERR); consoleAppender.setName("test-console-appender"); consoleAppender.setFollow(true); rootLogger.removeAppender("test-console-appender"); rootLogger.addAppender(consoleAppender); }
@Override protected void subAppend(LoggingEvent event) { if (printNow) { super.subAppend(event); } else { // set name of current thread on the event so it's correct when/if we print the message later event.getThreadName(); if (gatewayName != null) { injectGatewayName(event); } eventsList.add(event); // To avoid OOM, limit number of cached messages if (messageCount.incrementAndGet() > MAX_MESSAGES) { eventsList.poll(); // remove oldest message } } }
/** * Sets the system verbosity level * * @param verbosity a system verbosity level */ public void setSystemVerbosityLevel(String verbosity) { this.systemVerbosityLevel = Level.toLevel(verbosity, Level.INFO); consoleAppender.setThreshold(systemVerbosityLevel); systemLogger.setLevel(systemVerbosityLevel); }