log4j Syslogd 打印字符 '^I'而不是选项卡
我正在研究 syslogd,它打印一条消息(包含制表符、空格等...)。当我观察 /var/log/ 目录中的 syslogd 文件时,消息是没有任何选项卡。相反,它正在打印 ^I
。
在 ubuntu 10.04 LTS
和 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);
}
}
输出即将到来
这是一个制表符:^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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否使用 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.