log4rs测试

引入crate:

log4rs = {version = "1.3.0"}
log = {version = "0.4.20"}

配置文件

和Cargo.toml同级创建log4rs.yml,内容如下:

refresh_rate: 30 seconds
appenders:stdout:kind: consolerollingfile:kind: rolling_filepath: logs/app.logencoder:pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M} threadID:{I}] {m}{n}"policy:trigger:kind: sizelimit: 10mbroller:kind: fixed_windowpattern: "logs/app-{}.log"count: 5base: 1root:level: infoappenders:- stdout- rollingfile

测试代码

extern crate log;
extern crate log4rs;use log::{info,error};
use std::thread;#[tokio::main]
async fn main() -> io::Result<()> {log4rs::init_file("log4rs.yml", Default::default()).unwrap();info!("hello log4rs");error!("this is error message!");let t1 = thread::spawn(||{info!("this message is output by sub thead!");error!("从子线程里输出的错误信息");});t1.join();Ok(())
}

配置说明

d, date - The current time. By default, the ISO 8601 format is used. A custom format may be provided in the syntax accepted by chrono. The timezone defaults to local, but can be specified explicitly by passing a second argument of utc for UTC or local for local time.
{d} - 2016-03-20T14:22:20.644420340-08:00
{d(%Y-%m-%d %H:%M:%S)} - 2016-03-20 14:22:20
{d(%Y-%m-%d %H:%M:%S %Z)(utc)} - 2016-03-20 22:22:20 UTC
f, file - The source file that the log message came from, or ??? if not provided.
h, highlight - Styles its argument according to the log level. The style is intense red for errors, red for warnings, blue for info, and the default style for all other levels.
{h(the level is {l})} - the level is ERROR
l``, level - The log level.
L, line - The line that the log message came from, or ??? if not provided.
m, message - The log message.
M, module - The module that the log message came from, or ??? if not provided.
n - A platform-specific newline.
t, target - The target of the log message.
T, thread - The name of the current thread.
I, thread_id - The ID of the current thread.
X, mdc - A value from the MDC. The first argument specifies the key, and the second argument specifies the default value if the key is not present in the MDC. The second argument is optional, and defaults to the empty string.
{X(user_id)} - 123e4567-e89b-12d3-a456-426655440000
{X(nonexistent_key)(no mapping)} - no mapping
An "unnamed" formatter simply formats its argument, applying the format specification.
{({l} {m})} - INFO hello

输出效果

[2024-03-15T23:08:43.434750 INFO  helloworld threadID:20052] hello log4rs
[2024-03-15T23:08:43.434990 ERROR helloworld threadID:20052] this is error message!
[2024-03-15T23:08:43.435304 INFO  helloworld threadID:18732] this message is output by sub thead!
[2024-03-15T23:08:43.435507 ERROR helloworld threadID:18732] 从子线程里输出的错误信息
[2024-03-15T23:08:43.436489 INFO  helloworld threadID:20052] {"age":43,"name":"henreash","phone":["+44-012345","+44-0123456"]}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/748157.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【yolo检测模型出现大量误报】

文章目录 1.可能需要针对以下几个方面进行优化和调整&#xff1a;2.出现大量误报会直接导致精确率和准确率明显下降。3.解决办法&#xff0c;采用最简单的样本均衡3.1.样本均衡3.2.添加负样本 1.可能需要针对以下几个方面进行优化和调整&#xff1a; 数据集质量&#xff1a; 确…

ASP.NET Mvc+FFmpeg+Video实现视频转码

目录 首先&#xff0c;做了视频上传的页面&#xff1a; FFmpeg&#xff1a;视频转码 FFmpegHelper工作类&#xff1a; 后台控制器代码&#xff1a; 前端视图代码&#xff1a; 参考文章&#xff1a; 首先&#xff0c;做了视频上传的页面&#xff1a; 借鉴了这篇文章 ASP.…

D. Tandem Repeats?

思路&#xff1a;首先我们要枚举长度&#xff0c;然后从前往后遍历&#xff0c;判断是否存在改长度的重复串。 代码&#xff1a; void solve(){string s;cin >> s;int n s.size();int ans 0;for(int len n / 2;len > 1;len --){int t 0;for(int i 0;i len <…

【Qt问题】解决UI设计显示和运行显示界面大小不一致问题

问题描述&#xff1a; 在我自己第一次用Qt Creator的时候&#xff0c;发现老师的每次ui界面是多大&#xff0c;运行出来的窗口就是多大&#xff0c;而我自己的每次大小都对不上&#xff0c;所以我每次都要去手动调整窗口大小&#xff0c;非常痛苦。 经过多方查找发现这是由于…

TSINGSEE青犀AI智能分析网关V4酿酒厂安全挂网AI检测算法

在酿酒行业中&#xff0c;安全生产一直是企业经营中至关重要的一环。为了确保酒厂生产过程中的安全&#xff0c;TSINGSEE青犀AI智能分析网关V4的安全挂网AI检测算法发挥了重要作用。 TSINGSEE青犀AI智能分析网关V4的安全挂网检测算法是针对酒厂里酒窖挂网行为进行智能检测与识…

Qt按回车键实现确定/发送按钮功能

构造函数中&#xff0c;添加如下代码 connect(ui->lineEdit,SIGNAL(returnPressed()),ui->pushButton_send, SIGNAL(clicked()),Qt::UniqueConnection) 当光标在lineEdit上时&#xff0c;输入完毕直接按回车键&#xff08;大/小都可以&#xff09;&#xff0c; //就会…

