Skip to content

Commit

Permalink
updated building event logging context
Browse files Browse the repository at this point in the history
  • Loading branch information
MelonSmasher committed Dec 13, 2017
1 parent 3639f27 commit 3f7fd32
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 35 deletions.
27 changes: 23 additions & 4 deletions app/Events/Api/Building/AssignedCampus.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,36 @@ public function __construct(Building $building, Campus $campus)
{
parent::__construct();

$info = [
$logMessage = 'assigned building to campus - ';
$logContext = [
'action' => 'assignment',
'model' => 'building',
'pivot' => 'campus',
'building_id' => $building->id,
'building_code' => $building->code,
'building_label' => $building->label,
'building_created' => $building->created_at,
'building_updated' => $building->updated_at,
'campus_id' => $campus->id,
'campus_code' => $campus->code,
'campus_label' => $campus->label
'campus_label' => $campus->label,
'requester_id' => 0,
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'request_proxy_ip' => getRequestIP(true),
'request_method' => \Request::getMethod(),
'request_url' => \Request::fullUrl(),
'request_uri' => \Request::getRequestUri(),
'request_scheme' => \Request::getScheme(),
'request_host' => \Request::getHost()
];

Log::info('Building assigned Campus:', $info);

if ($user = auth()->user()) {

$logMessage = auth()->user()->name . ' ' . $logMessage;
$logContext['requester_id'] = auth()->user()->id;
$logContext['requester_name'] = auth()->user()->name;

if (Settings::get('broadcast-events', false)) {

$data_to_secure = json_encode([
Expand Down Expand Up @@ -67,5 +84,7 @@ public function __construct(Building $building, Campus $campus)
'bg-olive'
);
}

Log::info($logMessage, $logContext);
}
}
31 changes: 25 additions & 6 deletions app/Events/Api/Building/BuildingCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,34 @@ class BuildingCreated extends ApiRequestEvent
*/
public function __construct(Building $building)
{

parent::__construct();

Log::info('Building Created:', [
'id' => $building->id,
'code' => $building->code,
'label' => $building->label
]);
$logMessage = 'created building - ';
$logContext = [
'action' => 'create',
'model' => 'building',
'building_id' => $building->id,
'building_identifier' => $building->code,
'building_username' => $building->label,
'building_created' => $building->created_at,
'building_updated' => $building->updated_at,
'requester_id' => 0,
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'request_proxy_ip' => getRequestIP(true),
'request_method' => \Request::getMethod(),
'request_url' => \Request::fullUrl(),
'request_uri' => \Request::getRequestUri(),
'request_scheme' => \Request::getScheme(),
'request_host' => \Request::getHost()
];

if ($user = auth()->user()) {

$logMessage = auth()->user()->name . ' ' . $logMessage;
$logContext['requester_id'] = auth()->user()->id;
$logContext['requester_name'] = auth()->user()->name;

if (Settings::get('broadcast-events', false)) {

$building->campus;
Expand Down Expand Up @@ -58,5 +75,7 @@ public function __construct(Building $building)
'bg-green'
);
}

Log::info($logMessage, $logContext);
}
}
30 changes: 25 additions & 5 deletions app/Events/Api/Building/BuildingDestroyed.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,32 @@ public function __construct(Building $building)
{
parent::__construct();

Log::info('Building Deleted:', [
'id' => $building->id,
'code' => $building->code,
'label' => $building->label
]);
$logMessage = 'destroyed building - ';
$logContext = [
'action' => 'destroy',
'model' => 'building',
'building_id' => $building->id,
'building_identifier' => $building->code,
'building_username' => $building->label,
'building_created' => $building->created_at,
'building_updated' => $building->updated_at,
'requester_id' => 0,
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'request_proxy_ip' => getRequestIP(true),
'request_method' => \Request::getMethod(),
'request_url' => \Request::fullUrl(),
'request_uri' => \Request::getRequestUri(),
'request_scheme' => \Request::getScheme(),
'request_host' => \Request::getHost()
];

if ($user = auth()->user()) {

$logMessage = auth()->user()->name . ' ' . $logMessage;
$logContext['requester_id'] = auth()->user()->id;
$logContext['requester_name'] = auth()->user()->name;

if (Settings::get('broadcast-events', false)) {

$building->campus;
Expand Down Expand Up @@ -57,5 +75,7 @@ public function __construct(Building $building)
'bg-red'
);
}

Log::info($logMessage, $logContext);
}
}
30 changes: 25 additions & 5 deletions app/Events/Api/Building/BuildingRestored.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,32 @@ public function __construct(Building $building)
{
parent::__construct();

Log::info('Building Restored:', [
'id' => $building->id,
'code' => $building->code,
'label' => $building->label
]);
$logMessage = 'restored building - ';
$logContext = [
'action' => 'restore',
'model' => 'building',
'building_id' => $building->id,
'building_identifier' => $building->code,
'building_username' => $building->label,
'building_created' => $building->created_at,
'building_updated' => $building->updated_at,
'requester_id' => 0,
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'request_proxy_ip' => getRequestIP(true),
'request_method' => \Request::getMethod(),
'request_url' => \Request::fullUrl(),
'request_uri' => \Request::getRequestUri(),
'request_scheme' => \Request::getScheme(),
'request_host' => \Request::getHost()
];

if ($user = auth()->user()) {

$logMessage = auth()->user()->name . ' ' . $logMessage;
$logContext['requester_id'] = auth()->user()->id;
$logContext['requester_name'] = auth()->user()->name;

if (Settings::get('broadcast-events', false)) {

$building->campus;
Expand Down Expand Up @@ -56,5 +74,7 @@ public function __construct(Building $building)
'bg-lime'
);
}

Log::info($logMessage, $logContext);
}
}
30 changes: 25 additions & 5 deletions app/Events/Api/Building/BuildingUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,32 @@ public function __construct(Building $building)
{
parent::__construct();

Log::info('Building Updated:', [
'id' => $building->id,
'code' => $building->code,
'label' => $building->label
]);
$logMessage = 'updated building - ';
$logContext = [
'action' => 'update',
'model' => 'building',
'building_id' => $building->id,
'building_identifier' => $building->code,
'building_username' => $building->label,
'building_created' => $building->created_at,
'building_updated' => $building->updated_at,
'requester_id' => 0,
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'request_proxy_ip' => getRequestIP(true),
'request_method' => \Request::getMethod(),
'request_url' => \Request::fullUrl(),
'request_uri' => \Request::getRequestUri(),
'request_scheme' => \Request::getScheme(),
'request_host' => \Request::getHost()
];

if ($user = auth()->user()) {

$logMessage = auth()->user()->name . ' ' . $logMessage;
$logContext['requester_id'] = auth()->user()->id;
$logContext['requester_name'] = auth()->user()->name;

if (Settings::get('broadcast-events', false)) {

$building->campus;
Expand Down Expand Up @@ -57,5 +75,7 @@ public function __construct(Building $building)
'bg-lime'
);
}

Log::info($logMessage, $logContext);
}
}
27 changes: 24 additions & 3 deletions app/Events/Api/Building/BuildingViewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,32 @@ public function __construct(Building $building)

