首页 > 其他分享 >ignite系列之14--log4j2日志配置

ignite系列之14--log4j2日志配置

时间:2023-03-16 15:59:05浏览次数:40  
标签:ignite 14 -- cfg 配置 日志 log4j2

Ignite支持各种常见的日志库和框架:

  • JUL (默认);
  • Log4j2;
  • JCL;
  • SLF4J。

ignite默认日志介绍(无需配置)见:https://www.cnblogs.com/yangh2016/p/17221433.html

但上述日志方式在与log4j标准不同,在生产环境存在一些问题,故需要配置log4j的方式

.如何配置使用Log4j2?

1、配置文件

<?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="3" modulate="true" />-->
                            <SizeBasedTriggeringPolicy size="100 MB" />
                        </Policies>
                        <DefaultRolloverStrategy max="30"/>
                    </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="debug">
            <!-- 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>
1)日志级别:Root level="debug">
2)日志文件大小:
<SizeBasedTriggeringPolicy size="100 MB" />
3)压缩后的文件个数:
 <DefaultRolloverStrategy max="30"/>
日志文件效果:

 

 

2、jar包依赖

maven工程需要添加如下依赖

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

对于使用ignite部署包(apache-ignite-2.14.0-bin)需要把依赖包的目录移动到libs目录

 

 3、java代码示例(配置log4j2)

IgniteConfiguration cfg = new IgniteConfiguration();
IgniteLogger log = new Log4J2Logger("log4j2-config.xml");
cfg.setGridLogger(log);
// Start a node.
try (Ignite ignite = Ignition.start(cfg)) {
    ignite.log().info("Info Message Logged!");
}

4、ignite配置文件配置log4j2

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

 

标签:ignite,14,--,cfg,配置,日志,log4j2
From: https://www.cnblogs.com/yangh2016/p/17222883.html

相关文章

  • react项目中遇到的小问题汇总
    sessionStorage在刷新的时候不会销毁,在窗口关闭的时候才销毁默认情况下,useEffect在每次渲染之后执行文件上传上传文件通过form表单拿到的数据是解析后的,直接拿Upload.D......
  • 1 requests高级用法、2 代理池搭建、3 爬取某视频网站 、4 爬取新闻
    目录1requests高级用法1.0解析json1.1ssl认证(了解)1.2使用代理(重要)1.3超时设置1.4异常处理1.5上传文件2代理池搭建2.1django后端获取客户端的ip3爬取某视频网站......
  • 初始JSON、JSON三种形式
    初始JSON 1、什么是JSON JSON全称是JavaScriptObjectNotationAjax发送和接收数据的一种格式  2、为什么需要JSONJSON有三种形式,每种形式的写法都和JS中的数......
  • 解决:无法获取实体类com.xxx.pojo.AppUser对应的表名
    问题:在Application启动类中使用的@MapperScan注解,导入的包为:org.mybaties.spring.annotation.MapperScan解决:导入包改为:tk.mybatis.spring.annotation.MapperScan,解......
  • 【并发编程六】c++进程通信——信号量(semaphore)
     【并发编程六】c++进程通信——信号量(semaphore)一、概述二、信号量三、原理四、过程1、进程A过程2、进程B过程五、demo1、进程A2、进程B六、输出......
  • docker mysql8.0 启动,挂数据卷,定时备份,恢复~
    安装mysql从mysql社区版的官方源去拉取镜像:mysql/mysql-server-DockerImage|DockerHubdockerrun--name=mysql1-dmysql/mysql-server:latest 镜像起来之后,mys......
  • uni-app 实现图片主题色的获取
    uni-app实现图片主题色的获取<canvascanvas-id="getImageThemeColorCanvas"id="getImageThemeColorCanvas"></canvas>canvas元素默认宽为300,高为150。需要注意的......
  • 设计模式之装饰者模式,奶茶店场景
    //Seehttps://aka.ms/new-console-templateformoreinformationusingSystem.Drawing;/*装饰者模式,不改变实现类的情况下,动态给实现类增加新功能,这里使用聚合......
  • github更新项目中的子模块
    若a项目已经引入了b项目作为子模块,可以使用以下步骤来同步更新b子模块:进入a项目的根目录,执行以下命令来切换到b子模块的目录:cdb执行以下命令,将b子模块更新到最新版本:git......
  • redis线程模型-IO多路复用单线程通俗理解
     Redis单线程redis是以socket方式通信,socket服务端可同时接受多个客户端请求连接,也就是说,redis服务同时面对多个redis客户端连接请求,而redis服务本身是单线程运行。 ......