Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

로깅 추가 #50

Open
dongwook-chan opened this issue Aug 13, 2023 · 3 comments
Open

로깅 추가 #50

dongwook-chan opened this issue Aug 13, 2023 · 3 comments
Labels
0조 최강 0조 enhancement New feature or request

Comments

@dongwook-chan
Copy link

dongwook-chan commented Aug 13, 2023

본 라이브러리의 사용자가 활용할 수 있는 어떠한 로그도 제공되고 있지 않습니다.
다음의 예시처럼 로깅 수준 별로 기록될 로그 항목들을 정하고
사용자가 보기 쉬운 포맷으로 제공하면 좋을 것 같습니다.

ERROR

CRC 체크를 통과하지 못한 경우

WARN

과제#2 이슈 케이스에 해당하는 경우

INFO

이벤트 스트림의 시작과 끝

DEBUG

주요 이벤트에 대한 간단한 덤프

로깅 내장 라이브러리 사용해보신 분들의 많은 참여 부탁드립니다.

@dongwook-chan dongwook-chan added the enhancement New feature or request label Aug 13, 2023
@why-arong
Copy link

why-arong commented Aug 13, 2023

ERROR

event.py: BinLogEvent

Screenshot 2023-08-13 at 9 09 11 PM

binlogstream.py : BinLogStreamReader

Screenshot 2023-08-13 at 9 09 27 PM

terminal output

Screenshot 2023-08-13 at 9 09 48 PM

현재 간단하게 위와 같이 작성했습니다.
지금은 BinLogStreamReader에 설정 값을 작성했는데
config file을 만들어 여기에 작성하는 것으로 해야 할까요? 또 콘솔 말고도 저장될 .log 를 만드는 것은 어떤가요?

# config.yaml
version: 1
formatters:
  detailed:
    format: '%(levelname)s (%(asctime)s): %(message)s (Line: %(lineno)d [%(filename)s])'
    datefmt: '%d/%m/%Y %I:%M:%S %p'
handlers:
  console:
    class: logging.StreamHandler
    level: DEBUG
    formatter: detailed
  file:
    class: logging.FileHandler
    filename: app.log  # 로그 파일의 경로 및 이름
    level: DEBUG
    formatter: detailed
root:
  level: DEBUG
  handlers: [console, file]  # 여기서 file 핸들러를 추가
import logging
import logging.config
import yaml

# 로깅 설정 파일 로드
with open('logging_config.yaml', 'r') as config_file:
    config = yaml.safe_load(config_file)

# 로깅 설정 적용
logging.config.dictConfig(config)

@dongwook-chan
Copy link
Author

@why-arong
오오오오 logging에 대해서도 박학다식하시군요 ㅎㅎ
저희 프로젝트처럼 import되는 모듈이나 패키지들의 많은 경우, logging configuration을 거의 하지 않습니다.
왜냐하면 import를 하는 프로그램에 정의된 configuration을 상속받아 사용하면 되기 때문이죠.
logging의 특징이 특정 모듈에 logging configuration을 하면 자손 모듈에서 이를 상속해서 사용하게 됩니다.
만약 자손 모듈별로 configuration을 해야하고, 그 configuration 방법이 yaml을 작성하는 것이라면
프로그램에서 사용하는 모듈 및 패키지 개수만큼 configuration용 yaml 파일이 작성되어야 하고
관리하기 어려운 상황이 되겠지요?
이보다는 logging configuration을 상속을 최대한 활용하고
logging 세팅 권한과 책임을 최대한 사용자가 작성한 프로그램쪽에 위임하는 것이
사용자가 원하는 방식대로 저희 프로젝트를 사용할 수 있게 하고
그것이 프로젝트의 유용성을 극대화하는 설계가 아닌가 싶습니다.

@dongwook-chan
Copy link
Author

dongwook-chan commented Aug 13, 2023

그래서 configuration에 대한 고민보다는,
코드 어느 지점에 어떤 수준의 어떤 로깅을 남겨서 사용자에게 유용한 로그를 전달할지 고민하는 것이 더 좋아보입니다!

@dongwook-chan dongwook-chan added the 0조 최강 0조 label Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0조 최강 0조 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants