使用SimpleLogger的SLF4J:是否可以登录到文件AND System.out? [英] SLF4J with SimpleLogger: Is it possible to log to a file AND System.out?

查看:135
本文介绍了使用SimpleLogger的SLF4J:是否可以登录到文件AND System.out?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为SLF4J 1.7.5使用SimpleLogger绑定.根据 docs ,我可以使用<我的simplelogger.properties文件中的b> org.slf4j.simpleLogger.logFile 属性,用于指定日志文件或System.out或System.err.

I'm using the SimpleLogger binding for SLF4J 1.7.5. As per the docs I can use the org.slf4j.simpleLogger.logFile property in my simplelogger.properties file to specify a log file OR System.out OR System.err.

但是我想将日志消息发送到BOTH System.out和一个日志文件.有谁知道如何使用SimpleLogger实现这一目标? (我使用的是Windows,因此不能仅使用tail -f跟随控制台窗口中的日志文件;也不想获得在Windows中模拟"tail -f"的第三方实用程序.)

However I want to send log messages to BOTH System.out AND a log file. Does anyone know how to achieve this using SimpleLogger please? (I'm using Windows so cannot use tail -f simply to follow the log file in a console window; nor do I want to get a third party utility which emulates 'tail -f' in Windows.)

推荐答案

简短回答

您无法使用SimipleLogger做到这一点.

更多答案

放弃SimpleLogger并继续进行其他操作.您可以选择:

Short Answer

You can't do that with SimipleLogger.

More Answer

Give up on SimpleLogger and move on to something else. You have options:

  1. 获取logback(logback-classic.jar和logback-core.jar)而不是使用slf4j-simple-1.x.x.jar.使用logback,您可以定义两个追加程序;一个用于文件输出,另一个用于控制台(也称为System.out)输出.

  1. Instead of using slf4j-simple-1.x.x.jar get logback (logback-classic.jar and logback-core.jar). With logback you can define two appenders; one for the file output and one for console (also-known-as System.out) output.

获取xxx(替换slf4j支持的任何日志记录系统)和blah blah blah(与1 obove中的操作相同),而不是使用slf4j-simple.1.x.x.jar.

Instead of using slf4j-simple.1.x.x.jar get xxx (substitute any logging system supported by slf4j) and blah blah blah (do the same as in 1 obove).

SLF4j是开源的;派生您自己的记录器(简称为TeeLogger),该记录器记录到System.out和文件中.

SLF4j is open source; derive your own logger (lets call it TeeLogger) that logs to System.out and a file.

创建一个位于SLF4j前面的日志记录类(在您的应用程序中).先让它记录一个Logger和一个消息,然后再将消息写入System.out和Logger.

Create a logging class that that sits in front of SLF4j (in your application). Have it take a Logger and a messasge then have it write the message to System.out and the Logger.

我还没想过的东西.

这是上面#4的(超级简单)示例:

Here is a (super simplistic) example of #4 above:

import org.slf4j.Logger;

public class LoggyLoo
{
    public static void logZoreInfo(
        final Logger logger,
        final String message)
    {
        System.out.println(message);
        logger.info(message);
    }
}

这篇关于使用SimpleLogger的SLF4J:是否可以登录到文件AND System.out?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