Skip to content

Commit

Permalink
updated logging for account events
Browse files Browse the repository at this point in the history
  • Loading branch information
MelonSmasher committed Dec 12, 2017
1 parent 054d02d commit a0cec36
Show file tree
Hide file tree
Showing 16 changed files with 334 additions and 105 deletions.
27 changes: 21 additions & 6 deletions app/Events/Api/Account/AccountCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,28 @@ class AccountCreated extends Event
*/
public function __construct(Account $account)
{
Log::info('Account Created:', [
'id' => $account->id,
'identifier' => $account->identifier,
'username' => $account->username,
'name' => $account->format_full_name(true)
]);
$logMessage = 'created account - ';
$logContext = [
'action' => 'create',
'model' => 'account',
'account_id' => $account->id,
'account_identifier' => $account->identifier,
'account_username' => $account->username,
'account_name_first' => $account->name_first,
'account_name_last' => $account->name_last,
'account_name' => $account->format_full_name(true),
'account_created' => $account->created_at,
'account_updated' => $account->updated_at,
'requester_id' => 0,
'requester_name' => 'System'
];

if (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)) {

$account->primary_duty = $account->primaryDuty;
Expand Down Expand Up @@ -64,5 +77,7 @@ public function __construct(Account $account)
'bg-green'
);
}

Log::info($logMessage, $logContext);
}
}
27 changes: 21 additions & 6 deletions app/Events/Api/Account/AccountDestroyed.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,28 @@ class AccountDestroyed extends Event
*/
public function __construct(Account $account)
{
Log::info('Account Deleted:', [
'id' => $account->id,
'identifier' => $account->identifier,
'username' => $account->username,
'name' => $account->format_full_name(true)
]);
$logMessage = 'destroyed account - ';
$logContext = [
'action' => 'destroy',
'model' => 'account',
'account_id' => $account->id,
'account_identifier' => $account->identifier,
'account_username' => $account->username,
'account_name_first' => $account->name_first,
'account_name_last' => $account->name_last,
'account_name' => $account->format_full_name(true),
'account_created' => $account->created_at,
'account_updated' => $account->updated_at,
'requester_id' => 0,
'requester_name' => 'System'
];

if (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)) {

$trans = $account->toArray();
Expand Down Expand Up @@ -58,5 +71,7 @@ public function __construct(Account $account)
'bg-red'
);
}

Log::info($logMessage, $logContext);
}
}
27 changes: 21 additions & 6 deletions app/Events/Api/Account/AccountRestored.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,28 @@ class AccountRestored extends Event
*/
public function __construct(Account $account)
{
Log::info('Account Restored:', [
'id' => $account->id,
'identifier' => $account->identifier,
'username' => $account->username,
'name' => $account->format_full_name(true)
]);
$logMessage = 'restored account - ';
$logContext = [
'action' => 'restore',
'model' => 'account',
'account_id' => $account->id,
'account_identifier' => $account->identifier,
'account_username' => $account->username,
'account_name_first' => $account->name_first,
'account_name_last' => $account->name_last,
'account_name' => $account->format_full_name(true),
'account_created' => $account->created_at,
'account_updated' => $account->updated_at,
'requester_id' => 0,
'requester_name' => 'System'
];

if (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)) {

$account->primary_duty = $account->primaryDuty;
Expand Down Expand Up @@ -63,5 +76,7 @@ public function __construct(Account $account)
'bg-lime'
);
}

Log::info($logMessage, $logContext);
}
}
27 changes: 21 additions & 6 deletions app/Events/Api/Account/AccountUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,28 @@ class AccountUpdated extends Event
*/
public function __construct(Account $account)
{
Log::info('Account Updated:', [
'id' => $account->id,
'identifier' => $account->identifier,
'username' => $account->username,
'name' => $account->format_full_name(true)
]);
$logMessage = 'updated account - ';
$logContext = [
'action' => 'update',
'model' => 'account',
'account_id' => $account->id,
'account_identifier' => $account->identifier,
'account_username' => $account->username,
'account_name_first' => $account->name_first,
'account_name_last' => $account->name_last,
'account_name' => $account->format_full_name(true),
'account_created' => $account->created_at,
'account_updated' => $account->updated_at,
'requester_id' => 0,
'requester_name' => 'System'
];

if (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)) {

$account->primary_duty = $account->primaryDuty;
Expand Down Expand Up @@ -63,5 +76,7 @@ public function __construct(Account $account)
'bg-lime'
);
}

Log::info($logMessage, $logContext);
}
}
23 changes: 19 additions & 4 deletions app/Events/Api/Account/AccountViewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,27 @@ class AccountViewed extends Event
*/
public function __construct(Account $account)
{
$user_name = 'System';
$logMessage = 'viewed account - ';
$logContext = [
'action' => 'update',
'model' => 'account',
'account_id' => $account->id,
'account_identifier' => $account->identifier,
'account_username' => $account->username,
'account_name_first' => $account->name_first,
'account_name_last' => $account->name_last,
'account_name' => $account->format_full_name(true),
'account_created' => $account->created_at,
'account_updated' => $account->updated_at,
'requester_id' => 0,
'requester_name' => 'System'
];

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 broadcast view event
Expand All @@ -35,7 +51,6 @@ public function __construct(Account $account)
);
}