parent::__construct();

$user_name = 'System';
$logMessage = 'viewed building - ';
$logContext = [
'action' => 'view',
'model' => 'building',
'building_id' => $building->id,
'building_identifier' => $building->code,
'building_username' => $building->label,
'building_created' => $building->created_at,
'building_updated' => $building->updated_at,
'requester_id' => 0,
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'request_proxy_ip' => getRequestIP(true),
'request_method' => \Request::getMethod(),
'request_url' => \Request::fullUrl(),
'request_uri' => \Request::getRequestUri(),
'request_scheme' => \Request::getScheme(),
'request_host' => \Request::getHost()
];

if ($user = auth()->user()) {

$user_name = $user->name;
$logMessage = auth()->user()->name . ' ' . $logMessage;
$logContext['requester_id'] = auth()->user()->id;
$logContext['requester_name'] = auth()->user()->name;


if (Settings::get('broadcast-events', false)) {
// @todo bc view event
Expand All @@ -37,6 +58,6 @@ public function __construct(Building $building)
);
}

Log::info($user_name . ' viewed ' . $building->label . '.');
Log::info($logMessage, $logContext);
}
}
23 changes: 20 additions & 3 deletions app/Events/Api/Building/BuildingsViewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,28 @@ public function __construct($buildingIds = [])
{
parent::__construct();

$user_name = 'System';
$logMessage = 'viewed buildings - ';
$logContext = [
'action' => 'view',
'model' => 'building',
'building_ids' => $buildingIds,
'building_id_count' => count($buildingIds),
'requester_id' => 0,
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'request_proxy_ip' => getRequestIP(true),
'request_method' => \Request::getMethod(),
'request_url' => \Request::fullUrl(),
'request_uri' => \Request::getRequestUri(),
'request_scheme' => \Request::getScheme(),
'request_host' => \Request::getHost()
];

if ($user = auth()->user()) {

$user_name = $user->name;
$logMessage = auth()->user()->name . ' ' . $logMessage;
$logContext['requester_id'] = auth()->user()->id;
$logContext['requester_name'] = auth()->user()->name;

if (Settings::get('broadcast-events', false)) {
// @todo bc view event
Expand All @@ -42,6 +59,6 @@ public function __construct($buildingIds = [])

}

Log::info($user_name . ' viewed ' . count($buildingIds) . ' buildings', $buildingIds);
Log::info($logMessage, $logContext);
}
}
27 changes: 23 additions & 4 deletions app/Events/Api/Building/UnassignedCampus.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,36 @@ public function __construct(Building $building, Campus $campus)
{
parent::__construct();

$info = [
$logMessage = 'unassigned building from campus - ';
$logContext = [
'action' => 'unassignment',
'model' => 'building',
'pivot' => 'campus',
'building_id' => $building->id,
'building_code' => $building->code,
'building_label' => $building->label,
'building_created' => $building->created_at,
'building_updated' => $building->updated_at,
'campus_id' => $campus->id,
'campus_code' => $campus->code,
'campus_label' => $campus->label
'campus_label' => $campus->label,
'requester_id' => 0,
'requester_name' => 'System',
'requester_ip' => getRequestIP(),
'request_proxy_ip' => getRequestIP(true),
'request_method' => \Request::getMethod(),
'request_url' => \Request::fullUrl(),
'request_uri' => \Request::getRequestUri(),
'request_scheme' => \Request::getScheme(),
'request_host' => \Request::getHost()
];

Log::info('Building unassigned Campus:', $info);

if ($user = auth()->user()) {

$logMessage = auth()->user()->name . ' ' . $logMessage;
$logContext['requester_id'] = auth()->user()->id;
$logContext['requester_name'] = auth()->user()->name;

if (Settings::get('broadcast-events', false)) {

$data_to_secure = json_encode([
Expand Down Expand Up @@ -66,5 +83,7 @@ public function __construct(Building $building, Campus $campus)
'bg-yellow'
);
}

Log::info($logMessage, $logContext);
}
}

0 comments on commit 3f7fd32

Please sign in to comment.