tinylog – Java용 경량의 단순화된 로깅 프레임워크. HelloWorld 자습서 및 로깅 수준 세부 정보
게시 됨: 2021-11-09
작은 로그 란 무엇입니까?
Tinylog는 많은 JVM 언어를 위한 경량의 단순화된 로깅 프레임워크입니다. 정적 로거가 있습니다. 클래스별로 다른 로거 인스턴스를 생성할 필요가 없습니다.
다른 표준 로깅 프레임워크(log4j)와 마찬가지로 5가지 다른 로깅 수준도 지원합니다.
- 추적하다
- 디버그
- 정보 – 기본값
- 경고
- 오류
모든 로깅을 활성화하려면 trace
할 로깅 수준이 있어야 합니다.
모든 프레임워크 tinylog가 지원하는 것:
- 자바
- 코틀린
- 스칼라
- 다른 JVM 언어
tinylog 로깅 프레임워크의 주요 이점은 무엇입니까?
- 가벼움(~170kb lib)
- 더 빨라
- 구현하는 것은 매우 간단합니다.
- 표준 log4j 패턴을 따릅니다.
- 오픈소스다
코딩 및 샘플 HelloWorld 예제를 시작해 보겠습니다.
1 단계
- 프로젝트의 pom.xml 파일에 tinylog maven 종속성을 추가합니다.

프로덕션 프로젝트의 pom.xml 파일을 열고 아래 두 가지 종속성을 추가합니다.
1 2 3 4 5 6 7 8 9 10 |
< dependency > < groupId > org . tinylog < / groupId > < artifactId > tinylog - api < / artifactId > < version > 2.3.2 < / version > < / dependency > < dependency > < groupId > org . tinylog < / groupId > < artifactId > tinylog - impl < / artifactId > < version > 2.3.2 < / version > < / dependency > |
프로젝트를 다시 빌드하십시오.
2 단계
- /resources 폴더 아래에 tinylog.properties를 추가합니다.
- 파일: tinylog.properties

1 2 3 4 5 6 7 8 9 10 |
# logs to Console writerCrunchifyConsole = console writerCrunchifyConsole . format = { date : HH : mm : ss . SSS } { level } : { message } writerCrunchifyConsole . level = trace # logs to File writerCrunchifyFile = file writerCrunchifyFile . file = crunchifyLog . txt writerCrunchifyFile . level = trace |
여기에 두 개의 tinylog 어댑터가 있습니다.
- tinylog
console
어댑터- Eclipse / IntelliJ IDEA 콘솔에 로그를 인쇄합니다.
- tinylog
file
어댑터- 이것은 crunchifyLog.txt 파일의 로그를 인쇄합니다.

