JSP - 25. log4j, slf4j, mybatis 이용한 상품조회

갓김치·2020년 12월 22일
1

JSP+Spring

목록 보기
26/43

Logging Framework

log4j1Apache Log4j 2
설정파일: properties설정파일: xml

facade로 로깅 사용시 필요한것

  • 로깅을 찍는 framework = 빔프로젝트
    • log4j-api, log4j-core
  • 로깅 명령을 내리는 framework = 리모콘
    • commons-logging (무거워서 잘 안쓰임)
    • SLF4J - Simple Logging Facade for Java
      • The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks (e.g. java.util.logging, logback, log4j) allowing the end user to plug in the desired logging framework at deployment time.
        • org/slf4j : group id
        • jcl-over-slf4j: artifact id
        • 1.7.9: 버전

log4j - slf4j 바인딩

  • log4j - slf4j 바인딩
  • 바인딩과 어댑터를 함께쓸수는없음
    • Use of the Log4j 2 SLF4J Binding (log4j-slf4j-impl-2.0.jar) together with the SLF4J adapter (log4j-to-slf4j-2.0.jar) should never be attempted, as it will cause events to endlessly be routed between SLF4J and Log4j 2.

commons-logging 없애기

log4j-slf4j-impl

  • commons-logging을 지우려고했더니 이미 쓰고있던 애들이 있군
  • 일단 exclude해버렷
  • jcl-over-slf4j로 덮어써줘야 beanutils나 dbcp에서 ClassNotFoundException이 뜨지않음

Configuration

http://logging.apache.org/log4j/2.x/manual/configuration.html

로깅을 해봅시다

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
  </Appenders>
  <Loggers>
    <Logger name="com.foo.Bar" level="trace">
      <AppenderRef ref="Console"/>
    </Logger>
    <Root level="debug">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>

Appender: where

http://logging.apache.org/log4j/2.x/manual/appenders.html

  • FileAppender
  • ConsoleAppender
  • JDBCAppender

Message: what

Layout: how

http://logging.apache.org/log4j/2.x/manual/layouts.html

  • %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
  • 10:07:44.941 [http-nio-80-exec-2] DEBUG org.apache.commons.digester.Digester.sax - ignorableWhitespace

Logger: who

  • 전달자: 로거가 로깅메시지를 로깅프레임웤에게 전달
  • 클래스의 qualified name을 사용
  • 패턴 적용가능
    • logger.debug(String foramt, Object... args)
    • logger.debug("currentPage : {}, searchType: {}, searchWord : {}", pageParam, searchType, searchWord);

개별 로거 적용가능

  <Loggers>
    <!-- 별도의 로거를 등록하여 따로 이벤트 등급을 설정 -->
    <Logger name="kr.or.ddit.member.controller" level="debug">
      <AppenderRef ref="Console"/>
    </Logger>
    <Root level="info">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
  • qualifiend name을 쓰기때문에 계층구조도 적용 가능

appender 중복 충돌 방지 => additivity="false"

  <Loggers>
    <Logger name="com.foo.Bar" level="trace" additivity="false">
      <AppenderRef ref="Console"/>
    </Logger>
    <Root level="error">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>

log4jdbc - JDBC proxy driver for logging SQL

1. Change your JDBC URL

  • Prepend jdbc:log4 to the normal JDBC URL that you are using.
  • 예)기존: jdbc:derby://localhost:1527//db-derby-10.2.2.0-bin/databases/MyDatabase
  • 예)변경: jdbc:log4jdbc:derby://localhost:1527//db-derby-10.2.2.0-bin/databases/MyDatabase

2. Change the driver used 잘안되서 다른 걸로 교체

Set your JDBC driver class to net.sf.log4jdbc.sql.jdbcapi.DriverSpy in your application (please note that this is not the same class name as in the standard log4jdbc implementation). See the log4jdbc documentation to see the list of supported drivers, or how to add support for other drivers. log4jdbc supports almost all major drivers. (DriverSpy의 q.n copy)

  • 잘안되서 딴걸로 교체
  • 변경전
driverClassName=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:xe
  • 변경후 (lazyluke의 driverspy)
driverClassName=net.sf.log4jdbc.DriverSpy
url=jdbc:log4jdbc:oracle:thin:@localhost:1521:xe

logger description

loggerdesc
jdbc.sqlonlyLogs only SQL. SQL executed within a prepared statement is automatically shown with it's bind arguments replaced with the data bound at that position, for greatly increased readability.
jdbc.sqltimingLogs the SQL, post-execution, including timing statistics on how long the SQL took to execute.
jdbc.auditLogs ALL JDBC calls except for ResultSets. This is a very voluminous output, and is not normally needed unless tracking down a specific JDBC problem.
jdbc.resultsetEven more voluminous, because all calls to ResultSet objects are logged.
jdbc.resultsettableLog the jdbc results as a table. Level debug will fill in unread values in the result set.
jdbc.connectionLogs connection open and close events as well as dumping all open connection numbers. This is very useful for hunting down connection leak problems.



상품관리

Mybatis

trim

<trim prefix=" WHERE" prefixOverrides="AND">

  • prefix vs. prefixOverride 차이점?

VO 대신 Map<String, Object>

  • map사용시 주의사항: column alias 줄때 "lprod_id" 쿼테이션!

JSP

EL

  • 널포인트 발생할라하면 알아서 화이트스페이스로 바꿔줌
  • 기호 줄여서 가독성 높임
  • getter 호출이 쉽다리

ajaxForm - jQuery plugin

http://malsup.com/jquery/form/#options-object

  • options에 유용한게많군

과제

  • 회원관리 비동기로
  • select태그 만드는 라이브러리화
  • 시퀀스다이어그램. 클래스다이어그램 해석
profile
갈 길이 멀다

1개의 댓글

comment-user-thumbnail
2021년 1월 8일

안녕하세요! 좋은 글 올려주셔서 감사합니다. VO 대신 Map<String, Object> 이부분은 왜이렇게 쓰셨는지 여쭤봐도 될까요?

답글 달기