PHP의 Laravel에서 laravel.log를 지우려면 어떻게 해야 합니까?
저는 일반적으로 Laravel과 PHP를 처음 접하는데, 제 errorLog를 지우려고 합니다.현재 사용 중인 오류 로그는 /app/storage/logs에 있는 Laravel의 laravel.log 파일입니다.
laravel.log 파일을 쉽게 지울 수 있는 방법이 있습니까?삭제해도 안전하고 필요할 때 다시 만들 수 있습니까?
저는 우분투의 최신 버전을 사용하고 있습니다.감사합니다!
빈 문자열을 에코하면 다음과 같이 작동합니다.
echo "" > storage/logs/laravel.log
가장 효율적인 방법은truncate
0의 크기까지:
truncate -s 0 /app/storage/logs/laravel.log
여기 재사용 가능한 것이 있습니다.artisan
시간과 노력을 절약할 수 있는 명령어 :)
Artisan::command('logs:clear', function() {
exec('rm -f ' . storage_path('logs/*.log'));
exec('rm -f ' . base_path('*.log'));
$this->comment('Logs have been cleared!');
})->describe('Clear log files');
이거 집어넣어요?routes/console.php
그럼 그냥 뛰어요php artisan logs:clear
업데이트:
- 추가된
base_path('*.log')
위해서npm
,composer
루트 디렉토리에 로그를 저장합니다. - 추가된
-f
로.rm
억제하는 기능을 합니다.No such file or directory
메세지.
로그를 지우려는 곳에 이 행을 추가하기만 하면 됩니다.file_put_contents(storage_path('logs/laravel.log'),'');
사용자 지정 장인 명령을 만들 수도 있습니다.
먼저 명령어를 실행합니다.php artisan make:command Log/ClearLogFile
사용자 지정 명령 파일을 만듭니다.
그런 다음 파일을 엽니다.Console/Commands/Log/ClearLogFile.php
(Laravel 버전에 따라 다르며, 현재 5.5 버전을 사용하고 있습니다.)
그 다음에는 사용자 지정 명령 코드를 정의해야 합니다.
// Define command name
protected $signature = 'log:clear';
// Add description to your command
protected $description = 'Clear Laravel log';
// Create your own custom command
public function handle(){
exec('echo "" > ' . storage_path('logs/laravel.log'));
$this->info('Logs have been cleared');
}
그러면 다른 php artisan 명령어와 마찬가지로 실행만 하면 됩니다.
php artisan log:clear
@emotality 답변 감사합니다.
저에게 가장 쉬운 방법은 vim을 사용하는 것입니다.
$ vim laravel.log 그런 다음 ggdG를 입력합니다. 그런 다음 :wq 저장하고 종료합니다.
참고: gg - 커서를 첫 줄로 이동합니다.
d - 삭제
G - 파일 끝까지
이것이 나에게 효과가 있었습니다.
echo "" > storage/logs/laravel.log
Laravel 디렉토리에서:
rm storage/logs/laravel-*.log
이 솔루션이 윈도우에 적합하다는 것을 알았습니다.
Artisan::command('logs:clear', function() {
array_map('unlink', array_filter((array) glob(storage_path('logs/*.log'))));
$this->comment('Logs have been cleared!');
})->describe('Clear log files');
달려.php artisan logs:clear
라라벨 5의 경우는.
truncate -s 0 storage/logs/laravel.log
다음을 수행할 수도 있습니다.: > storage/logs/laravel.log
SQL 쿼리 수신기를 실행할 때 보통 컨트롤러 메서드에 다음 줄을 붙입니다.
exec("truncate -s 0 " . storage_path('/logs/laravel.log'));
다른 것을 사용하는 경우monolog
로그 파일의 이름을 조정할 수 있는 채널 설정입니다.
로그를 지우는 매우 쉬운 방법이 있습니다.php artisan log:clear
Laravel More Command Package를 사용하는 명령입니다.
Laravel 추가 명령 첫 번째 설치
composer require theanik/laravel-more-command --dev
그 다음 실행
php artisan log:clear
위에서 /storage/logs/ 디렉토리에서 이전 로그 데이터를 모두 삭제합니다.
감사해요.
@emotality 응답을 완료합니다.이것은 윈도우의 코드입니다.
Artisan::command('logs:clear', function() {
exec('echo "" > ' . storage_path('logs/laravel.log'));
$this->info('Logs have been cleared');
})->describe('Clear log files');
드랍인routes/console.php
그리고 이렇게 사용합니다.
php artisan logs:clear
팅커로 이동php artisan tinker
그다음달리기
use Illuminate\Support\Facades\Redis;
Redis::resolve('horizon')->flushall();
예상 응답:
> Redis::resolve('horizon')->flushall();
= true
>
언급URL : https://stackoverflow.com/questions/28127495/in-phps-laravel-how-do-i-clear-laravel-log
'programing' 카테고리의 다른 글
Ajax가 빈 값을 전달하지만 ASP에서 컨트롤러가 null이 됩니다.NET MVC (0) | 2023.10.01 |
---|---|
공개 동의어를 올바르게 만드는 방법 (0) | 2023.10.01 |
HANDLES에 fdopen과 동등한 윈도우가 있습니까? (0) | 2023.10.01 |
조건부 실행 (&& 및 ||) (0) | 2023.10.01 |
Pyspark: 여러 배열 열을 행으로 나눕니다. (0) | 2023.10.01 |