Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
MetaGer
Commits
a5c9f33e
Commit
a5c9f33e
authored
Mar 04, 2020
by
Dominik Hebeler
Browse files
added central log writer
parent
f255d654
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/Console/Commands/AppendLogs.php
0 → 100644
View file @
a5c9f33e
<?php
namespace
App\Console\Commands
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\Redis
;
use
Log
;
class
AppendLogs
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'logs:gather'
;
const
LOGKEY
=
"metager.logs"
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Retrieves all Log Entries from Redis and writes them to file'
;
/**
* Create a new command instance.
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Execute the console command.
*
* @return mixed
*/
public
function
handle
()
{
$redis
=
Redis
::
connection
(
'cache'
);
$elements
=
[];
$reply
=
$redis
->
pipeline
(
function
(
$pipe
)
use
(
$elements
)
{
$pipe
->
lrange
(
\
App\Console\Commands\AppendLogs
::
LOGKEY
,
0
,
-
1
);
$pipe
->
del
(
\
App\Console\Commands\AppendLogs
::
LOGKEY
);
});
$elements
=
$reply
[
0
];
if
(
!
is_array
(
$elements
)
||
sizeof
(
$elements
)
<=
0
)
{
return
;
}
if
(
file_put_contents
(
\
App\MetaGer
::
getMGLogFile
(),
implode
(
PHP_EOL
,
$elements
)
.
PHP_EOL
,
FILE_APPEND
)
===
false
)
{
Log
::
error
(
"Konnte Log Zeile(n) nicht schreiben"
);
$redis
->
lpush
(
array_reverse
(
$elements
));
}
else
{
Log
::
info
(
"Added "
.
sizeof
(
$elements
)
.
" lines to todays log!"
);
}
}
}
app/Console/Kernel.php
View file @
a5c9f33e
...
...
@@ -27,6 +27,7 @@ class Kernel extends ConsoleKernel
{
$schedule
->
command
(
'requests:gather'
)
->
everyFifteenMinutes
();
$schedule
->
command
(
'requests:useragents'
)
->
everyFiveMinutes
();
$schedule
->
command
(
'logs:gather'
)
->
everyMinute
();
$schedule
->
call
(
function
()
{
DB
::
table
(
'monthlyrequests'
)
->
truncate
();
...
...
app/MetaGer.php
View file @
a5c9f33e
...
...
@@ -1392,10 +1392,12 @@ class MetaGer
$logEntry
=
preg_replace
(
"/
\n
+/"
,
" "
,
$logEntry
);
$logpath
=
\
App\MetaGer
::
getMGLogFile
();
if
(
file_put_contents
(
$logpath
,
$logEntry
.
PHP_EOL
,
FILE_APPEND
)
===
false
)
{
Log
::
error
(
"Konnte Log Zeile nicht schreiben"
);
}
Redis
::
connection
(
'cache'
)
->
rpush
(
\
App\Console\Commands\AppendLogs
::
LOGKEY
,
$logEntry
);
/*$logpath = \App\MetaGer::getMGLogFile();
if (file_put_contents($logpath, $logEntry . PHP_EOL, FILE_APPEND) === false) {
Log::error("Konnte Log Zeile nicht schreiben");
}*/
}
catch
(
\
Exception
$e
)
{
Log
::
error
(
$e
->
getMessage
());
return
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment