如何用:: FileRotate替换Log :: Dispatch :: File? [英] How to replace Log::Dispatch::File with ::FileRotate?

查看:57
本文介绍了如何用:: FileRotate替换Log :: Dispatch :: File?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了使用 Log :: Dispatch :: File .这将建立一个 $ log 对象,您将其称为 $ log-> info('You are here').整个应用程序中有数千个对此对象的调用.

I've inherited a large app that's using Log::Dispatch::File. This sets up a $log object, which you call like $log->info('You are here'). There are thousands of calls to this object throughout this app.

我们需要旋转日志文件,因此我开始使用日志::Dispatch :: FileRotate .尽管在其文档中将其描述为基本上是Log :: Dispatch ::带有附加内容的文件包装器",但FileRotate却设置了一个 $ file 对象,并且您通过调用 $ file来记录内容-> log(level =>'info',message =>'You are here'); .这显然与我现有的应用程序不兼容.

We need to rotate the log files, so I started to play around with Log::Dispatch::FileRotate. Despite being described in its docs as "basically a Log::Dispatch::File wrapper with additions", FileRotate instead sets up a $file object, and you log things by calling $file->log( level => 'info', message => 'You are here' );. This is obviously incompatible with my existing app.

是否有一些简单的方法可以从这里到达典型的$ log对象,这样我就不必重写所有这数千个调用?

Is there some easy way to get from here to a typical $log object, so that I don't have to rewrite all of these thousands of calls?

推荐答案

Log :: Dispatch :: File不提供-> info 方法.您实际上是在创建和使用Log :: Dispatch对象.是的,确实创建了Log :: Dispatch :: File对象,但是您没有直接使用它.您正在使用Log :: Dispatch对象,并且您应该继续这样做!

Log::Dispatch::File does not provide an ->info method. You are actually creating and using a Log::Dispatch object. Yes, a Log::Dispatch::File object does get created, but you aren't using it directly. You are using a Log::Dispatch object, and you should continue to do so!

您可能正在使用类似以下的内容:

You might be using something like the following:

my $log = Log::Dispatch->new(
    outputs => [
        [ 'File', min_level => 'debug', filename => 'logfile' ],
    ],
);

如果是,则将其替换为以下内容:

If so, replace it with the following:

my $log = Log::Dispatch->new(
    outputs => [
        [ 'FileRotate', min_level => 'debug', filename => 'logfile' ],
    ],
);

要传递给L :: D :: FR的任何其他参数( size max 等)都可以放入数组中.

Any additional parameters you want to pass to L::D::FR (size, max, etc) can be put in the array.

您可能正在使用类似以下的内容:

You might be using something like the following:

my $log = Log::Dispatch->new();
$log->add(
    Log::Dispatch::File->new(
        name      => 'file1',
        min_level => 'debug',
        filename  => 'logfile'
    )
);

如果是,则将其替换为以下内容:

If so, replace it with the following:

my $log = Log::Dispatch->new();
$log->add(
    Log::Dispatch::FileRotate->new(
        name      => 'file1',
        min_level => 'debug',
        filename  => 'logfile'
    )
);

这篇关于如何用:: FileRotate替换Log :: Dispatch :: File?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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