public final class SphereInternalLogger extends Object
Uses slf4j logger named 'sphere' and does not depend on Play logger (which also uses slf4j loggers, named 'play' and 'application').
The logger can be configured per Play application using 'logger.sphere' in 'application.conf'.
import io.sphere.sdk.utils.SphereInternalLogger;
import static io.sphere.sdk.utils.SphereInternalLogger.getLogger;
public final class LoggingExample { //replace topic with the related endpoint path segment, like categories or product-types. private static final SphereInternalLogger LOGGER = getLogger("topic.objects"); public void showLazyToString() { BigComplexObjectWithExpensiveToString object = new BigComplexObjectWithExpensiveToString(); //object.toString will only be called if trace is enabled LOGGER.trace(() -> "failed doing xyz with " + object); } }
See the test code.
The loggers form a hierarchy separated by a dot. The root logger is "sphere"
which is implicit set for
getLogger(java.lang.String)
, so you never include "sphere" in the logger name.
The child loggers of sphere are the endpoints, so for example "sphere.categories"
for categories and
"sphere.product-types"
for product types.
The grandchild loggers refer to the action. "sphere.categories.requests"
refers to
performing requests per HTTPS to Composable Commerce for categories, "sphere.categories.responses"
refers to the responses from the API.
"sphere.categories.objects"
is for non HTTP API stuff like local object creation.
"sphere.categories.responses"
logs on debug level the
http response from the API (abbreviated example):
10:59:18.623 [ForkJoinPool.commonPool-worker-3] DEBUG sphere.categories.responses - io.sphere.sdk.requests.HttpResponse@39984ae7[statusCode=200,responseBody={"offset":0,"count":4,"total":4,"results":[{"id":"2c41b33e-2d8e-415c-a4b7-f62628fa06e3","version":1,"name":{"en":"Hats"}, [...]
"sphere.categories.responses"
logs on trace level additional the formatted http response from the API (abbreviated example):
10:59:18.657 [ForkJoinPool.commonPool-worker-3] TRACE sphere.categories.responses - 200 { "offset" : 0, "count" : 4, "total" : 4, "results" : [ { "id" : "2c41b33e-2d8e-415c-a4b7-f62628fa06e3", "version" : 1, "name" : { "en" : "Hats" }, "slug" : { "en" : "hats" }, "ancestors" : [ ], "orderHint" : "0.000013999891309781676091866", "createdAt" : "2014-05-13T13:52:10.978Z", "lastModifiedAt" : "2014-05-13T13:52:10.978Z" }, [...]
sphere.products.responses.queries
logs only HTTP GET requests and sphere.products.responses.commands
logs only HTTP POST/DELETE requests.
logback.xml
or logback-test.xml
the setting is <logger name="com.ning.http.client" level="WARN"/>
.
Modifier and Type | Method and Description |
---|---|
SphereInternalLogger |
debug(Supplier<Object> message) |
SphereInternalLogger |
error(Supplier<Object> message,
Throwable throwable) |
static SphereInternalLogger |
getLogger(Class<?> clazz) |
static SphereInternalLogger |
getLogger(HttpRequest httpRequest) |
static SphereInternalLogger |
getLogger(HttpResponse response) |
static SphereInternalLogger |
getLogger(String loggerName) |
SphereInternalLogger |
info(Supplier<Object> message) |
boolean |
isTraceEnabled() |
SphereInternalLogger |
trace(Supplier<Object> message) |
SphereInternalLogger |
warn(Supplier<Object> message) |
public SphereInternalLogger debug(Supplier<Object> message)
public SphereInternalLogger trace(Supplier<Object> message)
public boolean isTraceEnabled()
public SphereInternalLogger warn(Supplier<Object> message)
public SphereInternalLogger error(Supplier<Object> message, Throwable throwable)
public SphereInternalLogger info(Supplier<Object> message)
public static SphereInternalLogger getLogger(HttpRequest httpRequest)
public static SphereInternalLogger getLogger(HttpResponse response)
public static SphereInternalLogger getLogger(Class<?> clazz)
public static SphereInternalLogger getLogger(String loggerName)