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
30ee0d6e
Commit
30ee0d6e
authored
Dec 08, 2020
by
Dominik Hebeler
Browse files
added logging for advertisement
parent
db05fa3e
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/Console/Commands/AppendLogs.php
View file @
30ee0d6e
...
...
@@ -16,6 +16,7 @@ class AppendLogs extends Command
*/
protected
$signature
=
'logs:gather'
;
const
LOGKEY
=
"metager.logs"
;
const
LOGKEYTAZ
=
"metager.tazlogs"
;
/**
* The console command description.
...
...
@@ -41,8 +42,14 @@ class AppendLogs extends Command
*/
public
function
handle
()
{
$redis
=
null
;
$this
->
handleMGLogs
();
$this
->
handleTazLogs
();
}
private
function
handleMGLogs
()
{
$redis
=
null
;
if
(
env
(
"REDIS_CACHE_DRIVER"
,
"redis"
)
===
"redis"
)
{
$redis
=
Redis
::
connection
(
'cache'
);
}
elseif
(
env
(
"REDIS_CACHE_DRIVER"
,
"redis"
)
===
"redis-sentinel"
)
{
...
...
@@ -64,9 +71,50 @@ class AppendLogs extends Command
}
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
));
$redis
->
lpush
(
\
App\Console\Commands\AppendLogs
::
LOGKEY
,
array_reverse
(
$elements
));
}
else
{
Log
::
info
(
"Added "
.
sizeof
(
$elements
)
.
" lines to todays log!"
);
}
}
private
function
handleTazLogs
()
{
$redis
=
null
;
if
(
env
(
"REDIS_CACHE_DRIVER"
,
"redis"
)
===
"redis"
)
{
$redis
=
Redis
::
connection
(
'cache'
);
}
elseif
(
env
(
"REDIS_CACHE_DRIVER"
,
"redis"
)
===
"redis-sentinel"
)
{
$redis
=
RedisSentinel
::
connection
(
'cache'
);
}
if
(
$redis
===
null
)
{
Log
::
error
(
"No valid Redis Connection specified"
);
return
;
}
$elements
=
[];
$reply
=
$redis
->
pipeline
(
function
(
$pipe
)
use
(
$elements
)
{
$pipe
->
lrange
(
\
App\Console\Commands\AppendLogs
::
LOGKEYTAZ
,
0
,
-
1
);
$pipe
->
del
(
\
App\Console\Commands\AppendLogs
::
LOGKEYTAZ
);
});
$elements
=
$reply
[
0
];
if
(
!
is_array
(
$elements
)
||
sizeof
(
$elements
)
<=
0
)
{
return
;
}
if
(
file_put_contents
(
\
App\Console\Commands\AppendLogs
::
getTazLogFile
(),
implode
(
PHP_EOL
,
$elements
)
.
PHP_EOL
,
FILE_APPEND
)
===
false
)
{
Log
::
error
(
"Konnte Log Zeile(n) nicht schreiben"
);
$redis
->
lpush
(
\
App\Console\Commands\AppendLogs
::
LOGKEYTAZ
,
array_reverse
(
$elements
));
}
else
{
Log
::
info
(
"Added "
.
sizeof
(
$elements
)
.
" lines to todays TAZ log!"
);
}
}
public
static
function
getTazLogFile
()
{
$logpath
=
storage_path
(
"logs/metager/taz/"
.
date
(
"Y"
)
.
"/"
.
date
(
"m"
)
.
"/"
);
if
(
!
file_exists
(
$logpath
))
{
mkdir
(
$logpath
,
0777
,
true
);
}
$logpath
.
=
date
(
"d"
)
.
".log"
;
return
$logpath
;
}
}
app/Http/Controllers/StartpageController.php
View file @
30ee0d6e
...
...
@@ -7,6 +7,7 @@ use Cookie;
use
Illuminate\Http\Request
;
use
Jenssegers\Agent\Agent
;
use
LaravelLocalization
;
use
Illuminate\Support\Facades\Redis
;
use
Response
;
class
StartpageController
extends
Controller
...
...
@@ -43,6 +44,21 @@ class StartpageController extends Controller
$lang
=
'all'
;
}
/**
* Logging Requests from Taz advertisement
*/
if
(
$request
->
filled
(
"key"
)
&&
$request
->
input
(
"key"
,
""
)
===
"taz"
)
{
$logEntry
=
date
(
"H:i:s"
);
$referer
=
request
()
->
headers
->
get
(
'referer'
);
$logEntry
.
=
" ref=
$referer
"
;
if
(
env
(
"REDIS_CACHE_DRIVER"
,
"redis"
)
===
"redis"
)
{
Redis
::
connection
(
'cache'
)
->
rpush
(
\
App\Console\Commands\AppendLogs
::
LOGKEYTAZ
,
$logEntry
);
}
elseif
(
env
(
"REDIS_CACHE_DRIVER"
,
"redis"
)
===
"redis-sentinel"
)
{
RedisSentinel
::
connection
(
'cache'
)
->
rpush
(
\
App\Console\Commands\AppendLogs
::
LOGKEYTAZ
,
$logEntry
);
}
}
return
view
(
'index'
)
->
with
(
'title'
,
trans
(
'titles.index'
))
->
with
(
'homeIcon'
)
...
...
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