250x250
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- JDBC
- maven
- Spring Boot
- error
- oracle
- Core Java
- spring
- MSSQL
- jpa
- Python
- Exception
- AJAX
- 설정
- Source
- Eclipse
- myBatis
- JavaScript
- ubuntu
- SpringBoot
- Docker
- MySQL
- Thymeleaf
- git
- STS
- PostgreSQL
- Open Source
- Tomcat
- 오픈소스
- 문서
- IntelliJ
Archives
- Today
- Total
헤르메스 LIFE
[Log] Log4Jdbc 설정 본문
728x90
개발환경
Spring boot 기반
build.gradle
implementation 'org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1:1.16' /* Log4JDBC */
log4jdbc.log4j2.properties
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.dump.sql.maxlinelength=0
application.properties
# Postgresql Driver 설정
#spring.datasource.hikari.driver-class-name=org.postgresql.Driver
#spring.datasource.hikari.jdbc-url=jdbc:postgresql://[URL]:5432/[DB명]
# Oracle Driver 설정
#spring.datasource.hikari.driver-class-name=oracle.jdbc.pool.OracleDataSource
#spring.datasource.hikari.jdbc-url=jdbc:oracle:thin:@localhost:1521:XE
# Oracle Log4jdbc-log4j2 설정
# spring.datasource.hikari.driver-class-name=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
#spring.datasource.hikari.jdbc-url=jdbc:log4jdbc:oracle:thin:@localhost:1521:XE
# MySql Driver 설정
# spring.datasource.hikari.driver-class-name=com.mysql.jdbc.Drive
#spring.datasource.hikari.jdbc-url=jdbc:mysql://localhost:3306/[DB명]?serverTimezone=Asia/Seoul
# MySql Log4jdbc-log4j2 설정
# spring.datasource.hikari.driver-class-name=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
# # spring.datasource.hikari.connection-test-query=SELECT NOW() FROM dual
spring.datasource.hikari.driver-class-name=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
spring.datasource.hikari.jdbc-url=jdbc:log4jdbc:postgresql://localhost:5432/springboot?charSet=UTF-8&prepareThreshold=1
spring.datasource.hikari.username=hermeswing
spring.datasource.hikari.password=pass
# CP Setting
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.maximum-pool-size=50
spring.datasource.hikari.minimum-idle=30
spring.datasource.hikari.idle-timeout=60000
context-datasource.xml
<!-- Oracle -->
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<!--
<property name="driverClassName" value="oracle.jdbc.pool.OracleDataSource"></property>
<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:XE"></property>
-->
<property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
<property name="jdbcUrl" value="jdbc:log4jdbc:oracle:thin:@localhost:1521:XE"></property>
<!-- Oracle 11 경우>
<!-- Oracle 19 경우 "jdbc:log4jdbc:oracle:thin:@localhost:1521:orcl" -->
<property name="username" value="spring"></property>
<property name="password" value="1234"></property>
</bean>
<!-- MySQL경우 -->
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<!--
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/SpringDB?serverTimezone=Asia/Seoul"></property>
-->
<property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
<property name="jdbcUrl" value="jdbc:log4jdbc:mysql://localhost:3306/SpringDB?serverTimezone=Asia/Seoul"></property>
<property name="username" value="spring"></property>
<property name="password" value="1234"></property>
</bean>
<!-- MS SQL경우 -->
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<!--
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
<property name="jdbcUrl" value="jdbc:sqlserver://localhost:1433;DatabaseName=SpringDB"></property>
-->
<property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
<property name="jdbcUrl" value="jdbc:log4jdbc:sqlserver://localhost:1433;DatabaseName=SpringDB"></property>
<property name="username" value="spring"></property>
<property name="password" value="1234"></property>
</bean>
<!-- PostgreSQL 경우 -->
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<!--
<property name="driverClassName" value="org.postgresql.Driver"></property>
<property name="jdbcUrl" value="jdbc:postgresql:localhost:5432/SpringDB?charSet=UTF-8&prepareThreshold=1"></property>
-->
<property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
<property name="jdbcUrl" value="jdbc:log4jdbc:postgresql://localhost:5432/SpringDB?charSet=UTF-8&prepareThreshold=1"></property>
<property name="username" value="spring"></property>
<property name="password" value="1234"></property>
</bean>
<!-- Tibero 경우 -->
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<!--
<property name="driverClassName" value="com.tmax.tibero.jdbc.TbDriver"></property>
<property name="jdbcUrl" value="jdbc:tibero:thin:@localhost:1521:SpringDB"></property>
-->
<property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
<property name="jdbcUrl" value="jdbc:log4jdbc:tibero:thin:@localhost:1521:SpringDB"></property>
<property name="username" value="spring"></property>
<property name="password" value="1234"></property>
</bean>
application.yml
##############################################################
# Server port
server:
servlet:
context-path: /
encoding:
enabled: true
charset: UTF-8
force: true
session:
timeout: 18000 # 30분, Default 기본단위 : 초
tomcat:
uri-encoding: UTF-8 # Spring Default : UTF-8
##############################################################
# -Dspring.profiles.active=local
spring:
profiles:
include: local, dev, datasource
##############################################################
# Spring Message 처리
messages:
basename: messages/messages, messages/exception # 각각 ResourceBundle 규칙을 따르는 쉼표로 구분된 기본 이름 목록
always-use-message-format: false # 인수가 없는 메시지도 구문 분석하여 항상 MessageFormat 규칙을 적용할지 여부
encoding: UTF-8
fallback-to-system-locale: true # locale에 해당하는 file이 없을 경우 system locale을 사용 ( default : true )
use-code-as-default-message: true # 해당 코드를 찾을 수 없을 경우 Code 를 출력한다. ( default : false )
cache-duration: 3 # default는 forever
#cache-seconds: -1 # 로드된 자원 번들 파일 캐시 만료(초). -1로 설정하면 번들은 영원히 캐시됩니다.
application-local.yml
# Server port
server:
port: 9090
##############################################################
# Spring Message 처리
spring:
config.activate.on-profile: local
devtools:
livereload:
enabled: true
# p6spy 를 위한 설정
decorator.datasource.p6spy.enable-logging: true # false : Disable p6spy
#decorator.datasource.enable: true
application-datasource.yml
##############################################################
# Spring Database 처리
spring:
datasource:
# AWS -> Postgresql
#url: jdbc:postgresql://octopus-database-1.ca56feoc8rlf.ap-northeast-2.rds.amazonaws.com:5432/postgres
#driver-class-name: org.postgresql.Driver
#username: octopusAdmin
#password: octopusDev01
#driver-class-name: org.postgresql.Driver
#url: jdbc:postgresql://localhost:5432/springboot
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
url: jdbc:p6spy:postgresql://localhost:5432/springboot
username: hermeswing
password: pass
#sql-script-encoding: utf-8 # springboot 1.5.x - Deprecated!
##############################################################
# - 경로 : /src/main/resources 경로 하위
# - schema.sql : 테이블 생성 스크립트
# - data.sql : 데이터 입력 스크립트
# - 파일이름규칙 : schema-${platform}.sql , data-${platform}.sql
# ex. schema-h2.sql , shcema-postgres.sql
#spring.datasource.initialization-mode=always # Spring Boot <v2.5.x
# DB초기화(schema.sql, data.sql) , [always : 기동 시 매번 동작, never : 기동 시 동작하지 않음]
#schema: classpath*:initdata/${platform}/schema.sql
#data: classpath*:initdata/${platform}/data.sql
#schema: classpath*:initdata/h2db/schema.sql
#data: classpath*:initdata/h2db/data.sql
#initialization-mode: always
sql:
init:
#schema-locations: classpath*:initdata/${platform}/schema.sql
#data: classpath*:initdata/${platform}/data.sql
schema-locations: classpath*:initdata/schema-postgresql.sql
data-locations: classpath*:initdata/data-postgresql.sql
mode: always # Spring Boot >=v2.5.0
spy.properties
appender = com.p6spy.engine.spy.appender.Slf4JLogger
#driverlist = org.h2.Driver, org.postgresql.Driver
driverlist = org.postgresql.Driver
logMessageFormat = com.p6spy.engine.spy.appender.MultiLineFormat
spy.properties 참조
https://p6spy.readthedocs.io/en/latest/configandusage.html
https://hermeslog.tistory.com/551
728x90
'Spring Framework' 카테고리의 다른 글
[Spring & Spring Boot] 스프링 JDK 버전 호환 (2) | 2024.05.11 |
---|---|
[Spring Cloud Netflix] Eureka Service 샘플 (2) | 2024.03.27 |
[SpringBoot] Docker에 PostgreSQL 설치 / 연결하기 (2) | 2024.02.04 |
[Redis] Docker에 Redis 설치하기 + 비밀번호 (0) | 2024.01.30 |
[전자정부프레임워크] 샘플 프로젝트 생성 dev4.1 (0) | 2023.06.27 |