You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@griffin.apache.org by gu...@apache.org on 2019/08/07 14:48:02 UTC

[griffin] branch master updated: [GRIFFIN-273] Griffin Service with user-defined log4j2 configuration

This is an automated email from the ASF dual-hosted git repository.

guoyp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/griffin.git


The following commit(s) were added to refs/heads/master by this push:
     new 2945fd2  [GRIFFIN-273] Griffin Service with user-defined log4j2 configuration
2945fd2 is described below

commit 2945fd28b4130c716855b8603db76948ac141c48
Author: Johnnie <jo...@gmail.com>
AuthorDate: Wed Aug 7 22:47:39 2019 +0800

    [GRIFFIN-273] Griffin Service with user-defined log4j2 configuration
    
    Currently, the Griffin service module use spring-boot default log4j2 configuration.
    
    This approach is not easy to change the config for debugging and add new appender such as
    RollingFile
    
    Author: Johnnie <jo...@gmail.com>
    Author: Johnnie Zhang <yi...@ebay.com>
    
    Closes #518 from joohnnie/GRIFFIN-273.
---
 .gitignore                                         |  3 +-
 service/pom.xml                                    | 18 +++++++++
 .../apache/griffin/core/GriffinWebApplication.java |  2 +-
 .../src/main/resources/application-dev.properties  |  4 +-
 .../main/resources/application-docker.properties   |  2 +
 .../main/resources/application-mysql.properties    |  2 +
 .../src/main/resources/application-prod.properties |  4 +-
 service/src/main/resources/application.properties  |  2 +
 service/src/main/resources/log4j2-spring.xml       | 43 ++++++++++++++++++++++
 service/src/test/resources/application.properties  |  2 +
 10 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore
