{"id":194,"date":"2022-03-30T15:32:08","date_gmt":"2022-03-30T15:32:08","guid":{"rendered":"https:\/\/vkrastev1blog.com\/?p=194"},"modified":"2022-03-31T13:31:11","modified_gmt":"2022-03-31T13:31:11","slug":"java-configure-log4j2-in-your-project","status":"publish","type":"post","link":"https:\/\/vkrastev1blog.com\/2022\/03\/30\/java-configure-log4j2-in-your-project\/","title":{"rendered":"Java configura Log4j2 en tu proyecto"},"content":{"rendered":"\n<ol class=\"wp-block-list\"><li>Dependencias de enlace de Log4j2 y SLF4j<br>Para que Log4j2 funcione con SLF4J, debemos incluir las siguientes 3 dependencias. <br>log4j-slf4j-impl.jar: enlace Log4j 2 SLF4J. Permite que las aplicaciones codificadas en la API SLF4J utilicen Log4j2 como implementaci\u00c3\u00b3n.<br>log4j-api.jar: proporciona los componentes del adaptador necesarios para que los implementadores creen una implementaci\u00c3\u00b3n de registro.<br>log4j-core.jar: clases principales de implementaci\u00c3\u00b3n de Log4j.<br>Las dependencias de Maven y Gradle se pueden copiar como se muestra a continuaci\u00c3\u00b3n.<br>pom.xml<\/li><\/ol>\n\n\n\n<p class=\"has-text-align-left wp-block-paragraph\">&lt;dependencia&gt;     <br>&lt;groupId&gt;org.apache.logging.log4j&lt;\/groupId&gt;     <br>&lt;artifactId&gt;log4j-api&lt;\/artifactId&gt;     <br>&lt;versi\u00c3\u00b3n&gt;2.15.0&lt;\/versi\u00c3\u00b3n&gt; &lt;\/dependencia&gt; <br>&lt;dependencia&gt;     <br>&lt;groupId&gt;org.apache.logging.log4j&lt;\/groupId&gt;    <br> &lt;artifactId&gt;log4j-core&lt;\/artifactId&gt;     <br>&lt;versi\u00c3\u00b3n&gt;2.15.0&lt;\/versi\u00c3\u00b3n&gt; <br>&lt;\/dependencia&gt; &lt;dependencia&gt;     <br>&lt;groupId&gt;org.apache.logging.log4j&lt;\/groupId&gt;     <br>&lt;artifactId&gt;log4j-slf4j-impl&lt;\/artifactId&gt;     <br>&lt;versi\u00c3\u00b3n&gt;2.15.0&lt;\/versi\u00c3\u00b3n&gt; <br>&lt;\/dependencia&gt;<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>Cree el archivo log4j2.xml en la carpeta de recursos de su proyecto<br>Ejemplo con transferencia de archivos y uso de variables del sistema y dise\u00c3\u00b1ado para su uso en el servidor Wildfly:<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">&lt;?xml versi\u00c3\u00b3n=&#8221;1.0&#8243; codificaci\u00c3\u00b3n=&#8221;UTF-8&#8243;?&gt; <br>&lt;Estado de configuraci\u00c3\u00b3n=&#8221;${env:LOG_LEVEL}&#8221;&gt;     <br>&lt;Anexadores&gt;         <br>&lt;RollingFile name=&#8221;LogToFile&#8221; fileName=&#8221;${env:JBOSS_HOME}\/standalone\/log\/xxx.log&#8221; filePattern=&#8221;${env:JBOSS_HOME}\/standalone\/log\/xxx.log-%d{yyyy-MM-dd}&#8221;&gt; &lt;PatternLayout&gt; <br>&lt;pattern&gt;[%-5level] %d{aaaa-MM-dd HH:mm:ss.SSS} [%t] %c{1} &#8211; %msg%n &lt;\/pattern&gt; &lt;\/PatternLayout&gt; <br>&lt;Pol\u00c3\u00adticas&gt; <br>&lt;TimeBasedTriggeringPolicy intervalo=&#8221;1&#8243; modulate=&#8221;true&#8221; \/&gt; <br>&lt;OnStartupTriggeringPolicy \/&gt;<br>&lt;\/Policies&gt; &lt;!&#8211; Se crear\u00c3\u00a1n m\u00c3\u00a1ximo 10 archivos todos los d\u00c3\u00adas &#8211;&gt; <br>&lt;DefaultRolloverStrategy max=&#8221;20&#8243;&gt; <br>&lt;Eliminar basePath=&#8221;${env:JBOSS_HOME}\/standalone\/log\/&#8221; maxDepth=&#8221;10&#8243;&gt; <br>&lt;!&#8211; Eliminar todos los archivos con m\u00c3\u00a1s de 30 d\u00c3\u00adas &#8211;&gt; <br>&lt;IfLastModified edad=&#8221;30d&#8221; \/&gt; <br>&lt;\/Eliminar&gt; <br>&lt;\/Estrategia de rollover predeterminada&gt; <br>&lt;\/RollingFile&gt;     <br>&lt;\/Anexores&gt;    <br> &lt;Loggers&gt;         <br>&lt;!&#8211; evite registros duplicados con aditividad=false &#8211;&gt;         <br>&lt;Logger name=&#8221;xxx-be&#8221; nivel=&#8221;${env:LOG_LEVEL}&#8221; additivity=&#8221;false&#8221;&gt; &lt;AppenderRef ref=&#8221;LogToFile&#8221;\/&gt;         <br>&lt;\/Registrador&gt;         <br>&lt;Nivel ra\u00c3\u00adz=&#8221;${env:LOG_LEVEL}&#8221;&gt;             <br>&lt;ApenderRef ref=&#8221;LogToFile&#8221;\/&gt;         <br>&lt;\/Root&gt;     <br>&lt;\/Registradores&gt; <br>&lt;\/Configuraci\u00c3\u00b3n&gt;<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>log4j2.xml<\/li><li>Usando Logger en C\u00c3\u00b3digo<br>importar org.apache.logging.log4j.Logger;<br>Registrador registrador = LogManager.getLogger(&#8220;xxx-be&#8221;);<br>logger.info(&#8220;iniciado&#8221;);<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Necesitaba todo el d\u00c3\u00ada para que funcionara. Espero que esto ayude a los desarrolladores.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dependencias de enlace de Log4j2 y SLF4jPara que Log4j2 funcione con SLF4J, debemos incluir las siguientes 3 dependencias. log4j-slf4j-impl.jar: enlace Log4j 2 SLF4J. Permit que las aplicaciones codidas en la API SLF4J utilice Log4j2 como implementaci\u00f3n.log4j-api.jar: proporciona los componentes del adaptador necesarios para que los implementadores creen un registro. implementaci\u00f3n.log4j-core.jar: clases principales de implementaci\u00f3n [&hellip;]<\/p>\n","protected":false},"author":65283547,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_seo_llms_txt_always_include":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_wpcom_ai_launchpad_first_post":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1017],"tags":[731731598,177442530,731731587,731731575,731731561],"class_list":["post-194","post","type-post","status-publish","format-standard","hentry","category-java","tag-configure-log4j2","tag-log4j2","tag-log4j2-under-wildfly","tag-log4j2-using-environment-variable","tag-log4j2-using-system-variable"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4CoHV-38","jetpack-related-posts":[{"id":217,"url":"https:\/\/vkrastev1blog.com\/2022\/05\/20\/eclipse-how-to-use-the-jpa-static-metamodel-classes-while-writing-criteria-queries-in-hibernate\/","url_meta":{"origin":194,"position":0},"title":"Eclipse c\u00c3\u00b3mo utilizar las clases de metamodelo est\u00c3\u00a1tico JPA al escribir consultas de criterios en Hibernate","author":"vkrastev2014","date":"20.05.2022","format":false,"excerpt":"When you use Maven you have to add in your POM following dependency: <dependency> <groupId>org.hibernate<\/groupId> <artifactId>hibernate-jpamodelgen<\/artifactId> <version>5.3.7.Final<\/version> <\/dependency> Now you have to add folder target\\generated-sources\\annotations to your classpath as by default, the classes will be generated in this folder only. You go in Project Build Path -> Configure Build Path\u2026","rel":"","context":"In &quot;Java&quot;","block_context":{"text":"Java","link":"https:\/\/vkrastev1blog.com\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":247,"url":"https:\/\/vkrastev1blog.com\/2024\/04\/11\/how-to-create-pdf-from-html-or-image-using-java-pdfbox-framework\/","url_meta":{"origin":194,"position":1},"title":"C\u00c3\u00b3mo crear PDF a partir de HTML o imagen usando el marco java pdfbox","author":"vkrastev2014","date":"11.04.2024","format":false,"excerpt":"How to create PDF from HTML or image using java pdfbox framework Following example code here: In pom.xml insert or get the jar files and add them to the java project if you don't use maven: <repositories> <repository> <id>jitpack.io<\/id> <url>https:\/\/jitpack.io<\/url> <\/repository> <\/repositories> <!-- https:\/\/mvnrepository.com\/artifact\/org. apache.pdfbox\/pdfbox --> <dependency> <groupId>org.apache.pdfbox<\/groupId> <artifactId>pdfbox<\/artifactId> <version>3.0.2<\/version>\u2026","rel":"","context":"In &quot;Java&quot;","block_context":{"text":"Java","link":"https:\/\/vkrastev1blog.com\/category\/java\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2024\/04\/Java-PDFBox_-HTML-and-Image-to-PDF.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2024\/04\/Java-PDFBox_-HTML-and-Image-to-PDF.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2024\/04\/Java-PDFBox_-HTML-and-Image-to-PDF.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2024\/04\/Java-PDFBox_-HTML-and-Image-to-PDF.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2024\/04\/Java-PDFBox_-HTML-and-Image-to-PDF.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2024\/04\/Java-PDFBox_-HTML-and-Image-to-PDF.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":189,"url":"https:\/\/vkrastev1blog.com\/2022\/03\/24\/exclude-pom-dependency-from-all-dependencies-in-java-project-eclipse\/","url_meta":{"origin":194,"position":2},"title":"Excluir la dependencia de pom de todas las dependencias en Java Project Eclipse","author":"vkrastev2014","date":"24.03.2022","format":false,"excerpt":"I have had a problem to exclude a dependency from all dependencies in POM file. If you dont use Eclipse you have to put exlusioin clauses on all dependencies in POM file for this dependency. I use Eclipse and you can do following. Open the Project in Eclipse in Package\u2026","rel":"","context":"In &quot;Java&quot;","block_context":{"text":"Java","link":"https:\/\/vkrastev1blog.com\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":208,"url":"https:\/\/vkrastev1blog.com\/2022\/04\/03\/maven-excluding-jars-from-war-file\/","url_meta":{"origin":194,"position":3},"title":"Maven excluyendo Jars del archivo WAR","author":"vkrastev2014","date":"03.04.2022","format":false,"excerpt":"I have had a problem to exclude some Jars from War File with maven. You can do it using maven-war-plugin <project> ... <build> <plugins> <plugin> <artifactId>maven-war-plugin<\/artifactId> <version>3.3.2<\/version> <configuration> <packagingExcludes>WEB-INF\/lib\/xxxx*.jar<\/packagingExcludes> <\/configuration> <\/plugin> <\/plugins> <\/build> ... <\/project>","rel":"","context":"In &quot;Java&quot;","block_context":{"text":"Java","link":"https:\/\/vkrastev1blog.com\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":232,"url":"https:\/\/vkrastev1blog.com\/2022\/10\/31\/install-solr-8-under-windows-as-service\/","url_meta":{"origin":194,"position":4},"title":"Instale Solr 8 en Windows como servicio","author":"vkrastev2014","date":"31.10.2022","format":false,"excerpt":"Here is short explained how to install Solr 8 as Windows service Download nssm from https:\/\/nssm.cc\/release\/nssm-2.24.zip and extract it to C:\\Program Files\\nssm Donwload Solr 8 from https:\/\/dlcdn.apache.org\/lucene\/solr\/8.11.2\/solr-8.11.2.zip and extract it to C:\\web\\solr Java Version 8 or later have to be istalled and JAVA_HOME environment variable set Create Windows Service solr8.\u2026","rel":"","context":"In &quot;Art\u00c3\u00adculos sobre todos los dem\u00c3\u00a1s temas que no est\u00c3\u00a1n incluidos en los temas principales&quot;","block_context":{"text":"Art\u00c3\u00adculos sobre todos los dem\u00c3\u00a1s temas que no est\u00c3\u00a1n incluidos en los temas principales","link":"https:\/\/vkrastev1blog.com\/category\/articulos-sobre-todos-los-demas-temas-que-no-estan-incluidos-en-los-temas\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":129,"url":"https:\/\/vkrastev1blog.com\/2014\/05\/26\/new-gpu-bitcoin-miner-is-there-named-diamantminer-how-to-install-on-windows\/","url_meta":{"origin":194,"position":5},"title":"La nueva GPU Bitcoin Miner se llama DiamantMiner. C\u00c3\u00b3mo instalar en Windows","author":"vkrastev2014","date":"26.05.2014","format":false,"excerpt":"New GPU Bitcoin Miner is there named DiamantMiner. How to install on Windows I have tried the new bitcoin miner and I find it very good. What you should do to install it on Windows is described here. How to build and install DiamantMiner requires the SDK for Java Version\u2026","rel":"","context":"In &quot;Art\u00c3\u00adculos sobre todos los dem\u00c3\u00a1s temas que no est\u00c3\u00a1n incluidos en los temas principales&quot;","block_context":{"text":"Art\u00c3\u00adculos sobre todos los dem\u00c3\u00a1s temas que no est\u00c3\u00a1n incluidos en los temas principales","link":"https:\/\/vkrastev1blog.com\/category\/articulos-sobre-todos-los-demas-temas-que-no-estan-incluidos-en-los-temas\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/posts\/194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/users\/65283547"}],"replies":[{"embeddable":true,"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/comments?post=194"}],"version-history":[{"count":11,"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/posts\/194\/revisions"}],"predecessor-version":[{"id":207,"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/posts\/194\/revisions\/207"}],"wp:attachment":[{"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/media?parent=194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/categories?post=194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/tags?post=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}