Java Code Examples for org.slf4j.Logger

The following are top voted examples for showing how to use org.slf4j.Logger. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: jena   File: TestList.java View source code Vote up 6 votes
/** Test that an iterator delivers the expected values */
protected static void iteratorTest( final Iterator<?> i,
		final Object[] expected )
{
	final Logger logger = LoggerFactory.getLogger(TestList.class);
	final List<Object> expList = new ArrayList<>();
	for (final Object element : expected)
	{
		expList.add(element);
	}

	while (i.hasNext())
	{
		final Object next = i.next();

		// debugging
		if (!expList.contains(next))
		{
			logger.debug("TestList - Unexpected iterator result: " + next);
		}

		Assert.assertTrue("Value " + next
				+ " was not expected as a result from this iterator ",
				expList.contains(next));
		Assert.assertTrue("Value " + next
				+ " was not removed from the list ", expList.remove(next));
	}

	if (!(expList.size() == 0))
	{
		logger.debug("TestList - Expected iterator results not found");
		for (final Object object : expList)
		{
			logger.debug("TestList - missing: " + object);
		}
	}
	Assert.assertEquals(
			"There were expected elements from the iterator that were not found",
			0, expList.size());
}
 
Example 2
Project: automation-test-engine   File: LogbackWriter.java View source code Vote up 6 votes
/**
 * Prints the stack trace.
 *
 * @param thr the th
 */
public static void printStackTrace(Throwable thr) {
	final Logger mylogger2 = myLogger;
	if (mylogger2 == null) {
		throw GlobalUtils.createNotInitializedException("MYLOGGER"); //NOPMD
	} else {
		if (mylogger2.isErrorEnabled()) {
			mylogger2.error("Uncaught error!", thr);
		} else {
			throw new UnsupportedOperationException(
					ExceptionMessage.MSG_UNSUPPORTED_LOGBACK_LEVEL
							+ "MYLOGGER.isErrorEnabled()");
		}
		
	}
}
 
Example 3
Project: nmonvisualizer   File: DataHelper.java View source code Vote up 6 votes
public static void aggregateProcessData(ProcessDataSet data, Logger logger) {
    long start = System.nanoTime();
    Map<String, List<Process>> processNameToProcesses = DataHelper.getProcessesByName(data, false);

    for (List<Process> processes : processNameToProcesses.values()) {
        if (processes.size() > 1) {
            aggregateProcesses(data, processes, logger);
        }
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Aggregated process data for {} in {}ms ", data, (System.nanoTime() - start) / 1000000.0d);
    }
}
 
Example 4
Project: visuwall   File: ZooTrace.java View source code Vote up 6 votes
static public void logRequest(Logger log, long mask,
        char rp, Request request, String header)
{
    if (isTraceEnabled(log, mask)) {
        log.trace(header + ":" + rp + request.toString());
    }
}
 
Example 5
Project: appstatus   File: AbstractLoggingServiceMonitor.java View source code Vote up 6 votes
@Override
public void endCall() {
	if (endTime != null) {
		// endCall was called twice ! returning directly.
		return;
	}

	super.endCall();

	endTime = System.currentTimeMillis();

	if (executionTime == null) {
		executionTime = endTime - startTime;
	}

	if (enableLog) {
		Logger log = getLogger();
		if (log.isInfoEnabled()) {
			log.info(getLogMessage());

		}
	}
}
 
Example 6
Project: abiquo   File: JInteropLoggingListener.java View source code Vote up 6 votes
@Override
public void contextInitialized(final ServletContextEvent context)
{
    Logger logger = LoggerFactory.getLogger("org.jinterop");
    Level level = null;

    if (logger.isTraceEnabled())
    {
        level = Level.FINEST;
    }
    else if (logger.isDebugEnabled())
    {
        level = Level.FINE;
    }
    else if (logger.isInfoEnabled())
    {
        level = Level.INFO;
    }
    else if (logger.isWarnEnabled())
    {
        level = Level.FINER;
    }
    else if (logger.isDebugEnabled())
    {
        level = Level.WARNING;
    }
    else if (logger.isErrorEnabled())
    {
        level = Level.SEVERE;
    }
    else
    {
        level = Level.OFF;
    }

    JISystem.getLogger().setLevel(level);
}
 
