首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >apache Ignite ignite配置Log4j2日志例子

apache Ignite ignite配置Log4j2日志例子

作者头像
lovelife110
发布2021-12-08 17:14:58
5130
发布2021-12-08 17:14:58
举报
文章被收录于专栏:爱生活爱编程爱生活爱编程

apache Ignite ignite配置Log4j2日志例子

例子代码位置

https://github.com/lilihongjava/ignite_examples/tree/main/ignite-03

ignite-log4j2模块

在使用Log4j之前,需要先导入ignite-log4j2模块。

    <dependencies>
        <dependency>
            <groupId>org.apache.ignite</groupId>
            <artifactId>ignite-log4j2</artifactId>
            <version>${ignite.version}</version>
        </dependency>
    </dependencies>

配置xml文件

配置IgniteConfiguration的gridLogger属性,如下所示:

        <property name="gridLogger">
            <bean class="org.apache.ignite.logger.log4j2.Log4J2Logger">
                <!-- log4j2 configuration file -->
                <constructor-arg type="java.lang.String" value="config/ignite-log4j2.xml"/>
            </bean>
        </property>

注意: ignite-log4j2.xml的路径要么是绝对路径,要么是相对路径,相对于IGNITE_HOME (ignite-log4j2-2.11.0.jar里代码限制)

在这里插入图片描述
在这里插入图片描述

在idea中,设置环境变量IGNITE_HOME=E:\java\ignite_examples\如下所示:

在这里插入图片描述
在这里插入图片描述

ignite-log4j2.xml文件

在环境变量IGNITE_HOME下创建config目录,然后再创建ignite-log4j2.xml文件,内容如下,来源于官方apache-ignite-2.11.0-bin包下apache-ignite-2.11.0-bin\config\ignite-log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>

<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<Configuration monitorInterval="60">
    <Appenders>
        <Console name="CONSOLE" target="SYSTEM_OUT">
            <PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
            <ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="ACCEPT"/>
        </Console>

        <Console name="CONSOLE_ERR" target="SYSTEM_ERR">
            <PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
        </Console>

        <Routing name="FILE">
            <Routes pattern="$${sys:nodeId}">
                <Route>
                    <RollingFile name="Rolling-${sys:nodeId}" fileName="${sys:IGNITE_HOME}/work/log/ignite-${sys:nodeId}.log"
                                 filePattern="${sys:IGNITE_HOME}/work/log/ignite-${sys:nodeId}-%i-%d{yyyy-MM-dd}.log.gz">
                        <PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
                        <Policies>
                            <TimeBasedTriggeringPolicy interval="6" modulate="true" />
                            <SizeBasedTriggeringPolicy size="10 MB" />
                        </Policies>
                    </RollingFile>
                </Route>
            </Routes>
        </Routing>
    </Appenders>

    <Loggers>
        <!--
        <Logger name="org.apache.ignite" level=DEBUG/>
        -->

        <!--
            Uncomment to disable courtesy notices, such as SPI configuration
            consistency warnings.
        -->
        <!--
        <Logger name="org.apache.ignite.CourtesyConfigNotice" level=OFF/>
        -->

        <Logger name="org.springframework" level="WARN"/>
        <Logger name="org.eclipse.jetty" level="WARN"/>

        <!--
        Avoid warnings about failed bind attempt when multiple nodes running on the same host.
        -->
        <Logger name="org.eclipse.jetty.util.log" level="ERROR"/>
        <Logger name="org.eclipse.jetty.util.component" level="ERROR"/>

        <Logger name="com.amazonaws" level="WARN"/>

        <Root level="INFO">
            <!-- Uncomment to enable logging to console. -->
            <!--<AppenderRef ref="CONSOLE" level="DEBUG"/>-->

            <AppenderRef ref="CONSOLE_ERR" level="ERROR"/>
            <AppenderRef ref="FILE" level="DEBUG"/>
        </Root>
    </Loggers>
</Configuration>

查看内容可知,日志输出位置也依赖与IGNITE_HOME环境变量

调debug模式

修改 ignite-log4j2.xml ,开启debug模式,ignite有些报错需要开启debug模式下才会显示详细报错信息

        <Root level="DEBUG">
            <!-- Uncomment to enable logging to console. -->
            <AppenderRef ref="CONSOLE" level="DEBUG"/>

            <AppenderRef ref="CONSOLE_ERR" level="ERROR"/>
            <AppenderRef ref="FILE" level="DEBUG"/>
        </Root>

启动测试

执行https://github.com/lilihongjava/ignite_examples/blob/main/ignite-03/src/main/java/org/lovelife110/example/LogExample.java 日志如下

在这里插入图片描述
在这里插入图片描述
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-11-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • apache Ignite ignite配置Log4j2日志例子
  • 例子代码位置
  • ignite-log4j2模块
  • 配置xml文件
  • ignite-log4j2.xml文件
  • 调debug模式
  • 启动测试
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档