Logback and Spring Boot - Change Log Level to custom format

Create a custom converter This class converts the well known log levels to a custom format CustomLogLevelConverter.java package com.hascode; public class CustomLogLevelConverter extends ClassicConverter { @Override public String convert(ILoggingEvent event) { switch (event.getLevel().toInt()) { case Level.ERROR_INT: return "ERROR!!!"; case Level.WARN_INT: return "WARN!!"; case Level.INFO_INT: return "INFO!"; case Level.TRACE_INT: return "DEBUG"; default: return event.getLevel().toString(); } } } Register the converter The following Logback config includes some defaults and registers our custom converter. ...

August 19, 2021 · 1 min · 165 words · Micha Kops

Sensor Fun: Location Based Services and GPS for Android

The Android SDK offers a nice API to receive information about available providers for location based services and get the current location and coordinates. In this short tutorial we’re going to build a small activity that displays a list of available location providers and shows the current position using GPS services. Example Application Create a new Android Project using ADT and your IDE with a package named com.hascode.android.location_app Add the permissions needed to the AndroidManifest.xml – it should look like this <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hascode.android.location_app" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".LocationActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="7" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission> <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission> </manifest> ...

May 30, 2010 · 4 min · 731 words · Micha Kops

Git Snippets

Show commits from another branch not contained in current branch git cherry -v otherbranch + f7d6a569bb6912aac97fce9ac92c4302863fb0d9 thecommit Cherry pick without commit git cherry-pick -n HASH Using vimdiff for diff set it via git config git config --global diff.tool vimdiff git config --global merge.tool vimdiff set it via ~/.gitconfig [diff] tool = vimdiff [merge] tool = vimdiff Using vscode as diff and mergetool You need to have the shell integration installed (code binary in PATH) ...

March 1, 2010 · 4 min · 827 words · Micha Kops

Java Snippets

Remote Debug a Pod’s Java Process Simple steps for remote debugging a Java process running on a k8 pod: Edit deployment and add the following parameters to the Java start line: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005 Also add the following port mapping at the section container → ports in the deployment: - containerPort: 5005 protocol: TCP Safe, wait for the new pods and then add a port forward for port 5005 for this pod: kubectl port-forward podname 5005 ...

March 1, 2010 · 13 min · 2583 words · Micha Kops

Spring Boot Snippets

Define and Configure Log Groups This allows to configure a group of loggers at the same time Define a log group named myaspect with two packages application.properties logging.group.myaspect=com.hascode.package1,com.hascode.package2 Configure the log group and set all loggers to level TRACE application.properties logging.level.myaspect=TRACE This is also possible as parameter on startup java -Dlogging.level.myaspect=TRACE myapp.jar Use JUnit 5 with Spring Boot Use newer versions of Surefire and Failsafe plugins: <properties> [..] <maven-failsafe-plugin.version>2.22.0</maven-failsafe-plugin.version> <maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version> </properties> ...

March 1, 2010 · 6 min · 1082 words · Micha Kops