log4j Syslogd 打印字符 '^I'而不是选项卡

发布于 2024-11-10 04:23:45 字数 1410 浏览 0 评论 0原文

我正在研究 syslogd,它打印一条消息(包含制表符、空格等...)。当我观察 /var/log/ 目录中的 syslogd 文件时,消息是没有任何选项卡。相反,它正在打印 ^I

ubuntu 10.04 LTSsysklogd 上运行此程序。

import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.net.SyslogAppender;

public class syslogPrinter {

    private static int sysLogFacility = SyslogAppender.LOG_LOCAL3;
    private static String syslogHost = "localhost";
    private static String layoutPattern = "%m%n";
    public static Logger log2static = Logger.getLogger(syslogPrinter.class);

    public static void main(String[] args) {

        log2static.setLevel(Level.INFO);
        PatternLayout layout = new PatternLayout(layoutPattern);

        Appender syslogdAppender = new SyslogAppender(layout, syslogHost, sysLogFacility);

        log2static.addAppender(syslogdAppender);

        String str2 = "this is a tab: ";
        str2 = str2.concat("\t");
        str2 = str2.concat("    after space");
        log2static.error(str2);
    }

}

输出即将到来

这是一个制表符:^I 位于空格之后

预期输出为

这是一个制表符:空格后(制表符 空间应该来)

请告诉我如何打印消息中的选项卡而不是 ^I.......

我需要配置 syslogd.conf 文件吗?

I am working on syslogd which prints a message(contains tabs,spaces etc...).When i observe the syslogd file in /var/log/ directory,message is not having any tabs.Instead it is printing ^I.

Running this program on ubuntu 10.04 LTS and sysklogd.

import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.net.SyslogAppender;

public class syslogPrinter {

    private static int sysLogFacility = SyslogAppender.LOG_LOCAL3;
    private static String syslogHost = "localhost";
    private static String layoutPattern = "%m%n";
    public static Logger log2static = Logger.getLogger(syslogPrinter.class);

    public static void main(String[] args) {

        log2static.setLevel(Level.INFO);
        PatternLayout layout = new PatternLayout(layoutPattern);

        Appender syslogdAppender = new SyslogAppender(layout, syslogHost, sysLogFacility);

        log2static.addAppender(syslogdAppender);

        String str2 = "this is a tab: ";
        str2 = str2.concat("\t");
        str2 = str2.concat("    after space");
        log2static.error(str2);
    }

}

Output is coming like

this is a tab: ^I after space

expected out put is

this is a tab: after space(tab
space should come)

Please tell me how to print tab in the message instead of ^I.......

Do i need to configure syslogd.conf file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅唱ヾ落雨殇 2024-11-17 04:23:45

您是否使用 Gnome 日志文件查看器或 tail 来查看系统日志?如果没有,您使用哪个工具/编辑器来查看该文件? Ctrl+I 是某些终端中水平制表符的有效控制序列。

我怀疑您使用的实用程序无法将 Ctrl+I 识别为有效的转义序列,并且您最好使用用于查看系统日志文件的查看器。

Are you using the Gnome Logfile viewer or tail to view syslog? If not, which tool/editor are you using to view the file? Ctrl+I is a valid control sequence for the horizontal tab character in certain terminals.

I suspect that you are using a utility that does not recognize Ctrl+I as a valid escape sequence, and you would be better off using a viewer that is meant to view syslog files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文