Spark: Spark doesn't log anymore ... ?

Created on 11 May 2016  路  6Comments  路  Source: perwendel/spark

when start hello world. why not println the server listen on 0.0.0.0:4567 at the console?
I means i start java -jar build/libs/spark-hello-world.jar
it only display :

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

but no the

The server listen on 0.0.0.0:4567 

We do not know the spark app listen what port

Fix docs plz

Most helpful comment

Add a logger to your POM, for example:

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.7.13</version>
</dependency>

All 6 comments

Add a logger to your POM, for example:

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.7.13</version>
</dependency>

I will update the docs later to clarify this.

I am using gradle to build project. thanks

My gradle.build file like this

plugins {
    id 'java'
        id 'com.github.johnrengelman.shadow' version '1.2.3'
}
repositories {
    jcenter()
}
jar {
    manifest {
        attributes 'Main-Class' : 'Main'
    }
}
dependencies {
    compile 'com.sparkjava:spark-core:2.5'
    compile 'org.slf4j:slf4j-simple:1.7.13'
}

task run(dependsOn:jar)  {
    dependsOn shadowJar
    doLast {
        javaexec {
            main = "-jar";
            args = [
                "build/libs/jspark-demo1-all.jar"
            ]
        }
    println 'Jspark-demo1-all running'
    }
}

and the log seems work well

[Thread-0] INFO org.eclipse.jetty.util.log - Logging initialized @167ms
[Thread-0] INFO spark.embeddedserver.jetty.EmbeddedJettyServer - == Spark has ignited ...
[Thread-0] INFO spark.embeddedserver.jetty.EmbeddedJettyServer - >> Listening on 0.0.0.0:4567
[Thread-0] INFO org.eclipse.jetty.server.Server - jetty-9.3.z-SNAPSHOT
[Thread-0] INFO org.eclipse.jetty.server.ServerConnector - Started ServerConnector@560aa726{HTTP/1.1,[http/1.1]}{0.0.0.0:4567}
[Thread-0] INFO org.eclipse.jetty.server.Server - Started @250ms

Glad to hear it!
I added a small note in the "Getting started" part of the docs, linking to this example: http://sparkjava.com/documentation.html#add-a-logger

@tipsy thank you, this fixed my problem!
I'm just starting to learn the framework, and I'm wondering, wouldn't it be better for the logger dependency to be added at the same time you add spark-core as indicated here: http://sparkjava.com/documentation.html#getting-started ?

Is there a way to use spark without the logger?

Was this page helpful?
0 / 5 - 0 ratings