Skip to content

Commit

Permalink
Added support for including throwables in log messages
Browse files Browse the repository at this point in the history
Updated README.md
Updated Gradle to 6.0.1
  • Loading branch information
djcass44 committed Dec 7, 2019
1 parent b9fe08a commit 7eb4d09
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 67 deletions.
50 changes: 32 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
# LOG2

Log2 is a simple library for showing pretty log statements.
Log2 is a library for simplifying logging. It uses Slf4j internally and therefore will not interfere with any custom logging solutions.

It is written in Kotlin and therefore should be fully interoperable with Java
It is written in Kotlin and therefore should be fully interoperable with Java.
If you are using ONLY Java, I'd recommend using Lombok's `@Slf4j` annotation instead.

Log2 is a rewrite of a project by the same name ([Log2](https://gitlab.com/django-sandbox/log2))
### Download
Log2 is designed at the Java 11 language level and therefore may or may not work in lower versions of Java. YMMV.

### Setup

Gradle:

1. In your root build.gradle
```gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
```groovy
repositories {
maven { url 'https://jitpack.io' }
}
```
```kotlin
repositories {
maven(url = "https://jitpack.io")
}
```
2. In your project build.gradle
```gradle
```groovy
dependencies {
implementation 'com.github.djcass44:log2:4.1'
}
```
```kotlin
dependencies {
implementation 'com.github.djcass44:log2:3.0'
implementation("com.github.djcass44:log2:4.1")
}
```
Maven:
Expand All @@ -40,7 +49,7 @@ Maven:
<dependency>
<groupId>com.github.djcass44</groupId>
<artifactId>log2</artifactId>
<version>3.0</version>
<version>4.1</version>
</dependency>
```

Expand All @@ -50,15 +59,20 @@ Maven:
Log.e(javaClass, "An error occurred!")
// Will print
// 1970-01-01 00:00:00 000 | [main] |-ERROR in org.example.test.TestLog - An error occurred!
// kotlin extensions
"An error has occurred!".loge(javaClass)
try {
something.throwsErr()
}
catch (e: Exception) {
// include a throwable to print to console
"Caught exception in somemethod".logf(javaClass, e)
}
```

**Additional options**

```Log.USE_SHORT_COLOURS```(default: true): Only colour the part of the log which shows severity

### License

Log2 is releasesed under the [Apache 2.0 license](LICENSE)
Log2 is released under the [Apache 2.0 license](LICENSE)
```
Copyright 2019 Django Cass
Expand Down
20 changes: 13 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ plugins {
}

group = "dev.castive"
version = "4.0"
version = "4.1"
val moduleName by extra("dev.castive.log2")
val javaHome: String = System.getProperty("java.home")

Expand All @@ -36,20 +36,26 @@ repositories {

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("org.slf4j:slf4j-simple:1.7.29")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.2.0")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.2.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.2.0")
val slfVersion = "1.7.29"
implementation("org.slf4j:slf4j-api:$slfVersion")


testImplementation("org.slf4j:slf4j-simple:$slfVersion")

val junitVersion = "5.5.2"
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
testImplementation("org.junit.jupiter:junit-jupiter-params:$junitVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
}
configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
tasks {
withType<Wrapper> {
gradleVersion = "5.6.4"
distributionType = Wrapper.DistributionType.BIN
gradleVersion = "6.0.1"
distributionType = Wrapper.DistributionType.ALL
}
withType<KotlinCompile>().all {
kotlinOptions.jvmTarget = "11"
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
22 changes: 19 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# Licensed 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.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -109,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
Expand Down
18 changes: 17 additions & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem 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, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
Expand All @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m"
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
30 changes: 20 additions & 10 deletions src/main/kotlin/dev/castive/log2/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,56 +26,66 @@ package dev.castive.log2
/**
* Show a verbose message
* @param src Calling class
* @param t the exception (throwable) to log
*/
public fun String.logv(src: Class<out Any>) = Log.v(src.name, this)
public fun String.logv(src: Class<out Any>, t: Throwable? = null) = Log.v(src.name, this, t)

/**
* Show a debug message
* @param src Calling class
* @param t the exception (throwable) to log
*/
public fun String.logd(src: Class<out Any>) = Log.d(src.name, this)
public fun String.logd(src: Class<out Any>, t: Throwable? = null) = Log.d(src.name, this, t)
/**
* Show an information message
* @param src Calling class
* @param t the exception (throwable) to log
*/
public fun String.logi(src: Class<out Any>) = Log.i(src.name, this)
public fun String.logi(src: Class<out Any>, t: Throwable? = null) = Log.i(src.name, this, t)
/**
* Show an ok message
* Indicates that something is working
* @param src Calling class
* @param t the exception (throwable) to log
*/
public fun String.logok(src: Class<out Any>) = Log.ok(src.name, this)
public fun String.logok(src: Class<out Any>, t: Throwable? = null) = Log.ok(src.name, this, t)
/**
* Show a good message
* Indicates that a task completed correctly or something went as expected
* @param src Calling class
* @param t the exception (throwable) to log
*/
public fun String.logg(src: Class<out Any>) = Log.good(src.name, this)
public fun String.logg(src: Class<out Any>, t: Throwable? = null) = Log.good(src.name, this, t)
/**
* Show an alert message
* Useful for highlighting something to the user
* @param src Calling class
* @param t the exception (throwable) to log
*/
public fun String.loga(src: Class<out Any>) = Log.a(src.name, this)
public fun String.loga(src: Class<out Any>, t: Throwable? = null) = Log.a(src.name, this, t)
/**
* Show a warning message
* @param src Calling class
* @param t the exception (throwable) to log
*/
public fun String.logw(src: Class<out Any>) = Log.w(src.name, this)
public fun String.logw(src: Class<out Any>, t: Throwable? = null) = Log.w(src.name, this, t)
/**
* Show an error message
* @param src Calling class
* @param t the exception (throwable) to log
*/
public fun String.loge(src: Class<out Any>) = Log.e(src.name, this)
public fun String.loge(src: Class<out Any>, t: Throwable? = null) = Log.e(src.name, this, t)
/**
* Show a fatal message
* Fatal messages indicate critical failure that cannot be recovered from
* @param src Calling class
* @param t the exception (throwable) to log
*/
public fun String.logf(src: Class<out Any>) = Log.f(src.name, this)
public fun String.logf(src: Class<out Any>, t: Throwable? = null) = Log.f(src.name, this, t)
/**
* Show a silent message
* Silent messages are always shown and cannot be hidden
* @param src Calling class
* @param t the exception (throwable) to log
*/
public fun String.logs(src: Class<out Any>) = Log.s(src.name, this)
public fun String.logs(src: Class<out Any>, t: Throwable? = null) = Log.s(src.name, this, t)
Loading

0 comments on commit 7eb4d09

Please sign in to comment.