Example 7
Project: automation-test-engine   File: LogbackWriter.java View source code Vote up 6 votes
/**
	 * Write logback app log.
	 *
	 * @param logMessenger the log messenger
	 */
	public static void writeLogbackAppLog(LogMessage logMessenger) {
		final Logger logger = LoggerFactory.getLogger(LogbackWriter.class);
		if (null == logger) {
			throw GlobalUtils.createNotInitializedException(LOGBACKLOGGERNOTINIT);
		}
		if (!logMessenger.getErrorMsg().equals("") && logger.isErrorEnabled())
			logger.error(APPLOG_ERRORHEADER + logMessenger.getErrorMsg());
		if (!logMessenger.getWarningMsg().equals("") && logger.isWarnEnabled())
			logger.warn(APPLOG_WARNHEADER + logMessenger.getWarningMsg());
		if (!logMessenger.getInfoMsg().equals("") && logger.isInfoEnabled())
			logger.info(APPLOG_INFOHEADER + logMessenger.getInfoMsg());//NOPMD
//		if (!logMessenger.getDebugMsg().equals(""))
//			logger.debug(logMessenger.getDebugMsg());
//		if (!logMessenger.getTraceMsg().equals(""))
//			logger.trace(logMessenger.getTraceMsg());
	}
 
Example 8
Project: plugins   File: PluginManager.java View source code Vote up 6 votes
protected static PluginLoggerFactory defaultPluginLoggerFactory(Logger logger) {
    final String prefix = logger.getName() + ".";
    return new PluginLoggerFactory() {
        @Override
        public Logger getLogger(String pluginName) {
            return LoggerFactory.getLogger(prefix + pluginName);
        }
    };
}
 