index a09422a..5e0ef52 100644
--- a/.gitignore
+++ b/.gitignore
@@ -41,4 +41,5 @@ measure/src/test/test_scala/*
 
 .vscode
 
-environment.local.ts
\ No newline at end of file
+environment.local.ts
+logs/
\ No newline at end of file
diff --git a/service/pom.xml b/service/pom.xml
index 8f51587..3c4ed80 100644
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -84,6 +84,10 @@ under the License.
         </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-log4j2</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-jpa</artifactId>
             <exclusions>
                 <exclusion>
@@ -147,6 +151,10 @@ under the License.
                     <groupId>javax.servlet</groupId>
                     <artifactId>servlet-api</artifactId>
                 </exclusion>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-log4j12</artifactId>
+                </exclusion>
             </exclusions>
         </dependency>
         <dependency>
@@ -195,6 +203,10 @@ under the License.
                     <groupId>org.mortbay.jetty</groupId>
                     <artifactId>servlet-api-2.5</artifactId>
                 </exclusion>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-log4j12</artifactId>
+                </exclusion>
             </exclusions>
         </dependency>
 
@@ -203,6 +215,12 @@ under the License.
             <groupId>io.confluent</groupId>
             <artifactId>kafka-schema-registry-client</artifactId>
             <version>${confluent.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-log4j12</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <!--schedule-->
diff --git a/service/src/main/java/org/apache/griffin/core/GriffinWebApplication.java b/service/src/main/java/org/apache/griffin/core/GriffinWebApplication.java
index 4ed4773..33fc049 100644
--- a/service/src/main/java/org/apache/griffin/core/GriffinWebApplication.java
+++ b/service/src/main/java/org/apache/griffin/core/GriffinWebApplication.java
@@ -35,8 +35,8 @@ public class GriffinWebApplication {
             .getLogger(GriffinWebApplication.class);
 
     public static void main(String[] args) {
-        LOGGER.info("application start");
         SpringApplication.run(GriffinWebApplication.class, args);
+        LOGGER.info("application started");
     }
 
     @Bean
diff --git a/service/src/main/resources/application-dev.properties b/service/src/main/resources/application-dev.properties
index d310ce3..14bd198 100644
--- a/service/src/main/resources/application-dev.properties
+++ b/service/src/main/resources/application-dev.properties
@@ -25,4 +25,6 @@ spring.datasource.driver-class-name=org.h2.Driver
 spring.datasource.schema=classpath:init_quartz_h2.sql
 # enable h2 console, default path: http://localhost:8080/h2-console/
 spring.h2.console.enabled=true
-spring.jpa.show-sql=true
\ No newline at end of file
+spring.jpa.show-sql=true
+
+logging.file=logs/griffin-service.log
\ No newline at end of file
diff --git a/service/src/main/resources/application-docker.properties b/service/src/main/resources/application-docker.properties
index 8c7806e..2a0bf2b 100644
--- a/service/src/main/resources/application-docker.properties
+++ b/service/src/main/resources/application-docker.properties
@@ -80,3 +80,5 @@ livy.task.submit.interval.second=3
 livy.task.appId.retry.count=3
 # yarn url
 yarn.uri=http://10.148.215.23:38088
+
+logging.file=logs/griffin-service.log
\ No newline at end of file
diff --git a/service/src/main/resources/application-mysql.properties b/service/src/main/resources/application-mysql.properties
index 0b124ef..e80534b 100644
--- a/service/src/main/resources/application-mysql.properties
+++ b/service/src/main/resources/application-mysql.properties
@@ -25,3 +25,5 @@ spring.jpa.generate-ddl=true
 spring.datasource.driver-class-name=com.mysql.jdbc.Driver
 spring.jpa.show-sql=true
 spring.jpa.hibernate.ddl-auto=update
+
+logging.file=logs/griffin-service.log
\ No newline at end of file
diff --git a/service/src/main/resources/application-prod.properties b/service/src/main/resources/application-prod.properties
index b977276..29afae5 100644
--- a/service/src/main/resources/application-prod.properties
+++ b/service/src/main/resources/application-prod.properties
@@ -65,4 +65,6 @@ livy.task.max.concurrent.count=20
 livy.task.submit.interval.second=3
 livy.task.appId.retry.count=3
 # yarn url
-yarn.uri=http://localhost:8088
\ No newline at end of file
+yarn.uri=http://localhost:8088
+
+logging.file=logs/griffin-service.log
\ No newline at end of file
diff --git a/service/src/main/resources/application.properties b/service/src/main/resources/application.properties
index c01c270..ccef9dd 100644
--- a/service/src/main/resources/application.properties
+++ b/service/src/main/resources/application.properties
@@ -77,3 +77,5 @@ livy.server.auth.kerberos.keytab=/path/to/livy/keytab/file
 yarn.uri=http://localhost:8088
 # griffin event listener
 internal.event.listeners=GriffinJobEventHook
+
+logging.file=logs/griffin-service.log
\ No newline at end of file
diff --git a/service/src/main/resources/log4j2-spring.xml b/service/src/main/resources/log4j2-spring.xml
new file mode 100644
index 0000000..c021b4a
--- /dev/null
+++ b/service/src/main/resources/log4j2-spring.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="WARN">
+    <Properties>
+        <Property name="PID">????</Property>
+        <Property name="LOG_EXCEPTION_CONVERSION_WORD">%xwEx</Property>
+        <Property name="LOG_LEVEL_PATTERN">%5p</Property>
+        <Property name="CONSOLE_LOG_PATTERN">%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{${LOG_LEVEL_PATTERN}} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}[%L]}{cyan}  %clr{:}{faint} %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
+        <Property name="FILE_LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN} ${sys:PID} --- [%t] %-40.40c{1.}[%L] : %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
+    </Properties>
+    <Appenders>
+        <Console name="Console" target="SYSTEM_OUT" follow="true">
+            <PatternLayout pattern="${sys:CONSOLE_LOG_PATTERN}" />
+        </Console>
+        <RollingFile name="File" fileName="${sys:LOG_FILE}"
+                     filePattern="logs/$${date:yyyy-MM}/application-%d{yyyy-MM-dd-HH}-%i.log.gz">
+            <PatternLayout>
+                <Pattern>${sys:FILE_LOG_PATTERN}</Pattern>
+            </PatternLayout>
+            <Policies>
+                <SizeBasedTriggeringPolicy size="10 MB" />
+            </Policies>
+            <DefaultRollOverStrategy max = "10"/>
+        </RollingFile>
+    </Appenders>
+    <Loggers>
+        <Logger name="org.apache.catalina.startup.DigesterFactory" level="error" />
+        <Logger name="org.apache.catalina.util.LifecycleBase" level="error" />
+        <Logger name="org.apache.coyote.http11.Http11NioProtocol" level="warn" />
+        <logger name="org.apache.sshd.common.util.SecurityUtils" level="warn"/>
+        <Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="warn" />
+        <Logger name="org.crsh.plugin" level="warn" />
+        <logger name="org.crsh.ssh" level="warn"/>
+        <Logger name="org.eclipse.jetty.util.component.AbstractLifeCycle" level="error" />
+        <Logger name="org.hibernate.validator.internal.util.Version" level="warn" />
+        <logger name="org.springframework.boot.actuate.autoconfigure.CrshAutoConfiguration" level="warn"/>
+        <logger name="org.springframework.boot.actuate.endpoint.jmx" level="warn"/>
+        <logger name="org.thymeleaf" level="warn"/>
+        <Root level="info">
+            <AppenderRef ref="Console" />
+            <AppenderRef ref="File" />
+        </Root>
+    </Loggers>
+</Configuration>
diff --git a/service/src/test/resources/application.properties b/service/src/test/resources/application.properties
index 86d5316..7864be9 100644
--- a/service/src/test/resources/application.properties
+++ b/service/src/test/resources/application.properties
@@ -59,3 +59,5 @@ elasticsearch.scheme=http
 # elasticsearch.password = password
 # griffin event listener
 internal.event.listeners=GriffinJobEventHook,GriffinTestJobEventHook
+
+logging.file=logs/griffin-service.log
\ No newline at end of file