Skip to content

Instantly share code, notes, and snippets.

@ishults
ishults / example.groovy
Created September 24, 2017 18:35
Invoking the log marker
log.info(LoggingMarkers.JSON, '{"ssn": "1234567890"}') // Will mask
log.info('{"ssn": "1234567890"}') // Will NOT mask
log.info(LoggingMarkers.XML, '{"ssn": "1234567890"}') // Will try to mask, but probably won't work for this message
@ishults
ishults / log4j2.xml
Created September 24, 2017 18:07
Log4J 2 configuration
<Configuration packages='com.path.to.logging, com.your.other.packages'>
<Properties>
<Property name="maskingPattern">
%d, level=%p, %cm
</Property>
</Properties>
...
</Configuration>
@ishults
ishults / LoggingMarkers.groovy
Last active January 11, 2021 18:47
The logging markers for Log4j
class LoggingMarkers {
static final Marker JSON = MarkerFactory.getMarker('JSON-MASK')
static final Marker XML = MarkerFactory.getMarker('XML-MASK')
}
@ishults
ishults / LogMaskingConverterSpec.groovy
Last active September 26, 2017 17:07
Tests for the main class
class LogMaskingConverterSpec extends Specification {
@Shared
LogMaskingConverter converter
void setup() {
converter = new LogMaskingConverter()
}
@Unroll
@ishults
ishults / LogMaskingConverter.groovy
Last active February 2, 2023 15:41
The class that will handle filtering the log statements
@Plugin(name = 'logmask', category = 'Converter')
@ConverterKeys(['cm'])
class LogMaskingConverter extends LogEventPatternConverter {
private static final String NAME = 'cm'
private static final String JSON_REPLACEMENT_REGEX = "\"\$1\": \"****\""
private static final String JSON_KEYS = ['ssn', 'private', 'creditCard'].join('|')
private static final Pattern JSON_PATTERN = Pattern.compile(/"(${JSON_KEYS})": "([^"]+)"/)
LogMaskingConverter(String[] options) {
super(NAME, NAME)
@ishults
ishults / pom.xml
Last active September 24, 2017 17:06
Dependencies
<properties>
<log4j.version>2.7</log4j.version>
<slf4j.version>1.7.22</slf4j.version>
</properties>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
@ishults
ishults / garage_door.yaml
Last active August 29, 2016 19:03
Garage door signal script
script:
signal_garage_door:
sequence:
# turn_on closes the circuit, so always send it to "toggle"
- service: switch.turn_on
data:
entity_id: switch.fortrezz_unknown_type0453_id0111_switch_1
server {
listen 80;
server_name example.com; # Your site
rewrite ^ https://$host$request_uri permanent;
}
server {
listen 443 default_server ssl;
server_name example.com; # Your site
@ishults
ishults / cron
Last active July 12, 2016 19:54
crontab -e
# Add this. x is the minute of renewal, while y and z are the hours.
# You can (should) move the command into a script and run that.
x y,z * * * sudo service nginx stop && letsencrypt renew --quiet && sudo service nginx start
letsencrypt certonly