tinylog: marco de registro ligero y simplificado para Java. Tutorial de HelloWorld y detalles del nivel de registro
Publicado: 2021-11-09
¿Qué es tinylog?
Tinylog es un marco de registro ligero y simplificado para tantos lenguajes JVM. Tiene registrador estático. No es necesario crear ninguna otra instancia de registrador por clase.
Como cualquier otro marco de registro estándar (log4j), también admite 5 niveles de registro diferentes.
- RASTRO
- DEPURAR
- INFORMACIÓN – Predeterminado
- ADVERTENCIA
- ERROR
Tenga su nivel de registro para trace
para habilitar todos los registros.
Lo que todos los marcos soportan tinylog:
- Java
- kotlin
- Scala
- otro lenguaje JVM
¿Cuáles son las principales ventajas del marco de registro de tinylog?
- Es liviano (~170kb lib)
- Es mas rapido
- Es muy simple de implementar.
- Sigue patrones log4j estándar
- es de código abierto
Comencemos con la codificación y la muestra Ejemplo de HelloWorld
Paso 1
- Agregue dependencias de tinylog maven al archivo pom.xml de su proyecto.

Abra el archivo pom.xml de su proyecto de producción y agregue las dos dependencias a continuación.
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 > |
Reconstruya el proyecto.
Paso 2
- Agregue tinylog.properties en la carpeta /resources.
- Archivo: 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 |
Aquí tenemos dos adaptadores tinylog.
- adaptador de
console
tinylog- Esto imprime el registro en la consola Eclipse / IntelliJ IDEA
- adaptador de
file
tinylog- Esto imprime el registro en el archivo crunchifyLog.txt

Paso 3
- Crear clase 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" ) ; } } |
Copie el código anterior y guarde el archivo.
Etapa 4
Ejecute el programa anterior como aplicación Java y verá el resultado a continuación.
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 |
¿Cuáles son todos los formatos de registro que puede usar con tinylog?

Nombre | Descripción |
---|---|
CLASE | Nombre de clase completamente calificado donde se emite la solicitud de registro |
NOMBRE DE LA CLASE | Nombre de clase (sin paquete) donde se emite la solicitud de registro |
CONTEXTO | Todos los valores establecidos del contexto de registro (nuevo en tinylog 1.1) |
FECHA | Fecha y hora de la solicitud de registro |
EXCEPCIÓN | Excepción lanzada ( null , si no se ha lanzado ninguna) |
EXPEDIENTE | Nombre de archivo del archivo fuente de Java desde donde se emite la solicitud de registro |
NIVEL | Nivel de registro de la entrada de registro creada |
LÍNEA | Número de línea desde donde se emite la solicitud de registro |
MENSAJE | Mensaje asociado de la entrada de registro creada |
MÉTODO | Nombre del método desde donde se emite la solicitud de registro |
PAQUETE | Paquete donde se emite la solicitud de registro |
IDENTIFICACION DE PROCESO | ID de proceso de la aplicación |
RENDERED_LOG_ENTRY | Entrada de registro renderizada final como se usaría para salidas basadas en texto |
HILO_ID | ID del hilo actual |
SUBPROCESO_NOMBRE | Nombre del hilo actual |
¿Cuántos escritores podría usar con tinylog?
Escritor | Nombre | Descripción |
---|---|---|
Escritor de consola | consola | Escribe entradas de registro en la consola |
FileWriter | expediente | Escribe entradas de registro en un archivo definido |
JdbcEscritor | jdbc | Almacena entradas de registro en una base de datos SQL |
Escritor Logcat | gato de registro | Reenvía las entradas de registro al sistema de registro nativo de Android |
RollingArchivoEscritor | archivo rodante | Me gusta FileWriter pero usa varios archivos girándolos |
SharedFileWriter | archivo compartido | Admite la escritura de múltiples instancias de un programa en el mismo archivo |
nulo | nulo | Descarta todas las entradas de registro |
Iniciar sesión sin el archivo tinylog.properties
Como referencia, aquí hay un registro si no tiene ningún marco de registro habilitado para su aplicación.

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 |
Y ya está todo listo. Avíseme si tiene algún problema al ejecutar este tutorial de tinylog.