3단계
- CrunchifyTinyLogFirstTutorial.java 클래스 생성
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 32 33 34 35 36 37 38 39 40 |
package crunchify . com . java . tutorials ; import org . tinylog . Logger ; /** * @author Crunchify.com * Program: tinylog Hello World Tutorial with log levels and properties * */ public class CrunchifyTinyLogFirstTutorial { public static void main ( String [ ] args ) { // Logs a message at INFO level. Logger . info ( "Howdy Cruncher! This is App Shah and welcome to Tinylog Tutorial! - INFO Log Level" ) ; // Logs a message at TRACE level. Logger . trace ( "Howdy Cruncher! This is App Shah and welcome to Tinylog Tutorial! - TRACE Log Level!" ) ; // Logs a message at DEBUG level. Logger . debug ( "Howdy Cruncher! This is App Shah and welcome to Tinylog Tutorial! - DEBUG Log Level!" ) ; // Logs a message at WARN level. Logger . warn ( "Howdy Cruncher! This is App Shah and welcome to Tinylog Tutorial! - WARN Log Level!" ) ; // Logs a message at ERROR level. Logger . error ( "Howdy Cruncher! This is App Shah and welcome to Tinylog Tutorial! - ERROR Log Level!" ) ; String crunchifyString = "Cruncher" ; Logger . info ( "Howdy {}! This is Tinylog tutorial by {}." , crunchifyString , "Crunchify.com" ) ; Logger . error ( "Oh.. This is not {} but it's {}" , "Meta.com" , "Crunchify.com" ) ; } } |
위의 코드를 복사하고 파일을 저장합니다.
4단계
위의 프로그램을 Java Application으로 실행하면 아래와 같은 결과를 볼 수 있습니다.
1 2 3 4 5 6 7 8 9 10 11 |
/ Users / app / Library / Java / JavaVirtualMachines / openjdk - 17.0.1 / Contents / Home / bin / java - javaagent : / Applications / IntelliJ IDEA . app / Contents / lib / idea_rt . jar = 60075 : / Applications / crunchify . com . java . tutorials . CrunchifyTinyLogFirstTutorial 13 : 21 : 52.998 INFO : Howdy Cruncher ! This is App Shah and welcome to Tinylog Tutorial ! - INFO Log Level 13 : 21 : 53.001 TRACE : Howdy Cruncher ! This is App Shah and welcome to Tinylog Tutorial ! - TRACE Log Level ! 13 : 21 : 53.002 DEBUG : Howdy Cruncher ! This is App Shah and welcome to Tinylog Tutorial ! - DEBUG Log Level ! 13 : 21 : 53.002 INFO : Howdy Cruncher ! This is Tinylog tutorial by Crunchify . com . 13 : 21 : 53.002 WARN : Howdy Cruncher ! This is App Shah and welcome to Tinylog Tutorial ! - WARN Log Level ! 13 : 21 : 53.002 ERROR : Howdy Cruncher ! This is App Shah and welcome to Tinylog Tutorial ! - ERROR Log Level ! 13 : 21 : 53.002 ERROR : Oh . . This is not Meta . com but it ' s Crunchify . com Process finished with exit code 0 |
tinylog와 함께 사용할 수 있는 로깅 형식은 모두 무엇입니까?

이름 | 설명 |
---|---|
수업 | 로깅 요청이 발행된 정규화된 클래스 이름 |
CLASS_NAME | 로깅 요청이 발행된 클래스 이름(패키지 제외) |
문맥 | 로깅 컨텍스트의 모든 설정 값(tinylog 1.1의 새로운 기능) |
데이트 | 로깅 요청 날짜 및 시간 |
예외 | throw된 예외( 아무 것도 throw되지 않은 경우 null ) |
파일 | 로깅 요청이 발행된 Java 소스 파일의 파일 이름 |
수준 | 생성된 로그 항목의 로깅 수준 |
선 | 로깅 요청이 발행된 라인 번호 |
메세지 | 생성된 로그 항목의 관련 메시지 |
방법 | 로깅 요청이 발행된 메소드 이름 |
패키지 | 로깅 요청이 발행된 패키지 |
PROCESS_ID | 애플리케이션의 프로세스 ID |
RENDERED_LOG_ENTRY | 텍스트 기반 출력에 사용되는 최종 렌더링된 로그 항목 |
THREAD_ID | 현재 스레드의 ID |
THREAD_NAME | 현재 스레드의 이름 |
당신은 tinylog와 함께 얼마나 많은 작가를 사용할 수 있습니까?
작가 | 이름 | 설명 |
---|---|---|
콘솔작가 | 콘솔 | 콘솔에 로그 항목을 씁니다. |
파일라이터 | 파일 | 정의된 파일에 로그 항목을 씁니다. |
JdbcWriter | jdbc | SQL 데이터베이스에 로그 항목 저장 |
로그캣라이터 | 로그캣 | Android의 기본 로깅 시스템으로 로그 항목을 전달합니다. |
RollingFileWriter | 롤링 파일 | FileWriter 와 비슷하지만 여러 파일을 회전하여 사용합니다. |
공유파일작성기 | 공유 파일 | 동일한 파일에 프로그램의 여러 인스턴스 쓰기 지원 |
없는 | 없는 | 모든 로그 항목을 버립니다. |
tinylog.properties 파일 없이 기록
참고로 다음은 애플리케이션에 대해 활성화된 로깅 프레임워크가 없는 경우의 로그입니다.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
< meta charset = "utf-8" / > / Users / app / Library / Java / JavaVirtualMachines / openjdk - 17.0.1 / Contents / Home / bin / java - javaagent : / Applications / IntelliJ IDEA . app / Contents / lib / idea_rt . jar = 60075 : / Applications / crunchify . com . java . tutorials . CrunchifyTinyLogFirstTutorial 2021 - 11 - 08 13 : 28 : 30 [ main ] crunchify . com . java . tutorials . CrunchifyTinyLogFirstTutorial . main ( ) INFO : Howdy Cruncher ! This is App Shah and welcome to Tinylog Tutorial ! - INFO Log Level 2021 - 11 - 08 13 : 28 : 30 [ main ] crunchify . com . java . tutorials . CrunchifyTinyLogFirstTutorial . main ( ) TRACE : Howdy Cruncher ! This is App Shah and welcome to Tinylog Tutorial ! - TRACE Log Level ! 2021 - 11 - 08 13 : 28 : 30 [ main ] crunchify . com . java . tutorials . CrunchifyTinyLogFirstTutorial . main ( ) DEBUG : Howdy Cruncher ! This is App Shah and welcome to Tinylog Tutorial ! - DEBUG Log Level ! 2021 - 11 - 08 13 : 28 : 30 [ main ] crunchify . com . java . tutorials . CrunchifyTinyLogFirstTutorial . main ( ) INFO : Howdy Cruncher ! This is Tinylog tutorial by Crunchify . com . 2021 - 11 - 08 13 : 28 : 30 [ main ] crunchify . com . java . tutorials . CrunchifyTinyLogFirstTutorial . main ( ) WARN : Howdy Cruncher ! This is App Shah and welcome to Tinylog Tutorial ! - WARN Log Level ! 2021 - 11 - 08 13 : 28 : 30 [ main ] crunchify . com . java . tutorials . CrunchifyTinyLogFirstTutorial . main ( ) ERROR : Howdy Cruncher ! This is App Shah and welcome to Tinylog Tutorial ! - ERROR Log Level ! 2021 - 11 - 08 13 : 28 : 30 [ main ] crunchify . com . java . tutorials . CrunchifyTinyLogFirstTutorial . main ( ) ERROR : Oh . . This is not Meta . com but it ' s Crunchify . com Process finished with exit code 0 |
모든 준비가 완료되었습니다. 이 tinylog 자습서를 실행하는 데 문제가 있으면 알려주십시오.