일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- pytorch
- CUDA
- list
- TORCH
- Container
- Laravel
- Flask
- Paper
- GitLab
- Python
- enV
- git
- Converting
- format
- numpy
- Database
- Mac
- DB
- AI
- file
- evaluation
- Package
- Windows
- pandas
- LLM
- Linux
- KAKAO
- judge
- PostgreSQL
- docker
Archives
- Today
- Total
Daily Develope
[Python] 로그, 로깅 (logging) 본문
기본 선언 및 환경설정
ㅇ 선언
import logging
logging.basicConfig(filename=f'{os.getcwd()}/result_test.log', level=logging.INFO, format='%(asctime)s %(message)s')
# 사용 예)
import os
import logging
from datetime import datetime
logging.basicConfig(filename=f'{os.getcwd()}/logs/my_log_{datetime.now().strftime("%Y%m%d_%H%M%S")}.log',
level=logging.INFO,
format='%(asctime)s %(message)s')
ㅇ 사용 예1) logger 환경설정 및 info level에서의 등록
# main.py ---
import os
import logging
from datetime import datetime
import testLogging as tl
logging.basicConfig(filename=f'{os.getcwd()}/logs/my_log_{datetime.now().strftime("%Y%m%d_%H%M%S")}.log',
level=logging.INFO,
format='%(asctime)s %(message)s')
tl.testLogging()
# testLogging.py ---
import logging
def testLogging():
logging.info('this is a my log')
ㅇ 사용 예2) 신규 level 등록
# create new level with numeric value 15
logging.addLevelName(15, "DATA")
...
# write log with 'DATA' level (using numeric value)
logging.log(15, "hello")
ㅇ 참조
https://docs.python.org/3/library/logging.html
'Develope > Python' 카테고리의 다른 글
[Python] config 환경설정 관리 및 사용 (0) | 2022.03.31 |
---|---|
[Python] PCM 음성파일 파형 출력 (with pyplot) (0) | 2022.02.15 |
[Python] PCM 파일 통합 및 WAV로 변환 (0) | 2022.02.15 |
[Python] 매칭 (문자열 / 리스트 / 정규식) (0) | 2022.01.15 |
[Python] Pattern - Singleton (싱글톤) (0) | 2022.01.08 |
Comments