Skip to content

Instantly share code, notes, and snippets.

View martinschneider's full-sized avatar
🇹🇼

Martin Schneider martinschneider

🇹🇼
View GitHub Profile
package qa.justtestlah.aop;
import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
package qa.justtestlah.log;
import io.cucumber.plugin.ConcurrentEventListener;
import io.cucumber.plugin.event.EventHandler;
import io.cucumber.plugin.event.EventPublisher;
import io.cucumber.plugin.event.PickleStepTestStep;
import io.cucumber.plugin.event.Result;
import io.cucumber.plugin.event.Step;
import io.cucumber.plugin.event.TestCase;
import io.cucumber.plugin.event.TestCaseFinished;
private static final Logger LOG = LoggerFactory.getLogger("test");
try {
// something that can go wrong
} catch (XYZException exception) {
LOG.error("abc went wrong while doing xyz: {}", exception.getMessage());
LOG.debug("Caught {}", exception);
}
14:43:49.894 Scenario: Search (file:///.../features/integration/Google.feature:4)
14:43:51.748 ██ Step: I am on the homepage
14:43:51.765 ██▓▓ Entering GoogleSteps:homepage
14:43:51.784 ██▓▓▒▒ Verifying screen identifiers for GooglePage
14:43:51.838 ██▓▓▒▒ Finding element By.cssSelector: input[name=q]
14:43:51.907 ██▓▓▒▒ Finding element By.cssSelector: input[name=q]
14:43:51.947 ██▓▓▒▒ [OK] SEARCH_FIELD is displayed css:input[name=q]
14:43:51.948 ██▓▓ Entering GooglePage:enterSearchTerm [arg0=Search [searchTerm=I'm feeling lucky!]]
14:43:51.951 ██▓▓▒▒ Finding element By.cssSelector: input[name=q]
14:43:51.965 ██▓▓▒▒ Typing [I'm feeling lucky!] in [[ChromeDriver: chrome on MAC] -> css selector: input[name=q]]
14:45:13.979 Scenario: Use the search function (file:///.../features/stackoverflow/Search.feature:24)
14:45:18.963 ██ Step: I am on the homepage
14:45:18.978 ██▓▓ Entering HomeSteps:homepage
14:45:18.990 ██▓▓ Entering HomePage:load
14:45:19.797 ██▓▓▒▒ Navigating to https://www.stackoverflow.com
14:45:19.863 ██▓▓▒▒ Finding element By.xpath: //div[@id='js-gdpr-consent-banner']//a[contains(@aria-label,'notice-dismiss')]
14:45:19.956 ██▓▓▒▒ Finding element By.xpath: //div[@id='js-gdpr-consent-banner']//a[contains(@aria-label,'notice-dismiss')]
14:45:20.010 ██▓▓▒▒ Clicking on [[ChromeDriver: chrome on MAC] -> xpath: //div[@id='js-gdpr-consent-banner']//a[contains(@aria-label,'notice-dismiss')]]
14:45:20.076 ██▓▓ Exiting HomePage:load after 1086 ms
14:45:20.076 ██▓▓ Exiting HomeSteps:homepage after 1098 ms
LOG.info("Logging in user {} with password xxx on instance {}", user.getUsername(), instance.getURL());
LOG.info("Adding item {} (id: {}) to shopping cart with quantity {} and price {}", item.getId(), item.getTitle(), quantity, item.price());
LOG.error("Error adding item {} to shopping cart of user {}. Error message was: {} (Code {})", item.getId(), user.getUsername(), errorMessage, errorCode);
private static final Logger LOG = LoggerFactory.getLogger("test");
try {
// something that can go wrong
} catch (XYZException exception) {
LOG.error("abc went wrong while doing xyz", exception);
}
@martinschneider
martinschneider / logException1.java
Last active March 27, 2020 07:20
Omitting stacktrace
private static final Logger LOG = LoggerFactory.getLogger("test");
try {
// something that can go wrong
} catch (Exception e) {
LOG.error(e.getMessage());
}
<?xml version="1.0"?>
<configuration>
<contextListener
class="qa.justtestlah.log.ApplicationInfoEnricher" />
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%cyan(${appInfo}) %cyan(%d{HH:mm:ss.SSS}) %highlight(%.-1level) %cyan(%C{0}:%M:%L) %highlight(%msg) %n
</pattern>
</encoder>
package qa.justtestlah.log;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.LoggerContextListener;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.spi.LifeCycle;
import qa.justtestlah.configuration.PropertiesHolder;