Skip to content

Instantly share code, notes, and snippets.

View wkrzywiec's full-sized avatar
👦
Software Engineer

Wojtek Krzywiec wkrzywiec

👦
Software Engineer
View GitHub Profile
@wkrzywiec
wkrzywiec / web.xml
Last active March 16, 2018 14:50
Medium - web app config - web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
@wkrzywiec
wkrzywiec / index.html
Last active March 16, 2018 14:51
Medium - web app config - index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Home page</title>
</head>
<body>
Home page
@wkrzywiec
wkrzywiec / build.gradle
Created March 16, 2018 15:10
Medium - web app config - build.gradle Tomcat plugin
apply plugin: 'com.bmuschko.tomcat'
apply plugin: 'eclipse-wtp'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.4.1'
@wkrzywiec
wkrzywiec / build.gradle
Created March 16, 2018 15:12
Medium - web app config - build.gradle web project
apply plugin: 'java-library'
apply plugin: 'war'
repositories {
jcenter()
}
dependencies {
@wkrzywiec
wkrzywiec / userService.java
Last active March 20, 2018 20:33
Medium - 3 log4j2 - logger sample
//this part will could be in constructor of the class
Logger userLogger = LogManager.getLogger("userLoggerDB");
...
public void saveReaderUser(UserDTO user) {
//code for saving user into database
userLogger.info(“New user created: “ + user.getUsername())
}
@wkrzywiec
wkrzywiec / userService.java
Created March 21, 2018 18:23
Medium 3 - log4j2 - ThreadContext
//somewhere in the method
ThreadContext.put("username", "donkey_kong");
userLogger.info("New user");
ThreadContext.clearAll();
CREATE TABLE `user_logs` (
`id` int(12) NOT NULL AUTO_INCREMENT,
`level` varchar(10) NOT NULL,
`dated` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`username` varchar(64) NOT NULL,
`field` varchar(60) NOT NULL,
`from_value` varchar(1000) NOT NULL DEFAULT '',
`to_value` varchar(1000) NOT NULL DEFAULT '',
`message` varchar(500) NOT NULL,
@wkrzywiec
wkrzywiec / build.gradle
Created March 21, 2018 18:58
Medium 3 - log4j2 - build.gradle
dependencies {
//some other dependencies
compile 'org.apache.logging.log4j:log4j-api:2.10.0'
compile 'org.apache.logging.log4j:log4j-core:2.10.0'
}
@wkrzywiec
wkrzywiec / LogsConnectionFactory.java
Created March 21, 2018 19:04
Medium 3 - log4j2 - LogsConnectionFactory
package com.wkrzywiec.spring.library.config;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.commons.dbcp.DriverManagerConnectionFactory;
import org.apache.commons.dbcp.PoolableConnection;
@wkrzywiec
wkrzywiec / log4j2.xml
Created March 21, 2018 19:10
Medium 3 - log4j2 - log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration name="ChangesLogs">
<Appenders>
<Console name="consoleAppender" target="SYSTEM_OUT">
<PatternLayout pattern="%d | %level | %logger | %m" />
</Console>
<JDBC name="userAppenderDB" tableName="user_logs">
<ConnectionFactory class="com.wkrzywiec.spring.library.config.LogsConnectionFactory" method="getDatabaseConnection" />