Search in sources :

Example 71 with Logger

use of org.slf4j.Logger in project incubator-atlas by apache.

the class AbstractNotificationConsumerTest method testPeek.

@Test
public void testPeek() throws Exception {
    Logger logger = mock(Logger.class);
    TestMessage testMessage1 = new TestMessage("sValue1", 99);
    TestMessage testMessage2 = new TestMessage("sValue2", 98);
    TestMessage testMessage3 = new TestMessage("sValue3", 97);
    TestMessage testMessage4 = new TestMessage("sValue4", 96);
    List<String> jsonList = new LinkedList<>();
    jsonList.add(GSON.toJson(new VersionedMessage<>(new MessageVersion("1.0.0"), testMessage1)));
    jsonList.add(GSON.toJson(new VersionedMessage<>(new MessageVersion("1.0.0"), testMessage2)));
    jsonList.add(GSON.toJson(new VersionedMessage<>(new MessageVersion("1.0.0"), testMessage3)));
    jsonList.add(GSON.toJson(new VersionedMessage<>(new MessageVersion("1.0.0"), testMessage4)));
    Type versionedMessageType = new TypeToken<VersionedMessage<TestMessage>>() {
    }.getType();
    NotificationConsumer<TestMessage> consumer = new TestNotificationConsumer<>(versionedMessageType, jsonList, logger);
    assertTrue(consumer.hasNext());
    assertEquals(testMessage1, consumer.peek());
    assertTrue(consumer.hasNext());
    assertEquals(testMessage1, consumer.peek());
    assertTrue(consumer.hasNext());
}
Also used : Type(java.lang.reflect.Type) Logger(org.slf4j.Logger) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 72 with Logger

use of org.slf4j.Logger in project jena by apache.

the class FusekiCmd method processModulesAndArgs.

