Tuesday, October 13, 2015

Ruby On Rails에서 로그 출력 하는 방법

콘솔용 Ruby에서는 print와 puts를 사용하면 화면에 문자열을 찍을 수 있는데 Ruby On Rails는 웹 프레임워크라서 print/puts를 사용하면 문자열이 HTML로 출력이 된다.

그래서 다음과 같이 출력하면 로그 파일에 안전하게 로그가 출력이 된다.

Rails.logger.debug "(문자열)"

문자열은 log/development.log, production.log에 출력이 된다.

debug대신에 info, warn등을 사용할수 있는데 이것은 다음과 같은 환경설정을 따른다.
config/environments/development.rb, production.rb에서 다음과 같이 지정한다.

config.log_level = :debug

No comments:

Post a Comment