Logback Luhn Mask

Logback converter for masking credit card numbers in your logs

License

License

Categories

Categories

Logback Application Layer Libs Logging
GroupId

GroupId

ph.samson.logback
ArtifactId

ArtifactId

logback-luhn-mask
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Logback Luhn Mask
Logback converter for masking credit card numbers in your logs
Project URL

Project URL

https://github.com/esamson/logback-luhn-mask
Project Organization

Project Organization

samson.ph
Source Code Management

Source Code Management

https://github.com/esamson/logback-luhn-mask

Download logback-luhn-mask

How to add to project

<!-- https://jarcasting.com/artifacts/ph.samson.logback/logback-luhn-mask/ -->
<dependency>
    <groupId>ph.samson.logback</groupId>
    <artifactId>logback-luhn-mask</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/ph.samson.logback/logback-luhn-mask/
implementation 'ph.samson.logback:logback-luhn-mask:1.0.1'
// https://jarcasting.com/artifacts/ph.samson.logback/logback-luhn-mask/
implementation ("ph.samson.logback:logback-luhn-mask:1.0.1")
'ph.samson.logback:logback-luhn-mask:jar:1.0.1'
<dependency org="ph.samson.logback" name="logback-luhn-mask" rev="1.0.1">
  <artifact name="logback-luhn-mask" type="jar" />
</dependency>
@Grapes(
@Grab(group='ph.samson.logback', module='logback-luhn-mask', version='1.0.1')
)
libraryDependencies += "ph.samson.logback" % "logback-luhn-mask" % "1.0.1"
[ph.samson.logback/logback-luhn-mask "1.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
ch.qos.logback : logback-classic jar 1.0.10

test (3)

Group / Artifact Type Version
junit : junit jar 4.11
org.mockito : mockito-core jar 1.9.5
com.google.caliper : caliper jar 1.0-beta-1

Project Modules

There are no modules declared in this project.

Logback Luhn Mask

Build Status

This is a Logback Converter that masks any possible credit card numbers in your log messages.

What is it for?

If you use Logback, this is an easy way to ensure that no credit card numbers are exposed through your application logs.

How do I use it?

First, add the logback-luhn-mask JAR to you runtime classpath. The latest release is always available from Maven Central. If you are using Maven, just add it to your runtime dependencies:

<dependency>
    <groupId>ph.samson.logback</groupId>
    <artifactId>logback-luhn-mask</artifactId>
    <version>1.0</version>
    <scope>runtime</scope>
</dependency>

Next, in your Logback configuration, define a new conversionRule to use the LuhnMaskingConverter. In you appender's pattern configuration, use this new conversionRule where you would usually use %msg. For example, if your existing Logback configuration went like.:

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date [%thread] - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

You would modify it to:

<configuration>
    <conversionRule conversionWord="maskedMsg" 
            converterClass="ph.samson.logback.luhn.LuhnMaskingConverter" />

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date [%thread] - %maskedMsg%n</pattern>
        </encoder>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

How does it work?

The LuhnMaskingConverter takes the formatted message of the event being logged and scans for consecutive numeric characters that are long enough to form a credit card number. The space ( ) and dash (-) characters are considered as separators. When such a substring is found, the Luhn algorithm is used to check if it forms a possible credit card number. When a possible credit card number is found, all its digits except for the last four are replaced with the word MASKED centered in asterisk (*) characters. So 5137 0049 8639 6403 becomes ****MASKED*****6403.

How can I help?

Any and all contributions are appreciated.

This project uses maven Maven and can be built the usual Maven way.

Caliper is used for microbenchmarks. You can run

mvn -Pbenchmark

to execute them. Here's a sample run from my box.

Versions

Version
1.0.1
1.0