@Override
protected void processModulesAndArgs() {
    int x = 0;
    Logger log = Fuseki.serverLog;
    if (contains(argFusekiConfig))
        fusekiConfigFile = getValue(argFusekiConfig);
    ArgDecl assemblerDescDecl = new ArgDecl(ArgDecl.HasValue, "desc", "dataset");
    if (contains(argMem))
        x++;
    if (contains(argFile))
        x++;
    if (contains(assemblerDescDecl))
        x++;
    if (contains(argTDB))
        x++;
    if (contains(argMemTDB))
        x++;
    if (fusekiConfigFile != null) {
        if (x >= 1)
            throw new CmdException("Dataset specified on the command line but a configuration file also given.");
    } else {
        if (x != 1)
            throw new CmdException("Required: either --config=FILE or one of --mem, --file, --loc or --desc");
    }
    if (contains(argMem)) {
        log.info("Dataset: in-memory");
        dsg = DatasetGraphFactory.create();
    }
    if (contains(argFile)) {
        dsg = DatasetGraphFactory.create();
        // replace by RiotLoader after ARQ refresh.
        String filename = getValue(argFile);
        log.info("Dataset: in-memory: load file: " + filename);
        if (!FileOps.exists(filename))
            throw new CmdException("File not found: " + filename);
        Lang language = RDFLanguages.filenameToLang(filename);
        if (language == null)
            throw new CmdException("Can't guess language for file: " + filename);
        InputStream input = IO.openFile(filename);
        if (RDFLanguages.isQuads(language))
            RDFDataMgr.read(dsg, filename);
        else
            RDFDataMgr.read(dsg.getDefaultGraph(), filename);
    }
    if (contains(argMemTDB)) {
        log.info("TDB dataset: in-memory");
        dsg = TDBFactory.createDatasetGraph();
    }
    if (contains(argTDB)) {
        String dir = getValue(argTDB);
        if (Objects.equals(dir, Names.memName)) {
            log.info("TDB dataset: in-memory");
        } else {
            if (!FileOps.exists(dir))
                throw new CmdException("Directory not found: " + dir);
            log.info("TDB dataset: directory=" + dir);
        }
        dsg = TDBFactory.createDatasetGraph(dir);
    }
    // Otherwise
    if (contains(assemblerDescDecl)) {
        log.info("Dataset from assembler");
        Dataset ds = modDataset.createDataset();
        if (ds != null)
            dsg = ds.asDatasetGraph();
    }
    if (contains(argFusekiConfig)) {
        if (dsg != null)
            throw new CmdException("(internal error) Dataset specificed on the command line but a a configuration file also given.");
        fusekiConfigFile = getValue(argFusekiConfig);
    }
    if (contains(argPort)) {
        String portStr = getValue(argPort);
        try {
            port = Integer.parseInt(portStr);
        } catch (NumberFormatException ex) {
            throw new CmdException(argPort.getKeyName() + " : bad port number: " + portStr);
        }
    }
    if (contains(argMgtPort)) {
        String mgtPortStr = getValue(argMgtPort);
        try {
            mgtPort = Integer.parseInt(mgtPortStr);
        } catch (NumberFormatException ex) {
            throw new CmdException(argMgtPort.getKeyName() + " : bad port number: " + mgtPortStr);
        }
    }
    if (contains(argLocalhost))
        listenLocal = true;
    if (fusekiConfigFile == null && dsg == null)
        throw new CmdException("No dataset defined and no configuration file: " + argUsage);
    if (dsg != null) {
        if (getPositional().size() == 0)
            throw new CmdException("No dataset path name given");
        if (getPositional().size() > 1)
            throw new CmdException("Multiple dataset path names given");
        datasetPath = getPositionalArg(0);
        if (datasetPath.length() > 0 && !datasetPath.startsWith("/"))
            throw new CmdException("Dataset path name must begin with a /: " + datasetPath);
        allowUpdate = contains(argAllowUpdate);
    }
    if (contains(argTimeout)) {
        String str = getValue(argTimeout);
        ARQ.getContext().set(ARQ.queryTimeout, str);
    }
    if (contains(argJettyConfig)) {
        jettyConfigFile = getValue(argJettyConfig);
        if (!FileOps.exists(jettyConfigFile))
            throw new CmdException("No such file: " + jettyConfigFile);
    }
    if (contains(argBasicAuth)) {
        authConfigFile = getValue(argBasicAuth);
        if (!FileOps.exists(authConfigFile))
            throw new CmdException("No such file: " + authConfigFile);
    }
    if (contains(argHome)) {
        List<String> args = super.getValues(argHome);
        homeDir = args.get(args.size() - 1);
    }
    if (contains(argPages)) {
        List<String> args = super.getValues(argPages);
        pagesDir = args.get(args.size() - 1);
    }
    if (contains(argGZip)) {
        if (!hasValueOfTrue(argGZip) && !hasValueOfFalse(argGZip))
            throw new CmdException(argGZip.getNames().get(0) + ": Not understood: " + getValue(argGZip));
        enableCompression = super.hasValueOfTrue(argGZip);
    }
    if (contains(argUber))
        SPARQLServer.überServlet = true;
    if (contains(argGSP)) {
        SPARQLServer.überServlet = true;
        Fuseki.graphStoreProtocolPostCreate = true;
    }
}
Also used : CmdException(jena.cmd.CmdException) InputStream(java.io.InputStream) Dataset(org.apache.jena.query.Dataset) ArgDecl(jena.cmd.ArgDecl) Lang(org.apache.jena.riot.Lang) Logger(org.slf4j.Logger)

Example 73 with Logger

use of org.slf4j.Logger in project sling by apache.

the class SlingStatusPrinter method print.

private static void print(List<Status> statusList, boolean initSuccess) {
    if (statusList == null) {
        return;
    }
    StringBuilder sb = new StringBuilder();
    if (initSuccess) {
        sb.append("While (re)configuring Logback transient issues were observed. " + "More details are provided below.");
        sb.append(CoreConstants.LINE_SEPARATOR);
    }
    String prefix = "";
    if (initSuccess) {
        prefix = "*Logback Status* ";
    }
    for (Status s : statusList) {
        StatusPrinter.buildStr(sb, prefix, s);
    }
    //otherwise make it part of 'normal' logs
    if (!initSuccess) {
        System.out.println(sb.toString());
    } else {
        Logger logger = LoggerFactory.getLogger(SlingStatusPrinter.class);
        logger.info(sb.toString());
    }
}
Also used : ErrorStatus(ch.qos.logback.core.status.ErrorStatus) Status(ch.qos.logback.core.status.Status) Logger(org.slf4j.Logger)

