如何禁用Laravel 5日志文件?

时间:2022-10-18 21:37:54

My Laravel 5 website is working in a shared host with 1 GB disk space. But now I have about 100 MB log file. How I can disable log file in Laravel 5 ?

我的Laravel 5网站正在使用1 GB磁盘空间的共享主机。但现在我有大约100 MB的日志文件。如何在Laravel 5中禁用日志文件?

5 个解决方案

#1


10  

If your log is very large then either you are logging a lot or your application is throwing a lot of errors. You should first examine the log and see if you can reduce data being written.

如果您的日志非常大,那么您要么记录很多,要么您的应用程序会丢失很多错误。您应首先检查日志,看看是否可以减少正在写入的数据。

You can also switch to daily logging and then have a job to delete old log files.

您还可以切换到每日日志记录,然后找到删除旧日志文件的作业。

The next thing to do would be to update your logging configuration to daily instead of the default single in config/app.php

接下来要做的是将日志记录配置更新为每日而不是config / app.php中的默认单一

Laravel will handle rotating the file daily and deleting old log files after 5 days, or the value of the app.max_log_files if you need more kept.

Laravel将处理每天旋转文件并在5天后删除旧日志文件,或者如果需要更多保留,则删除app.max_log_files的值。

#2


14  

In order to completely disable logging you'll need to overwrite the default log handlers that are set by Laravel. You can easily do this with

为了完全禁用日志记录,您需要覆盖Laravel设置的默认日志处理程序。你可以轻松地做到这一点

$nullLogger = new NullHandler();
\Log::getMonolog()->setHandlers(array($nullLogger));

You need to call as early as possible, before request is processed, e.g. you could do that in your bootstrap/app.php:

您需要在处理请求之前尽早致电,例如你可以在你的bootstrap / app.php中做到这一点:

$app->configureMonologUsing(function($monolog) {
  $nullLogger = new \Monolog\Handler\NullHandler();
  $monolog->setHandlers(array($nullLogger));
});

return $app;

#3


1  

Maximum Daily Log Files

When using the daily log mode, Laravel will only retain five days of log files by default. If you want to adjust the number of retained files, you may add a log_max_files configuration value to your app configuration file:

使用每日日志模式时,Laravel默认只保留五天的日志文件。如果要调整保留文件的数量,可以将log_max_files配置值添加到应用程序配置文件中:

config >> app.php

'log_max_files' => 30

For more : https://laravel.com/docs/5.5/errors

更多信息:https://laravel.com/docs/5.5/errors

#4


-2  

You May disable the writing action Log:: is called by commenting the follow line:

您可以通过注释以下行来禁用写入操作Log ::

Log::useFiles(storage_path().'/logs/laravel.log');

in start/global.php

在start / global.php中

But first, you should find out why your log file is that big? Second, having some kind of archive function to your file will help as well. Maybe twice a day.

但首先,你应该找出你的日志文件那么大的原因?其次,为您的文件提供某种存档功能也会有所帮助。也许一天两次。

Hope it helps. Good Luck!

希望能帮助到你。祝你好运!

#5


-4  

Yes definitively you need to edit core laravel file in order not to save log file ..

确切地说,您需要编辑核心laravel文件以便不保存日志文件。

go to vendor->laravel->framework->src->Illuminate->Log->Writer.php and then comment out all the code within function __call like below.

转到vendor-> laravel-> framework-> src-> Illuminate-> Log-> Writer.php然后注释掉函数__call中的所有代码,如下所示。

public function __call($method, $parameters)
{
    // if (in_array($method, $this->levels))
    // {
    //  call_user_func_array(array($this, 'fireLogEvent'), array_merge(array($method), $parameters));

    //  $method = 'add'.ucfirst($method);

    //  return $this->callMonolog($method, $parameters);
    // }

    // throw new \BadMethodCallException("Method [$method] does not exist.");
}

You log will never be save.

您的日志永远不会保存。

#1


10  

If your log is very large then either you are logging a lot or your application is throwing a lot of errors. You should first examine the log and see if you can reduce data being written.

如果您的日志非常大,那么您要么记录很多,要么您的应用程序会丢失很多错误。您应首先检查日志,看看是否可以减少正在写入的数据。

You can also switch to daily logging and then have a job to delete old log files.

您还可以切换到每日日志记录,然后找到删除旧日志文件的作业。

The next thing to do would be to update your logging configuration to daily instead of the default single in config/app.php

接下来要做的是将日志记录配置更新为每日而不是config / app.php中的默认单一

Laravel will handle rotating the file daily and deleting old log files after 5 days, or the value of the app.max_log_files if you need more kept.

Laravel将处理每天旋转文件并在5天后删除旧日志文件,或者如果需要更多保留,则删除app.max_log_files的值。

#2


14  

In order to completely disable logging you'll need to overwrite the default log handlers that are set by Laravel. You can easily do this with

为了完全禁用日志记录,您需要覆盖Laravel设置的默认日志处理程序。你可以轻松地做到这一点

$nullLogger = new NullHandler();
\Log::getMonolog()->setHandlers(array($nullLogger));

You need to call as early as possible, before request is processed, e.g. you could do that in your bootstrap/app.php:

您需要在处理请求之前尽早致电,例如你可以在你的bootstrap / app.php中做到这一点:

$app->configureMonologUsing(function($monolog) {
  $nullLogger = new \Monolog\Handler\NullHandler();
  $monolog->setHandlers(array($nullLogger));
});

return $app;

#3


1  

Maximum Daily Log Files

When using the daily log mode, Laravel will only retain five days of log files by default. If you want to adjust the number of retained files, you may add a log_max_files configuration value to your app configuration file:

使用每日日志模式时,Laravel默认只保留五天的日志文件。如果要调整保留文件的数量,可以将log_max_files配置值添加到应用程序配置文件中:

config >> app.php

'log_max_files' => 30

For more : https://laravel.com/docs/5.5/errors

更多信息:https://laravel.com/docs/5.5/errors

#4


-2  

You May disable the writing action Log:: is called by commenting the follow line:

您可以通过注释以下行来禁用写入操作Log ::

Log::useFiles(storage_path().'/logs/laravel.log');

in start/global.php

在start / global.php中

But first, you should find out why your log file is that big? Second, having some kind of archive function to your file will help as well. Maybe twice a day.

但首先,你应该找出你的日志文件那么大的原因?其次,为您的文件提供某种存档功能也会有所帮助。也许一天两次。

Hope it helps. Good Luck!

希望能帮助到你。祝你好运!

#5


-4  

Yes definitively you need to edit core laravel file in order not to save log file ..

确切地说,您需要编辑核心laravel文件以便不保存日志文件。

go to vendor->laravel->framework->src->Illuminate->Log->Writer.php and then comment out all the code within function __call like below.

转到vendor-> laravel-> framework-> src-> Illuminate-> Log-> Writer.php然后注释掉函数__call中的所有代码,如下所示。

public function __call($method, $parameters)
{
    // if (in_array($method, $this->levels))
    // {
    //  call_user_func_array(array($this, 'fireLogEvent'), array_merge(array($method), $parameters));

    //  $method = 'add'.ucfirst($method);

    //  return $this->callMonolog($method, $parameters);
    // }

    // throw new \BadMethodCallException("Method [$method] does not exist.");
}

You log will never be save.

您的日志永远不会保存。