diff --git a/.gitignore b/.gitignore
index f8b92c3..bcfaa2d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,11 @@
.gradle
+.project
+.settings/*
build
+.ackrc
+bin
+**target
+**.DS_Store
+**.vscode
+Main.java
+/src/main/resources
\ No newline at end of file
diff --git a/README.md b/README.md
index 742bb3d..f69733b 100644
--- a/README.md
+++ b/README.md
@@ -2,12 +2,16 @@
[![Build Status](https://travis-ci.org/airbrake/logback.svg?branch=master)](https://travis-ci.org/airbrake/logback)
+## Introduction
+
+logback is a logging Middleware in Java for Airbrake.
+
## Installation
Gradle:
```gradle
-compile 'io.airbrake:logback:0.1.1'
+compile 'io.airbrake:logback:0.1.2'
```
Maven:
@@ -16,19 +20,20 @@ Maven:
io.airbrake
logback
- 0.1.1
+ 0.1.2
```
Ivy:
```xml
-
+
```
## Configuration
+If you want to send the error logs to Airbrake, you need to have following lines in logback.xml. Add this file in the resources folder. This is the main file for logback configuration. and contains information about log levels, log appenders.
```xml
@@ -53,3 +58,48 @@ Ivy:
```
+## Error Logging
+
+```java
+import org.slf4j.LoggerFactory;
+import ch.qos.logback.classic.Logger;
+
+Logger logger = ((ch.qos.logback.classic.Logger))LoggerFactory.getLogger("Name");
+
+try {
+ do();
+} catch (IOException e) {
+ logger.error(e.getMessage());
+}
+```
+
+## Notifier release instrucitons
+
+### A note on Java version
+Make sure you build and release this notifier with open-jdk, one way to manage your local java version is using [asdf](https://asdf-vm.com). You can install this tool via homebrew:
+```
+brew install asdf
+```
+Then install open-jdk-'mention version here' and set it as JAVA home before running any of the `./gradlew` commands:
+```
+asdf plugin add java
+asdf install java openjdk-'mention version here'
+export JAVA_HOME=$HOME/.asdf/installs/java/openjdk-'mention version here'
+```
+
+### Building and Releasing
+
+```shell
+./gradlew build
+```
+Upload to Maven Central:
+
+```shell
+./gradlew publish
+```
+
+To release the deployment to maven central repository:
+ - http://central.sonatype.org/pages/releasing-the-deployment.html
+
+Usefull links:
+ - https://search.maven.org/artifact/io.airbrake/logback
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 482fe7c..c8c72e9 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,20 +3,24 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.11.0"
+ classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0"
}
}
-plugins {
- id 'com.jfrog.bintray' version '1.7.3'
-}
+ plugins {
+ id 'java'
+ id 'java-library'
+ id 'maven-publish'
+ id 'signing'
+ }
-apply plugin: 'maven'
-apply plugin: 'java-library'
-apply plugin: 'io.codearte.nexus-staging'
+ apply plugin: 'io.codearte.nexus-staging'
group = 'io.airbrake'
-version = '0.1.1'
+version = '0.1.2'
+sourceCompatibility = 1.8
+targetCompatibility = 1.8
+
if (project.hasProperty('signing.keyId')) {
apply plugin: 'signing'
@@ -26,15 +30,18 @@ if (project.hasProperty('signing.keyId')) {
}
repositories {
- jcenter()
+ mavenCentral()
}
dependencies {
- compile 'io.airbrake:javabrake:0.1.6'
- compile 'ch.qos.logback:logback-classic:1.2.3'
- compile 'org.slf4j:slf4j-api:1.7.25'
+ implementation 'io.airbrake:javabrake:0.3.0'
+ implementation 'ch.qos.logback:logback-classic:1.3.5'
+ testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
+}
- testImplementation 'junit:junit:4.12'
+java{
+ withJavadocJar()
+ withSourcesJar()
}
test {
@@ -48,105 +55,64 @@ test {
}
}
-bintray {
- user = System.getenv('BINTRAY_USER')
- key = System.getenv('BINTRAY_KEY')
- configurations = ['archives']
- publish = true
- override = true
- pkg {
- repo = 'maven'
- name = project.name
- userOrg = 'airbrake'
- licenses = ['MIT']
- vcsUrl = 'https://github.com/airbrake/logback.git'
- version {
- name = project.version
- desc = 'logback integration for javabrake'
- vcsTag = project.version
- }
- }
-}
-
-if (project.hasProperty('ossrhUsername')) {
- uploadArchives {
- repositories {
- mavenDeployer {
- beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
-
- repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2") {
- authentication(userName: ossrhUsername, password: ossrhPassword)
- }
-
- snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots") {
- authentication(userName: ossrhUsername, password: ossrhPassword)
- }
-
- pom.project {
- name project.name
- packaging 'jar'
- description 'Logback integration for javabrake'
- url 'https://airbrake.io'
-
- scm {
- connection 'https://github.com/airbrake/logback.git'
- developerConnection 'https://github.com/airbrake/logback.git'
- url 'https://github.com/airbrake/logback'
- }
-
- licenses {
- license {
- name 'MIT License'
- url 'https://opensource.org/licenses/MIT'
- }
- }
+publishing {
+ publications{
+
+ mavenJava(MavenPublication){
+
+ group = 'io.airbrake'
+ artifactId = 'logback'
+ version = '0.1.2'
+ description = 'logback integration for javabrake'
+ from(components.java)
+
+
+ pom{
+ name = 'logback'
+ url = 'https://airbrake.io'
+ description = 'Logback integration for javabrake'
+ licenses {
+ license {
+ name = 'MIT License'
+ url = 'https://opensource.org/licenses/MIT'
+ }
+ }
+ developers {
+ developer {
+ id = 'sumitjoshi1989'
+ name = 'Sumit Joshi'
+ email = 'joshisumitsunil@gmail.com'
+ }
+ }
+ scm {
+ connection = 'scm:git:git:github.com/airbrake/logback.git'
+ developerConnection = 'scm:git:ssh://github.com/airbrake/logback.git'
+ url = 'https://github.com/airbrake/logback'
+ }
- developers {
- developer {
- id 'vmihailenco'
- name 'Vladimir Mihailenco'
- email 'vladimir.webdev@gmail.com'
}
- }
}
- }
}
- }
-}
-
-task sourcesJar(type: Jar, dependsOn: classes) {
- classifier = 'sources'
- from sourceSets.main.allSource
-}
-
-task javadocJar(type: Jar, dependsOn: javadoc) {
- classifier = 'javadoc'
- from javadoc.destinationDir
+ repositories{
+ maven{
+
+ name = 'OSSRH'
+ url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
+ // url = 'https://oss.sonatype.org/content/repositories/snapshots'
+ credentials {
+ username = project.properties["ossrhUsername"]
+ password = project.properties["ossrhPassword"]
+ }
+
+ }
+ }
+
}
-artifacts {
- archives sourcesJar
- archives javadocJar
+signing {
+ sign publishing.publications.mavenJava
}
-task createPom {
- doLast {
- pom {
- project {
- groupId project.group
- artifactId project.name
- version project.version
-
- inceptionYear '2017'
- licenses {
- license {
- name 'MIT License'
- url 'http://www.opensource.org/licenses/mit-license.php'
- distribution 'repo'
- }
- }
- }
- }.writeTo("pom.xml")
- }
-}
-build.dependsOn createPom
+javadoc{
+
+}
\ No newline at end of file
diff --git a/examples/springboot/.gitignore b/examples/springboot/.gitignore
new file mode 100644
index 0000000..549e00a
--- /dev/null
+++ b/examples/springboot/.gitignore
@@ -0,0 +1,33 @@
+HELP.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
diff --git a/examples/springboot/.mvn/wrapper/maven-wrapper.jar b/examples/springboot/.mvn/wrapper/maven-wrapper.jar
new file mode 100644
index 0000000..c1dd12f
Binary files /dev/null and b/examples/springboot/.mvn/wrapper/maven-wrapper.jar differ
diff --git a/examples/springboot/.mvn/wrapper/maven-wrapper.properties b/examples/springboot/.mvn/wrapper/maven-wrapper.properties
new file mode 100644
index 0000000..b7cb93e
--- /dev/null
+++ b/examples/springboot/.mvn/wrapper/maven-wrapper.properties
@@ -0,0 +1,2 @@
+distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip
+wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
diff --git a/examples/springboot/README.md b/examples/springboot/README.md
new file mode 100644
index 0000000..50435dc
--- /dev/null
+++ b/examples/springboot/README.md
@@ -0,0 +1,53 @@
+# Spring Boot Sample Application for JavaBrake
+
+## About the application
+
+The example application provides three GET endpoints:
+
+1. `/date` - returns server date and time.
+2. `/locations` - returns list of available locations.
+3. `/weather/{locationName}` - returns the weather details for the locations.
+
+## Steps to run the API
+
+1. Install the dependencies for the application
+
+ ```
+ mvn install
+ ```
+
+2. You must get both `project_id` & `project_key`.
+
+ Find your `project_id` and `project_key` in your Airbrake account and replace them in `application.properties` file.
+
+ ```java
+ airbrake.project.id=project_id
+ airbrake.project.key=project_key
+ ```
+
+3. Run the application
+
+4. To retrieve the responses, append the endpoints to the localhost URL.
+
+ Use the below curl commands to interact with the endpoints.
+
+ ```bash
+ curl "http://localhost:8080/date"
+ curl "http://localhost:8080/locations"
+ curl "http://localhost:8080/weather/"
+ ```
+
+ The below curl command will raise `404 Not Found` error.
+
+ ```bash
+ curl -I "http://localhost:8080/weather"
+ ```
+
+ The below curl command will raise `500 Internal server error` error.
+
+ ```bash
+ # Should produce an intentional HTTP 500 error and report the error to Airbrake (since `washington` is in the supported cities list but there is no data for `washington`, an `if` condition is bypassed and the `data` variable is used but not initialized)
+ curl -I "http://localhost:8080/weather/washington"
+ ```
+
+ Or you can use Postman application.
\ No newline at end of file
diff --git a/examples/springboot/mvnw b/examples/springboot/mvnw
new file mode 100755
index 0000000..8a8fb22
--- /dev/null
+++ b/examples/springboot/mvnw
@@ -0,0 +1,316 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ----------------------------------------------------------------------------
+
+# ----------------------------------------------------------------------------
+# Maven Start Up Batch script
+#
+# Required ENV vars:
+# ------------------
+# JAVA_HOME - location of a JDK home dir
+#
+# Optional ENV vars
+# -----------------
+# M2_HOME - location of maven2's installed home dir
+# MAVEN_OPTS - parameters passed to the Java VM when running Maven
+# e.g. to debug Maven itself, use
+# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+# ----------------------------------------------------------------------------
+
+if [ -z "$MAVEN_SKIP_RC" ] ; then
+
+ if [ -f /usr/local/etc/mavenrc ] ; then
+ . /usr/local/etc/mavenrc
+ fi
+
+ if [ -f /etc/mavenrc ] ; then
+ . /etc/mavenrc
+ fi
+
+ if [ -f "$HOME/.mavenrc" ] ; then
+ . "$HOME/.mavenrc"
+ fi
+
+fi
+
+# OS specific support. $var _must_ be set to either true or false.
+cygwin=false;
+darwin=false;
+mingw=false
+case "`uname`" in
+ CYGWIN*) cygwin=true ;;
+ MINGW*) mingw=true;;
+ Darwin*) darwin=true
+ # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
+ # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
+ if [ -z "$JAVA_HOME" ]; then
+ if [ -x "/usr/libexec/java_home" ]; then
+ export JAVA_HOME="`/usr/libexec/java_home`"
+ else
+ export JAVA_HOME="/Library/Java/Home"
+ fi
+ fi
+ ;;
+esac
+
+if [ -z "$JAVA_HOME" ] ; then
+ if [ -r /etc/gentoo-release ] ; then
+ JAVA_HOME=`java-config --jre-home`
+ fi
+fi
+
+if [ -z "$M2_HOME" ] ; then
+ ## resolve links - $0 may be a link to maven's home
+ PRG="$0"
+
+ # need this for relative symlinks
+ while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG="`dirname "$PRG"`/$link"
+ fi
+ done
+
+ saveddir=`pwd`
+
+ M2_HOME=`dirname "$PRG"`/..
+
+ # make it fully qualified
+ M2_HOME=`cd "$M2_HOME" && pwd`
+
+ cd "$saveddir"
+ # echo Using m2 at $M2_HOME
+fi
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME=`cygpath --unix "$M2_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+ [ -n "$CLASSPATH" ] &&
+ CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
+fi
+
+# For Mingw, ensure paths are in UNIX format before anything is touched
+if $mingw ; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME="`(cd "$M2_HOME"; pwd)`"
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
+fi
+
+if [ -z "$JAVA_HOME" ]; then
+ javaExecutable="`which javac`"
+ if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
+ # readlink(1) is not available as standard on Solaris 10.
+ readLink=`which readlink`
+ if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
+ if $darwin ; then
+ javaHome="`dirname \"$javaExecutable\"`"
+ javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
+ else
+ javaExecutable="`readlink -f \"$javaExecutable\"`"
+ fi
+ javaHome="`dirname \"$javaExecutable\"`"
+ javaHome=`expr "$javaHome" : '\(.*\)/bin'`
+ JAVA_HOME="$javaHome"
+ export JAVA_HOME
+ fi
+ fi
+fi
+
+if [ -z "$JAVACMD" ] ; then
+ if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ else
+ JAVACMD="`\\unset -f command; \\command -v java`"
+ fi
+fi
+
+if [ ! -x "$JAVACMD" ] ; then
+ echo "Error: JAVA_HOME is not defined correctly." >&2
+ echo " We cannot execute $JAVACMD" >&2
+ exit 1
+fi
+
+if [ -z "$JAVA_HOME" ] ; then
+ echo "Warning: JAVA_HOME environment variable is not set."
+fi
+
+CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
+
+# traverses directory structure from process work directory to filesystem root
+# first directory with .mvn subdirectory is considered project base directory
+find_maven_basedir() {
+
+ if [ -z "$1" ]
+ then
+ echo "Path not specified to find_maven_basedir"
+ return 1
+ fi
+
+ basedir="$1"
+ wdir="$1"
+ while [ "$wdir" != '/' ] ; do
+ if [ -d "$wdir"/.mvn ] ; then
+ basedir=$wdir
+ break
+ fi
+ # workaround for JBEAP-8937 (on Solaris 10/Sparc)
+ if [ -d "${wdir}" ]; then
+ wdir=`cd "$wdir/.."; pwd`
+ fi
+ # end of workaround
+ done
+ echo "${basedir}"
+}
+
+# concatenates all lines of a file
+concat_lines() {
+ if [ -f "$1" ]; then
+ echo "$(tr -s '\n' ' ' < "$1")"
+ fi
+}
+
+BASE_DIR=`find_maven_basedir "$(pwd)"`
+if [ -z "$BASE_DIR" ]; then
+ exit 1;
+fi
+
+##########################################################################################
+# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+# This allows using the maven wrapper in projects that prohibit checking in binary data.
+##########################################################################################
+if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found .mvn/wrapper/maven-wrapper.jar"
+ fi
+else
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
+ fi
+ if [ -n "$MVNW_REPOURL" ]; then
+ jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
+ else
+ jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
+ fi
+ while IFS="=" read key value; do
+ case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
+ esac
+ done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Downloading from: $jarUrl"
+ fi
+ wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
+ if $cygwin; then
+ wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
+ fi
+
+ if command -v wget > /dev/null; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found wget ... using wget"
+ fi
+ if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
+ wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
+ else
+ wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
+ fi
+ elif command -v curl > /dev/null; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found curl ... using curl"
+ fi
+ if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
+ curl -o "$wrapperJarPath" "$jarUrl" -f
+ else
+ curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
+ fi
+
+ else
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Falling back to using Java to download"
+ fi
+ javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
+ # For Cygwin, switch paths to Windows format before running javac
+ if $cygwin; then
+ javaClass=`cygpath --path --windows "$javaClass"`
+ fi
+ if [ -e "$javaClass" ]; then
+ if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo " - Compiling MavenWrapperDownloader.java ..."
+ fi
+ # Compiling the Java class
+ ("$JAVA_HOME/bin/javac" "$javaClass")
+ fi
+ if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+ # Running the downloader
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo " - Running MavenWrapperDownloader.java ..."
+ fi
+ ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
+ fi
+ fi
+ fi
+fi
+##########################################################################################
+# End of extension
+##########################################################################################
+
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
+if [ "$MVNW_VERBOSE" = true ]; then
+ echo $MAVEN_PROJECTBASEDIR
+fi
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME=`cygpath --path --windows "$M2_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+ [ -n "$CLASSPATH" ] &&
+ CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+ [ -n "$MAVEN_PROJECTBASEDIR" ] &&
+ MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
+fi
+
+# Provide a "standardized" way to retrieve the CLI args that will
+# work with both Windows and non-Windows executions.
+MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
+export MAVEN_CMD_LINE_ARGS
+
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+exec "$JAVACMD" \
+ $MAVEN_OPTS \
+ $MAVEN_DEBUG_OPTS \
+ -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
+ "-Dmaven.home=${M2_HOME}" \
+ "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
+ ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
diff --git a/examples/springboot/mvnw.cmd b/examples/springboot/mvnw.cmd
new file mode 100644
index 0000000..1d8ab01
--- /dev/null
+++ b/examples/springboot/mvnw.cmd
@@ -0,0 +1,188 @@
+@REM ----------------------------------------------------------------------------
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements. See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership. The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License. You may obtain a copy of the License at
+@REM
+@REM https://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied. See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM ----------------------------------------------------------------------------
+
+@REM ----------------------------------------------------------------------------
+@REM Maven Start Up Batch script
+@REM
+@REM Required ENV vars:
+@REM JAVA_HOME - location of a JDK home dir
+@REM
+@REM Optional ENV vars
+@REM M2_HOME - location of maven2's installed home dir
+@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
+@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
+@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
+@REM e.g. to debug Maven itself, use
+@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+@REM ----------------------------------------------------------------------------
+
+@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
+@echo off
+@REM set title of command window
+title %0
+@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
+@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
+
+@REM set %HOME% to equivalent of $HOME
+if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
+
+@REM Execute a user defined script before this one
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
+@REM check for pre script, once with legacy .bat ending and once with .cmd ending
+if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
+if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
+:skipRcPre
+
+@setlocal
+
+set ERROR_CODE=0
+
+@REM To isolate internal variables from possible post scripts, we use another setlocal
+@setlocal
+
+@REM ==== START VALIDATION ====
+if not "%JAVA_HOME%" == "" goto OkJHome
+
+echo.
+echo Error: JAVA_HOME not found in your environment. >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+:OkJHome
+if exist "%JAVA_HOME%\bin\java.exe" goto init
+
+echo.
+echo Error: JAVA_HOME is set to an invalid directory. >&2
+echo JAVA_HOME = "%JAVA_HOME%" >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+@REM ==== END VALIDATION ====
+
+:init
+
+@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
+@REM Fallback to current working directory if not found.
+
+set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
+IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
+
+set EXEC_DIR=%CD%
+set WDIR=%EXEC_DIR%
+:findBaseDir
+IF EXIST "%WDIR%"\.mvn goto baseDirFound
+cd ..
+IF "%WDIR%"=="%CD%" goto baseDirNotFound
+set WDIR=%CD%
+goto findBaseDir
+
+:baseDirFound
+set MAVEN_PROJECTBASEDIR=%WDIR%
+cd "%EXEC_DIR%"
+goto endDetectBaseDir
+
+:baseDirNotFound
+set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
+cd "%EXEC_DIR%"
+
+:endDetectBaseDir
+
+IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
+
+@setlocal EnableExtensions EnableDelayedExpansion
+for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
+@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
+
+:endReadAdditionalConfig
+
+SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
+set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
+set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
+
+FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
+ IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
+)
+
+@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
+if exist %WRAPPER_JAR% (
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Found %WRAPPER_JAR%
+ )
+) else (
+ if not "%MVNW_REPOURL%" == "" (
+ SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
+ )
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Couldn't find %WRAPPER_JAR%, downloading it ...
+ echo Downloading from: %DOWNLOAD_URL%
+ )
+
+ powershell -Command "&{"^
+ "$webclient = new-object System.Net.WebClient;"^
+ "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
+ "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
+ "}"^
+ "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
+ "}"
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Finished downloading %WRAPPER_JAR%
+ )
+)
+@REM End of extension
+
+@REM Provide a "standardized" way to retrieve the CLI args that will
+@REM work with both Windows and non-Windows executions.
+set MAVEN_CMD_LINE_ARGS=%*
+
+%MAVEN_JAVA_EXE% ^
+ %JVM_CONFIG_MAVEN_PROPS% ^
+ %MAVEN_OPTS% ^
+ %MAVEN_DEBUG_OPTS% ^
+ -classpath %WRAPPER_JAR% ^
+ "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
+ %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
+if ERRORLEVEL 1 goto error
+goto end
+
+:error
+set ERROR_CODE=1
+
+:end
+@endlocal & set ERROR_CODE=%ERROR_CODE%
+
+if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
+@REM check for post script, once with legacy .bat ending and once with .cmd ending
+if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
+if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
+:skipRcPost
+
+@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
+if "%MAVEN_BATCH_PAUSE%"=="on" pause
+
+if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
+
+cmd /C exit /B %ERROR_CODE%
diff --git a/examples/springboot/pom.xml b/examples/springboot/pom.xml
new file mode 100644
index 0000000..2c3cd02
--- /dev/null
+++ b/examples/springboot/pom.xml
@@ -0,0 +1,49 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.7.3
+
+
+ io.airbrake
+ weather
+ 0.0.1-SNAPSHOT
+ jar
+ weather
+ Demo weather project using Airbrake with Spring Boot
+
+ 17
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ io.airbrake
+ logback
+ 0.1.2
+
+
+ org.springframework.boot
+ spring-boot-starter-tomcat
+ provided
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
diff --git a/examples/springboot/src/main/java/io/airbrake/weather/GlobalExceptionContoller.java b/examples/springboot/src/main/java/io/airbrake/weather/GlobalExceptionContoller.java
new file mode 100644
index 0000000..4dfc32d
--- /dev/null
+++ b/examples/springboot/src/main/java/io/airbrake/weather/GlobalExceptionContoller.java
@@ -0,0 +1,20 @@
+package io.airbrake.weather;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+
+import ch.qos.logback.classic.Logger;
+
+@ControllerAdvice
+public class GlobalExceptionContoller {
+
+ @Autowired
+ Logger logger;
+
+ @ExceptionHandler(Exception.class)
+ public void ExceptionHandling(Exception e)
+ {
+ logger.error(e.getMessage());
+ }
+}
diff --git a/examples/springboot/src/main/java/io/airbrake/weather/WeatherApplication.java b/examples/springboot/src/main/java/io/airbrake/weather/WeatherApplication.java
new file mode 100644
index 0000000..1769324
--- /dev/null
+++ b/examples/springboot/src/main/java/io/airbrake/weather/WeatherApplication.java
@@ -0,0 +1,29 @@
+package io.airbrake.weather;
+
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.client.RestTemplate;
+import ch.qos.logback.classic.Logger;
+
+
+@SpringBootApplication
+public class WeatherApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(WeatherApplication.class, args);
+ }
+
+ @Bean
+ public RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+
+ @Bean
+ public Logger getLogger() {
+
+ Logger logger = (Logger) LoggerFactory.getLogger("Airbrake");
+ return logger;
+ }
+}
\ No newline at end of file
diff --git a/examples/springboot/src/main/java/io/airbrake/weather/WeatherController.java b/examples/springboot/src/main/java/io/airbrake/weather/WeatherController.java
new file mode 100644
index 0000000..80409ef
--- /dev/null
+++ b/examples/springboot/src/main/java/io/airbrake/weather/WeatherController.java
@@ -0,0 +1,43 @@
+package io.airbrake.weather;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+
+
+@RestController("api")
+@RequestMapping(value="/api")
+public class WeatherController {
+
+ @Autowired
+ WeatherService weatherService;
+
+ @GetMapping("/date")
+ public String date() {
+
+ return weatherService.getDate();
+ }
+
+ @GetMapping("/locations")
+ public String locations() {
+
+ return weatherService.getLocations();
+ }
+
+ @GetMapping("/weather/{location}")
+ public String weather(@PathVariable String location) {
+
+ return weatherService.getWeather(location);
+
+ }
+
+ @GetMapping("/weather1/{location}")
+ public String weatherTryCatch(@PathVariable String location) {
+
+ return weatherService.getWeatherTryCatch(location);
+
+ }
+}
diff --git a/examples/springboot/src/main/java/io/airbrake/weather/WeatherService.java b/examples/springboot/src/main/java/io/airbrake/weather/WeatherService.java
new file mode 100644
index 0000000..f71c854
--- /dev/null
+++ b/examples/springboot/src/main/java/io/airbrake/weather/WeatherService.java
@@ -0,0 +1,64 @@
+package io.airbrake.weather;
+
+import java.util.Date;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+import ch.qos.logback.classic.Logger;
+
+@Service
+public class WeatherService {
+
+ @Value("${airbrake.baseurl}")
+ private String baseUrl;
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ @Autowired
+ Logger logger;
+
+ public String getDate() {
+ String url = baseUrl + "/date";
+ String resp = this.restTemplate.getForObject(url, String.class);
+ long l = Long.parseLong(resp.trim());
+ Date d = new Date(l * 1000);
+
+ return d.toString();
+ }
+
+ public String getLocations() {
+ String url = baseUrl + "/locations";
+ String resp = this.restTemplate.getForObject(url, String.class);
+
+ return resp;
+ }
+
+ // Api is to check location is available or not?
+ // If not then it will given an exception. Exception will get reported to
+ // airbrake protal through GlobalExceptionController.
+ public String getWeather(String location) {
+ String url = baseUrl + "/weather/{location}";
+ ResponseEntity resp = new ResponseEntity<>(HttpStatus.OK);
+ resp = this.restTemplate.getForEntity(url, String.class, location);
+
+ return resp.getBody();
+ }
+
+ // Using try-catch exception will get reported to airbrake protal
+ public String getWeatherTryCatch(String location) {
+ String url = baseUrl + "/weather/{location}";
+ ResponseEntity resp = new ResponseEntity<>(HttpStatus.OK);
+ try {
+ resp = this.restTemplate.getForEntity(url, String.class, location);
+ } catch (Exception e) {
+ logger.error("Message: "+e.getMessage());
+ }
+ return resp.getBody();
+ }
+
+}
diff --git a/examples/springboot/src/main/resources/application.properties b/examples/springboot/src/main/resources/application.properties
new file mode 100644
index 0000000..a29c153
--- /dev/null
+++ b/examples/springboot/src/main/resources/application.properties
@@ -0,0 +1,2 @@
+airbrake.baseurl=https://airbrake.github.io/weatherapi
+
diff --git a/examples/springboot/src/main/resources/logback.xml b/examples/springboot/src/main/resources/logback.xml
new file mode 100644
index 0000000..a721c9d
--- /dev/null
+++ b/examples/springboot/src/main/resources/logback.xml
@@ -0,0 +1,22 @@
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+ 123456
+ FIXME
+ test
+
+ ERROR
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/springboot/src/test/java/io/airbrake/weather/WeatherApplicationTests.java b/examples/springboot/src/test/java/io/airbrake/weather/WeatherApplicationTests.java
new file mode 100644
index 0000000..ee24e1a
--- /dev/null
+++ b/examples/springboot/src/test/java/io/airbrake/weather/WeatherApplicationTests.java
@@ -0,0 +1,49 @@
+package io.airbrake.weather;
+
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+
+@SpringBootTest
+class WeatherApplicationTests {
+
+ @Autowired
+ WeatherService weatherService;
+
+
+ @Test
+ void getDate() {
+
+ assertNotNull(weatherService.getDate());
+ }
+
+ @Test
+ void getLocations() {
+
+ assertNotNull(weatherService.getLocations());
+ }
+
+ @Test
+ void getWeather() {
+
+ assertNotNull(weatherService.getWeather("austin"));
+ }
+
+ @Test
+ public void checkIfWeatherIsNotAvailable() {
+ Exception exception = assertThrows(org.springframework.web.client.HttpClientErrorException.class, () -> {
+ weatherService.getWeather("boston");
+ });
+
+ String expectedMessage = "404 Not Found:";
+ String actualMessage = exception.getMessage();
+
+ assertTrue(actualMessage.contains(expectedMessage));
+}
+}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index e0b3fb8..aa991fc 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/pom.xml b/pom.xml
index 9f055fb..3246beb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
io.airbrake
logback
- 0.1.1
+ 0.1.2
2017
@@ -17,25 +17,19 @@
io.airbrake
javabrake
- 0.1.6
+ 0.3.0
compile
ch.qos.logback
logback-classic
- 1.2.3
+ 1.3.5
compile
- org.slf4j
- slf4j-api
- 1.7.25
- compile
-
-
- junit
- junit
- 4.12
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.8.1
test
diff --git a/src/main/java/AirbrakeAppender.java b/src/main/java/io/airbrake/logback/AirbrakeAppender.java
similarity index 84%
rename from src/main/java/AirbrakeAppender.java
rename to src/main/java/io/airbrake/logback/AirbrakeAppender.java
index 8dc46fe..2fa3f4e 100644
--- a/src/main/java/AirbrakeAppender.java
+++ b/src/main/java/io/airbrake/logback/AirbrakeAppender.java
@@ -3,24 +3,22 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.Future;
-
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.classic.spi.StackTraceElementProxy;
import ch.qos.logback.core.AppenderBase;
-
import io.airbrake.javabrake.Notifier;
import io.airbrake.javabrake.Airbrake;
+import io.airbrake.javabrake.Config;
import io.airbrake.javabrake.Notice;
import io.airbrake.javabrake.NoticeError;
public class AirbrakeAppender extends AppenderBase {
- int projectId;
- String projectKey;
- String env;
+
Notifier notifier;
+ int projectId;
+ String projectKey;String env;
public void setProjectId(int projectId) {
this.projectId = projectId;
@@ -36,11 +34,14 @@ public void setEnv(String env) {
this.env = env;
}
- void initNotifier() {
- if (this.projectId == 0 || this.projectKey == null) {
+ public void initNotifier() {
+ if (projectId == 0 || projectKey == null) {
return;
}
- this.notifier = new Notifier(projectId, projectKey);
+ Config config = new Config();
+ config.projectId = projectId;
+ config.projectKey = projectKey;
+ this.notifier = new Notifier(config);
}
@Override
@@ -54,20 +55,20 @@ protected void append(ILoggingEvent event) {
errors.add(err);
Notice notice = new Notice(errors);
- if (this.env != null) {
+ if (this.env != null) {
notice.setContext("environment", this.env);
}
notice.setContext("severity", formatLevel(event.getLevel()));
notice.setParam("threadName", event.getThreadName());
Map mdc = event.getMDCPropertyMap();
- if (mdc.size() > 0) {
+ if (mdc !=null && mdc.size() > 0) {
notice.setParam("mdc", mdc);
}
Map ctx = event.getLoggerContextVO().getPropertyMap();
- if (ctx.size() > 0) {
+ if (ctx!= null && ctx.size() > 0) {
notice.setParam("contextV0", ctx);
}
- if (event.getMarker() != null) {
+ if (event.getMarker() != null ) {
notice.setParam("marker", event.getMarker().getName());
}
this.send(notice);
@@ -112,10 +113,10 @@ static String formatLevel(Level level) {
return "trace";
}
- Future send(Notice notice) {
+ Notice send(Notice notice) {
if (this.notifier != null) {
- return this.notifier.send(notice);
+ return this.notifier.sendSync(notice);
}
- return Airbrake.send(notice);
+ return Airbrake.sendSync(notice);
}
}
diff --git a/src/test/java/TestAsyncSender.java b/src/test/java/TestAsyncSender.java
deleted file mode 100644
index f6685d2..0000000
--- a/src/test/java/TestAsyncSender.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package io.airbrake.logback;
-
-import java.util.concurrent.CompletableFuture;
-
-import io.airbrake.javabrake.Notice;
-import io.airbrake.javabrake.AsyncSender;
-
-class TestAsyncSender implements AsyncSender {
- public Notice notice;
-
- @Override
- public CompletableFuture send(Notice notice) {
- this.notice = notice;
- return new CompletableFuture();
- }
-
- @Override
- public void setHost(String host) {}
-}
diff --git a/src/test/java/AirbrakeAppenderTest.java b/src/test/java/io/airbrake/logback/AirbrakeAppenderTest.java
similarity index 64%
rename from src/test/java/AirbrakeAppenderTest.java
rename to src/test/java/io/airbrake/logback/AirbrakeAppenderTest.java
index 8bb5b72..493e140 100644
--- a/src/test/java/AirbrakeAppenderTest.java
+++ b/src/test/java/io/airbrake/logback/AirbrakeAppenderTest.java
@@ -1,28 +1,35 @@
package io.airbrake.logback;
import java.io.IOException;
-
-import org.slf4j.LoggerFactory;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import ch.qos.logback.classic.LoggerContext;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.BeforeClass;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import io.airbrake.javabrake.NoticeError;
import io.airbrake.javabrake.Airbrake;
+import io.airbrake.javabrake.Config;
import io.airbrake.javabrake.NoticeStackFrame;
import io.airbrake.javabrake.Notifier;
public class AirbrakeAppenderTest {
- Notifier notifier = new Notifier(0, "");
+ static Notifier notifier;
Throwable exc = new IOException("hello from Java");
- TestAsyncSender sender = new TestAsyncSender();
+ MockSyncSender senderSync = new MockSyncSender();
- @BeforeClass
+ @BeforeAll
public static void beforeClass() {
+ Config config = new Config();
+ config.projectId = 0;
+ config.projectKey = "";
+ notifier = new Notifier(config);
+
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
ch.qos.logback.classic.Logger logger = context.getLogger("io.airbrake.logback");
@@ -32,9 +39,9 @@ public static void beforeClass() {
logger.addAppender(app);
}
- @Before
+ @BeforeEach
public void before() {
- notifier.setAsyncSender(sender);
+ notifier.setSyncSender(senderSync);
Airbrake.setNotifier(notifier);
}
@@ -43,7 +50,7 @@ public void testLogException() {
Logger logger = LoggerFactory.getLogger("io.airbrake.logback");
logger.error("hello from Java", exc);
- NoticeError err = sender.notice.errors.get(0);
+ NoticeError err = senderSync.notice.errors.get(0);
assertEquals("java.io.IOException", err.type);
assertEquals("hello from Java", err.message);
}
@@ -53,13 +60,13 @@ public void testLogMessage() {
Logger logger = LoggerFactory.getLogger("io.airbrake.logback");
logger.error("hello from Java");
- NoticeError err = sender.notice.errors.get(0);
+ NoticeError err = senderSync.notice.errors.get(0);
assertEquals("io.airbrake.logback", err.type);
assertEquals("hello from Java", err.message);
NoticeStackFrame frame = err.backtrace[0];
assertEquals("testLogMessage", frame.function);
- assertEquals("test/io/airbrake/logback/AirbrakeAppenderTest.class", frame.file);
- assertEquals(54, frame.line);
+ assertTrue(frame.file.contains("test/io/airbrake/logback/AirbrakeAppenderTest.class"));
+ assertEquals(65, frame.line);
}
}
diff --git a/src/test/java/io/airbrake/logback/MockSyncSender.java b/src/test/java/io/airbrake/logback/MockSyncSender.java
new file mode 100644
index 0000000..e5be17a
--- /dev/null
+++ b/src/test/java/io/airbrake/logback/MockSyncSender.java
@@ -0,0 +1,26 @@
+package io.airbrake.logback;
+
+import io.airbrake.javabrake.Notice;
+import io.airbrake.javabrake.SyncSender;
+
+class MockSyncSender implements SyncSender {
+ public Notice notice;
+
+ @Override
+ public Notice send(Notice notice) {
+ this.notice = notice;
+ return notice;
+ }
+
+ @Override
+ public void setErrorHost(String host) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setAPMHost(String host) {
+ // TODO Auto-generated method stub
+
+ }
+}