Example 74 with Logger

use of org.slf4j.Logger in project sling by apache.

the class ITDefaultConfig method testDefaultSettings.

/**
     * Checks the default settings. It runs the bundle with minimum dependencies
     */
@Test
public void testDefaultSettings() throws Exception {
    Logger slf4jLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    assertTrue("Default Log level should be INFO", slf4jLogger.isInfoEnabled());
    // Check for Logback being used
    assertTrue(LoggerFactory.getILoggerFactory() instanceof LoggerContext);
    assertTrue(slf4jLogger instanceof ch.qos.logback.classic.Logger);
    // Test that root logger has one FileAppender attached
    ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) slf4jLogger;
    Iterator<Appender<ILoggingEvent>> itr = logger.iteratorForAppenders();
    assertTrue("One appender should be attached with root logger", itr.hasNext());
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(org.slf4j.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 75 with Logger

use of org.slf4j.Logger in project sling by apache.

the class LogSupport method logOut.

/**
     * Actually logs the given log entry to the logger for the bundle recorded
     * in the log entry.
     */
private void logOut(LogEntry logEntry) {
    // get the logger for the bundle
    Logger log = getLogger(logEntry.getBundle());
    if (logEntry.getLevel() > getLevel(log))
        // early Exit, this message will not be logged, don't do any work...
        return;
    final StringBuilder msg = new StringBuilder();
    ServiceReference sr = logEntry.getServiceReference();
    if (sr != null) {
        msg.append("Service [");
        if (sr.getProperty(Constants.SERVICE_PID) != null) {
            msg.append(sr.getProperty(Constants.SERVICE_PID)).append(',');
        } else if (sr.getProperty(COMPONENT_NAME) != null) {
            msg.append(sr.getProperty(COMPONENT_NAME)).append(',');
        } else if (sr.getProperty(Constants.SERVICE_DESCRIPTION) != null) {
            msg.append(sr.getProperty(Constants.SERVICE_DESCRIPTION)).append(',');
        }
        msg.append(sr.getProperty(Constants.SERVICE_ID)).append(", ").append(Arrays.toString((String[]) sr.getProperty(Constants.OBJECTCLASS))).append("] ");
    }
    if (logEntry.getMessage() != null) {
        msg.append(logEntry.getMessage());
    }
    Throwable exception = logEntry.getException();
    if (exception != null) {
        msg.append(" (").append(exception).append(')');
    }
    String message = msg.toString();
    switch(logEntry.getLevel()) {
        case LogService.LOG_DEBUG:
            log.debug(message, exception);
            break;
        case LogService.LOG_INFO:
            log.info(message, exception);
            break;
        case LogService.LOG_WARNING:
            log.warn(message, exception);
            break;
        case LogService.LOG_ERROR:
            log.error(message, exception);
            break;
        default:
            if (logEntry.getLevel() > LogService.LOG_DEBUG) {
                log.trace(message, exception);
            } else if (logEntry.getLevel() < LogService.LOG_ERROR) {
                log.error(message, exception);
            }
            break;
    }
}
Also used : Logger(org.slf4j.Logger) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

Logger (org.slf4j.Logger)1088 Test (org.junit.Test)249 IOException (java.io.IOException)127 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)110 ArrayList (java.util.ArrayList)71 InputStream (java.io.InputStream)64 List (java.util.List)59 File (java.io.File)56 Map (java.util.Map)51 LoggerFactory (org.slf4j.LoggerFactory)46 Test (org.testng.annotations.Test)43 HashMap (java.util.HashMap)39 Properties (java.util.Properties)35 HashSet (java.util.HashSet)31 FileInputStream (java.io.FileInputStream)29 Transfer (org.commonjava.maven.galley.model.Transfer)29 Set (java.util.Set)28 StoreKey (org.commonjava.indy.model.core.StoreKey)28 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)27 Date (java.util.Date)26