Example 9
Project: jena   File: FusekiCmd.java View source code Vote up 5 votes
@Override
        protected void processModulesAndArgs() {
            int x = 0 ;

            if ( super.isVerbose() || super.isDebug() ) {
                jettyServerConfig.verboseLogging = true ;
                // Output is still at level INFO (currently) 
            }
            
            Logger log = Fuseki.serverLog ;

            if ( contains(argFusekiConfig) )
                cmdLineConfig.fusekiCmdLineConfigFile = getValue(argFusekiConfig) ;

            ArgDecl assemblerDescDecl = new ArgDecl(ArgDecl.HasValue, "desc", "dataset") ;

            // ---- Datasets

            if ( contains(argMem) )             
                x++ ;
            if ( contains(argFile) )
                x++ ;
            if ( contains(assemblerDescDecl) )
                x++ ;
            if ( contains(argTDB) )
                x++ ;
            if ( contains(argMemTDB) )
                x++ ;

            if ( cmdLineConfig.fusekiCmdLineConfigFile != null ) {
                if ( x >= 1 )
                    throw new CmdException("Dataset specified on the command line but a configuration file also given.") ;
            } else {
                // No configuration file.  0 or 1 legal.
                if ( x > 1 )
                    throw new CmdException("Multiple ways providing a dataset. Only one of --mem, --file, --loc or --desc") ;
            }
            
            boolean cmdlineConfigPresent = ( x != 0 ) ;
            if ( cmdlineConfigPresent && getPositional().size() == 0 )
                throw new CmdException("Missing service name") ;

            if ( cmdLineConfig.fusekiCmdLineConfigFile != null && getPositional().size() > 0 )
                throw new CmdException("Service name will come from --conf; no command line service name allowed") ;

            
            if ( !cmdlineConfigPresent && getPositional().size() > 0 )
                throw new CmdException("Service name given but no configuration argument to match (e.g. --mem, --loc/--tdb, --file)") ;
            
            if ( cmdlineConfigPresent && getPositional().size() > 1 )
                throw new CmdException("Multiple dataset path names given") ;
            
            cmdLineConfig.allowUpdate = contains(argUpdate) ; 

            if ( contains(argMem) ) {
                log.info("Dataset: in-memory") ;
                // Only one setup should be called by the test above but to be safe
                // and in case of future changes, clear the configuration.  
                cmdLineConfig.reset();
                cmdLineConfig.argTemplateFile = Template.templateMemFN ;
                // Always allow.
                cmdLineConfig.allowUpdate = true ;
            }

            if ( contains(argFile) ) {
                String filename = getValue(argFile) ;
                log.info("Dataset: in-memory: load file: " + filename) ;
                if ( !FileOps.exists(filename) )
                    throw new CmdException("File not found: " + filename) ;

                // Directly populate the dataset.
                cmdLineConfig.reset();
                cmdLineConfig.dsg = DatasetGraphFactory.createMem() ;

                // INITIAL DATA.
                Lang language = RDFLanguages.filenameToLang(filename) ;
                if ( language == null )
                    throw new CmdException("Can't guess language for file: " + filename) ;
                RDFDataMgr.read(cmdLineConfig.dsg, filename) ;
            }

            if ( contains(argMemTDB) ) {
                //log.info("TDB dataset: in-memory") ;
                cmdLineConfig.reset();
                cmdLineConfig.argTemplateFile = Template.templateTDBMemFN ;
                cmdLineConfig.params.put(Template.DIR, Names.memName) ;
                // Always allow.
                cmdLineConfig.allowUpdate = true ;
            }

            if ( contains(argTDB) ) {
                cmdLineConfig.reset();
                cmdLineConfig.argTemplateFile = Template.templateTDBDirFN ;
                String dir = getValue(argTDB) ;
                cmdLineConfig.params.put(Template.DIR, dir) ;
            }

            // Otherwise
            if ( contains(assemblerDescDecl) ) {
                log.info("Dataset from assembler") ;
                // Need to add service details.
                Dataset ds = modDataset.createDataset() ;
                //cmdLineDataset.dsg = ds.asDatasetGraph() ;
            }
            
            if ( cmdlineConfigPresent ) {
                cmdLineConfig.datasetPath = getPositionalArg(0) ;
                if ( cmdLineConfig.datasetPath.length() > 0 && !cmdLineConfig.datasetPath.startsWith("/") )
                    throw new CmdException("Dataset path name must begin with a /: " + cmdLineConfig.datasetPath) ;
                if ( ! cmdLineConfig.allowUpdate )
                    Fuseki.serverLog.info("Running in read-only mode for "+cmdLineConfig.datasetPath) ;
                // Include the dataset name as NAME for any templates.
                cmdLineConfig.params.put(Template.NAME,  cmdLineConfig.datasetPath) ;
            }

            // ---- Jetty server
            if ( contains(argBasicAuth) )
                Fuseki.configLog.warn("--basic-auth ignored: Use Apache Shiro security - see shiro.ini") ;

            if ( contains(argPort) ) {
                String portStr = getValue(argPort) ;
                try {
                    jettyServerConfig.port = Integer.parseInt(portStr) ;
                } catch (NumberFormatException ex) {
                    throw new CmdException(argPort.getKeyName() + " : bad port number: " + portStr) ;
                }
            }

            if ( contains(argMgt) )
                Fuseki.configLog.warn("Fuseki v2: Management functions are always enabled.  --mgt not needed.") ; 
            
            if ( contains(argMgtPort) )
                Fuseki.configLog.warn("Fuseki v2: Management functions are always on the same port as the server.  --mgtPort ignored.") ; 

//            if ( contains(argMgt) ) {
//                jettyServerConfig.mgtPort = 0 ;
//                if (  contains(argMgtPort) ) {
//                    String mgtPortStr = getValue(argMgtPort) ;
//                    try {
//                        jettyServerConfig.mgtPort = Integer.parseInt(mgtPortStr) ;
//                    } catch (NumberFormatException ex) {
//                        throw new CmdException("--"+argMgtPort.getKeyName() + " : bad port number: " + mgtPortStr) ;
//                    }
//                }
//            }

            if ( contains(argLocalhost) )
                jettyServerConfig.loopback = true ;

            if ( contains(argTimeout) ) {
                String str = getValue(argTimeout) ;
                ARQ.getContext().set(ARQ.queryTimeout, str) ;
            }

            if ( contains(argJettyConfig) ) {
                jettyServerConfig.jettyConfigFile = getValue(argJettyConfig) ;
                if ( !FileOps.exists(jettyServerConfig.jettyConfigFile) )
                    throw new CmdException("No such file: " + jettyServerConfig.jettyConfigFile) ;
            }

            if ( contains(argBasicAuth) ) {
                jettyServerConfig.authConfigFile = getValue(argBasicAuth) ;
                if ( !FileOps.exists(jettyServerConfig.authConfigFile) )
                    throw new CmdException("No such file: " + jettyServerConfig.authConfigFile) ;
            }

            if ( contains(argHome) ) {
                Fuseki.configLog.warn("--home ignored (use enviroment variables $FUSEKI_HOME and $FUSEKI_BASE)") ;
//                List<String> args = super.getValues(argHome) ;
//                homeDir = args.get(args.size() - 1) ;
            }

            if ( contains(argPages) ) {
                List<String> args = super.getValues(argPages) ;
                jettyServerConfig.pages = args.get(args.size() - 1) ;
            }

            if ( contains(argGZip) ) {
                if ( !hasValueOfTrue(argGZip) && !hasValueOfFalse(argGZip) )
                    throw new CmdException(argGZip.getNames().get(0) + ": Not understood: " + getValue(argGZip)) ;
                jettyServerConfig.enableCompression = super.hasValueOfTrue(argGZip) ;
            }
        }
 
