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
日志如下
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lovelife110

你的鼓励是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值