个人简历主页搭建系列-03:Hexo+Github Pages 介绍,框架配置

今天的更新内容主要是了解为什么选择这个网站搭建方案&#xff0c;以及一些前置软件的安装。 Why Hexo? 首先我们了解一下几种简单的网站框架搭建方案&#xff0c;看看对于搭建简历网站的需求哪个更合适。 在 BuiltWith&#xff08;网站技术分析工具&#xff09;上我们可以…

【矩阵】73. 矩阵置零【中等】

矩阵置零 给定一个 m x n 的矩阵&#xff0c;如果一个元素为 0 &#xff0c;则将其所在行和列的所有元素都设为 0 。请使用 原地 算法。 示例 1&#xff1a; 输入&#xff1a;matrix [[1,1,1],[1,0,1],[1,1,1]] 输出&#xff1a;[[1,0,1],[0,0,0],[1,0,1]] 解题思路 1、…

SpringCloud Bus 消息总线

一、前言 接下来是开展一系列的 SpringCloud 的学习之旅&#xff0c;从传统的模块之间调用&#xff0c;一步步的升级为 SpringCloud 模块之间的调用&#xff0c;此篇文章为第八篇&#xff0c;即介绍 Bus 消息总线。 二、概述 2.1 遗留的问题 在上一篇文章的最后&#xff0c;我…

汇编语言(Assemble Language)学习笔记(更新中)

零.学习介绍和使用工具 【1】我们使用的教材是机械工业出版社的《32位汇编语言程序设计第二版》。 指导老师是福州大学的倪一涛老师。 这门课程教授的是Intel 80*86系列处理器的32位汇编。我们现在的处理器都兼容这个处理器。 这篇博客只是大二下汇编语言学习的总结&#xff…

数据结构顺序表的操作,窗口界面(c语言版)

// 准备头文件 #include <stdio.h> #include <stdlib.h>#define InitSize 10 // 动态顺序表的初始默认长度// 定义C语言的bool变量 #define bool char #define true 1 #define false 0/* 定义数据元素的数据类型 */ typedef int ElemType; // 方便更改// 动态顺…

sui move动态字段练习(5)- 总结与思考

引言 之前几篇文章&#xff0c;我们用sui move动态字段模拟solidity映射&#xff0c;实现了一个类似erc20的代币&#xff0c;这使我更加深刻地理解了sui move和solidity编程特性和编程思想的区别。下面是我的总结与思考。 总结 首先&#xff0c;sui与solidity的编程特性有很…

css 各种方位计算 - client系列 offset系列 scroll系列 x/y 系列

offset系列 HTMLElement.offsetTop - Web API 接口参考 | MDN 一文读懂offsetHeight/offsetLeft/offsetTop/offsetWidth/offsetParent_heightoffset-CSDN博客 client系列 搞清clientHeight、offsetHeight、scrollHeight、offsetTop、scrollTop-CSDN博客 scroll系列 秒懂scr…

2024年,如何使用chatgpt4.0为工作赋能?

ChatGPT 4.0的工作原理和功能 ChatGPT 4.0的工作原理和功能可以从以下几个方面进行详细说明&#xff1a; 工作原理 ChatGPT 4.0的工作原理主要基于深度学习技术&#xff0c;特别是Transformer模型的应用。它通过大量的文本数据进行训练&#xff0c;学习语言的模式和规律&…

Android 启动service(Kotlin)

一、使用startForegroundService()或startService&#xff08;&#xff09;启用service **Activity //启动service val intent: Intent Intent(ServiceActivitythis,MyService::class.java) //Build.VERSION_CODES.O 26 // Android8以后&#xff0c;不允许后台启动Service i…

波特图笔记

波特图相关知识 介绍波特图之前,首先要介绍放大电路的复频域分析的相关概念。 增益函数 放大器工作在小信号时,晶体管可以用线性模型近似。忽略温度等参数对元件的影响,认为放大器是一个线性是不变系统。输入信号和输出信号之间关系可以用线性常系数微分方程来进行描述。…

OpenOFDM接收端信号处理流程

Overview — OpenOFDM 1.0 documentation 本篇文章为学习OpenOFDM之后的产出PPT&#xff0c;仅供学习参考。 ​​​​​​​

vsto快速在excel中查找某个字符串

是的&#xff0c;使用foreach循环遍历 Excel.Range 可能会较慢&#xff0c;特别是在大型数据集上。为了提高效率&#xff0c;你可以考虑使用 Value 属性一次性获取整个范围的值&#xff0c;然后在内存中搜索文本。这样可以减少与 Excel 之间的交互次数&#xff0c;提高性能。 …

嵌入式3-15

1、整理思维导图 2、整理课上单向循环链表的代码 3、完成双向链表的剩下四个功能 2、 node_p create_list()//创建链表 { node_p p(node_p)malloc(sizeof(node)); if(pNULL) { printf("申请失败\n"); return NULL; } p->len…

使用VLC实现自动播放视频

VLC是一款开源的多媒体播放器&#xff0c;它支持大量的视频和音频格式&#xff0c;并且具有强大的脚本和编程接口。虽然VLC本身并没有内置的编程语言&#xff0c;但你可以通过其命令行接口或Lua脚本来实现自动化播放视频的功能。 以下是一个简单的示例&#xff0c;展示如何使用…