Log::info($user_name . ' viewed ' . $account->format_full_name() . '\'s account [' . $account->identifier . ']');

Log::info($logMessage, $logContext);
}
}
16 changes: 13 additions & 3 deletions app/Events/Api/Account/AccountsViewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ class AccountsViewed extends Event
*/
public function __construct($accountIds = [])
{
$user_name = 'System';
$logMessage = 'viewed accounts - ';
$logContext = [
'action' => 'restore',
'model' => 'account',
'account_ids' => $accountIds,
'account_id_count' => count($accountIds),
'requester_id' => 0,
'requester_name' => 'System'
];

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 broadcast view event
Expand All @@ -34,6 +44,6 @@ public function __construct($accountIds = [])

}

Log::info($user_name . ' viewed ' . count($accountIds) . ' accounts', $accountIds);
Log::info($logMessage, $logContext);
}
}
28 changes: 21 additions & 7 deletions app/Events/Api/Account/AssignedCourse.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,32 @@ class AssignedCourse extends Event
*/
public function __construct(Account $account, Course $course)
{
$info = [
$logMessage = 'assigned account to course - ';
$logContext = [
'action' => 'assignment',
'model' => 'account',
'pivot' => 'course',
'account_id' => $account->id,
'identifier' => $account->identifier,
'username' => $account->username,
'name' => $account->format_full_name(true),
'account_identifier' => $account->identifier,
'account_username' => $account->username,
'account_name_first' => $account->name_first,
'account_name_last' => $account->name_last,
'account_name' => $account->format_full_name(true),
'account_created' => $account->created_at,
'account_updated' => $account->updated_at,
'course_id' => $course->id,
'course_code' => $course->code,
'course_label' => $course->label
'course_label' => $course->label,
'requester_id' => 0,
'requester_name' => 'System'
];

Log::info('Account assigned Course:', $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)) {

$account->primary_duty = $account->primaryDuty;
Expand Down Expand Up @@ -71,5 +83,7 @@ public function __construct(Account $account, Course $course)
'bg-olive'
);
}

Log::info($logMessage, $logContext);
}
}
28 changes: 22 additions & 6 deletions app/Events/Api/Account/AssignedDepartment.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,34 @@ class AssignedDepartment extends Event
*/
public function __construct(Account $account, Department $department)
{
$info = [

$logMessage = 'assigned account to department - ';
$logContext = [
'action' => 'assignment',
'model' => 'account',
'pivot' => 'department',
'account_id' => $account->id,
'identifier' => $account->identifier,
'username' => $account->username,
'name' => $account->format_full_name(true),
'account_identifier' => $account->identifier,
'account_username' => $account->username,
'account_name_first' => $account->name_first,
'account_name_last' => $account->name_last,
'account_name' => $account->format_full_name(true),
'account_created' => $account->created_at,
'account_updated' => $account->updated_at,
'department_id' => $department->id,
'department_code' => $department->code,
'department_label' => $department->label
'department_label' => $department->label,
'requester_id' => 0,
'requester_name' => 'System'
];

Log::info('Account assigned Department:', $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)) {

$account->primary_duty = $account->primaryDuty;
Expand Down Expand Up @@ -72,5 +86,7 @@ public function __construct(Account $account, Department $department)
'bg-olive'
);
}

Log::info($logMessage, $logContext);
}
}
29 changes: 22 additions & 7 deletions app/Events/Api/Account/AssignedDuty.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,33 @@ class AssignedDuty extends Event
*/
public function __construct(Account $account, Duty $duty)
{
$info = [

$logMessage = 'assigned account to duty - ';
$logContext = [
'action' => 'assignment',
'model' => 'account',
'pivot' => 'duty',
'account_id' => $account->id,
'identifier' => $account->identifier,
'username' => strtolower($account->username),
'name' => $account->format_full_name(true),
'account_identifier' => $account->identifier,
'account_username' => $account->username,
'account_name_first' => $account->name_first,
'account_name_last' => $account->name_last,
'account_name' => $account->format_full_name(true),
'account_created' => $account->created_at,
'account_updated' => $account->updated_at,
'duty_id' => $duty->id,
'duty_code' => $duty->code,
'duty_label' => $duty->label
'duty_label' => $duty->label,
'requester_id' => 0,
'requester_name' => 'System'
];

Log::info('Account assigned Duty:', $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)) {

$account->primary_duty = $account->primaryDuty;
Expand Down Expand Up @@ -71,5 +84,7 @@ public function __construct(Account $account, Duty $duty)
'bg-olive'
);
}

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

0 comments on commit a0cec36

Please sign in to comment.