linux 下生成日期格式,在linux日期生成log4j时间戳格式(Generate log4j timestamp format in linux date)...

在linux日期生成log4j时间戳格式(Generate log4j timestamp format in linux date)

我想使用linux日期模拟log4j中用于时间戳的格式(只是一些快速脚本)

在log4j上,格式定义为%d{dd MMM yyyy HH:mm:ss,SSS}这将转换为如下行:

2016-03-10 07:01:09,778

2016-03-10 07:01:09,784

这可以在日期完成吗? 我越接近使用

date +"%Y-%m-%d %H:%M:%S,%N"

但这仍然有9位而不是3位,任何想法? 我不喜欢使用sed / cut等,但如果别无选择那就没关系了。

I want to mimic the format used in log4j for timestamps using the linux date (just some quick scripting)

On log4j the format is defined as %d{dd MMM yyyy HH:mm:ss,SSS} That would translate into lines like:

2016-03-10 07:01:09,778

2016-03-10 07:01:09,784

Can this be accomplished in date? The closer I got was using

date +"%Y-%m-%d %H:%M:%S,%N"

But this still has 9 digits instead of 3, any ideas? I'd prefer not using sed/cut,etc, but if there's no alternative it'd be fine.

原文:https://stackoverflow.com/questions/35939181

更新时间:2019-07-01 01:20

最满意答案

那个%N给你的是纳秒数,(每秒10亿)因此九位数,而GNU date没有毫秒选项。

谢天谢地,我们可以像这样指定字段宽度

date +"%Y-%m-%d %H:%M:%S,%3N"

将亿万分之一变为千分之一。

M.

That %N is giving you the number of nanoseconds, (one billion per second) hence the nine digits, and GNU date doesn't have a milliseconds option.

Thankfully we can specify the field width like this

date +"%Y-%m-%d %H:%M:%S,%3N"

To turn billionths into thousandths.

M.

2016-03-14

相关问答

TimeBasedRollingPolicy使用以下依赖项:

ch.qos.logback

logback-core

1.2.2

请参考下面的链接以供参考: https : //examples.javacodegeeks.com/enterprise-java/logback/logback-

...

那个%N给你的是纳秒数,(每秒10亿)因此九位数,而GNU date没有毫秒选项。 谢天谢地,我们可以像这样指定字段宽度 date +"%Y-%m-%d %H:%M:%S,%3N"

将亿万分之一变为千分之一。 M. That %N is giving you the number of nanoseconds, (one billion per second) hence the nine digits, and GNU date doesn't have a milliseconds opti

...

在PatternLayout中使用%d。 另外%d可以采用格式模式,如%d {dd MMM yyyy HH:mm:ss,SSS},您可以选择并选择所需的元素。 当格式模式被省略时,日期将以ISO8601格式。 Use %d in your PatternLayout. Also %d can take a format pattern as in %d{dd MMM yyyy HH:mm:ss,SSS} you can pick and choose the elements that you w

...

我的回答仅适用于log4j 1.2。 日志记录包含在将消息写入磁盘时调用logger.log(..)的时间。 为了更好地理解,请检查log4j的源代码。 所有logger.log(..)方法都创建一个新的LogRecord实例。 LogRecord的构造函数检索时间戳,稍后将其用于将时间戳写入磁盘。 My answer is valid for log4j 1.2 only. The logging contains the time when logger.log(..) is called n

...

是的,它确实。 只要等到午夜,就会创建一个新文件。 该日的文件仍将是application.log Yes it does. Just wait till midnight and a new file will be created. The day's file will remain application.log

找到我的答案。 此应用程序部署在Servicemix容器中。 显然在servicemix的安装目录中我找到了这个配置文件。 “/usr/local/servicemix/etc/org.ops4j.pax.logging.cfg”。 在这个文件中,有一个SiftingAppender使用%d [ABSOLUTE]作为转换模式。 所以基本上在servicemix下部署的每个bundle都将使用这个“siftingappender”属性。 我刚刚从这个配置文件中删除[ABSOLUTE]并开始在我的日志

...

如果你有一个完全匹配你想要分割输出,根据另一个问题,你可以使用sed只输出该时间戳之后和之后的行。 找到要中断的完全匹配可能意味着逐渐使你的时间戳更加宽松,例如删除最后一个字符,直到你得到匹配/匹配,然后解析那些匹配以决定哪个是第一个匹配。 如果你想在bash中这样做,请考虑这个问题 ; 专门将日期转换为unix时间戳,然后比较结果值。 其余的应该是直截了当的; 同样在Java中,提取日期并比较它们不应该太具有挑战性。 除非您拥有学习经验的带宽,否则请使用您更熟悉的语言。 If you have

...

我不知道它在以后的版本中是怎么回事,在JBoss 4中有一个jboss-log4j.xml,我会说这是默认使用的。 你可以查看那个文件.. I needed to put log4 props in the src/resources folder - its a maven issue as it appears it has a standard dir it checks for log4j props

编辑 :根据我的建议,根据我的建议,找到正在为文件添加时间戳的内容,这个答案现在已经多余了。 但是我会把它放在这里因为它可能对某人有所帮助。 首先,指示Git忽略文件中的各个行是不可能的。 我的第一个建议是找到为文件添加时间戳的内容并将其停止。 唯一可以帮助你在Git中解决的问题就是从Gits工作树中删除文件。 git update-index --skip-worktree 这将指示Git不应提交此文件的更改版本,因此不会将其包含在其工作树中,但仍会将跟踪的副本保留在存储库中。 在

...

您可以通过使用< 和>通过> 在基于html或xml的上下文中。 You can escape < by using < and > by > in html or xml based contexts.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值