Example 10
Project: jena   File: JenaUUID.java View source code Vote up 5 votes
/** Recreate a UUID from string */
public static JenaUUID parse(String s) {
    if ( s.equals(strNil()) )
        return nil() ;

    // Canonical: this works in conjunction with .equals
    s = s.toLowerCase(Locale.ENGLISH) ;

    if ( s.startsWith("urn:") )
        s = s.substring(4) ;
    if ( s.startsWith("uuid:") )
        s = s.substring(5) ;

    if ( s.length() != 36 )
        throw new UUIDFormatException("UUID string is not 36 chars long: it's " + s.length() + " [" + s + "]") ;

    if ( s.charAt(8) != '-' || s.charAt(13) != '-' || s.charAt(18) != '-' || s.charAt(23) != '-' )
        throw new UUIDFormatException("String does not have dashes in the right places: " + s) ;

    // The UUID broken up into parts.
    //       00000000-0000-0000-0000-000000000000
    //       ^        ^    ^    ^    ^           
    // Byte: 0        4    6    8    10
    // Char: 0        9    14   19   24  including hyphens
    int x = (int)Bits.unpack(s, 19, 23) ;
    int variant = (x >>> 14) ;
    int version = (int)Bits.unpack(s, 14, 15) ;

    if ( variant == Var_Std ) {
        switch (version) {
            case UUID_V1.version :
                return UUID_V1_Gen.parse$(s) ;
            case UUID_V4.version :
                return UUID_V4_Gen.parse$(s) ;
        }
        LoggerFactory.getLogger(JenaUUID.class).warn(s + " : Unsupported version: " + version) ;
        throw new UnsupportedOperationException("String specifies unsupported UUID version: " + version) ;
    }

    Logger log = LoggerFactory.getLogger(JenaUUID.class) ;

    switch (variant) {
        case Var_NCS : // NCS
            log.warn(s + " : Oh look! An NCS UUID ID.  Call the museum.") ;
            break ;
        case Var_DCE : // DCE - should have been caught earlier.
            log.warn(s + " : Oh look! A DCE UUID ID - but we should have already handled this") ;
            break ;
        case Var_MS_GUID :
            log.warn(s + " : Microsoft UUID ID.") ;
            break ;
        case Var_Reserved :
            log.warn(s + " : Reserved variant") ;
            break ;
        default :
            log.warn(s + " : Unknown variant: " + variant) ;
            break ;
    }
    throw new UnsupportedOperationException("String specifies unsupported UUID variant: " + variant) ;
}