Logging: removed logEvent() and log prefixes

This looked ugly.
This commit is contained in:
Marcin Kurczewski 2013-11-22 23:32:56 +01:00
parent db602f08d3
commit 676c3a41e2
5 changed files with 35 additions and 40 deletions

View file

@ -63,7 +63,7 @@ class CommentController
if (InputHelper::get('sender') != 'preview')
{
Model_Comment::save($comment);
LogHelper::logEvent('comment-add', '{user} commented on {post}', ['post' => TextHelper::reprPost($post->id)]);
LogHelper::log('{user} commented on {post}', ['post' => TextHelper::reprPost($post->id)]);
}
$this->context->transport->textPreview = $comment->getText();
StatusHelper::success();
@ -82,7 +82,7 @@ class CommentController
PrivilegesHelper::confirmWithException(Privilege::DeleteComment, PrivilegesHelper::getIdentitySubPrivilege($comment->commenter));
Model_Comment::remove($comment);
LogHelper::logEvent('comment-del', '{user} removed comment from {post}', ['post' => TextHelper::reprPost($comment->post)]);
LogHelper::log('{user} removed comment from {post}', ['post' => TextHelper::reprPost($comment->post)]);
StatusHelper::success();
}
}

View file

@ -139,12 +139,12 @@ class PostController
if (in_array($tag, $tags))
{
$tags = array_diff($tags, [$tag]);
LogHelper::logEvent('post-tag-del', '{user} untagged {post} with {tag}', ['post' => TextHelper::reprPost($post), 'tag' => TextHelper::reprTag($tag)]);
LogHelper::log('{user} untagged {post} with {tag}', ['post' => TextHelper::reprPost($post), 'tag' => TextHelper::reprTag($tag)]);
}
else
{
$tags += [$tag];
LogHelper::logEvent('post-tag-add', '{user} tagged {post} with {tag}', ['post' => TextHelper::reprPost($post), 'tag' => TextHelper::reprTag($tag)]);
LogHelper::log('{user} tagged {post} with {tag}', ['post' => TextHelper::reprPost($post), 'tag' => TextHelper::reprTag($tag)]);
}
$dbTags = Model_Tag::insertOrUpdate($tags);
@ -214,7 +214,7 @@ class PostController
? '{anon}'
: '{user}';
$fmt .= ' added {post}';
LogHelper::logEvent('post-new', $fmt, ['post' => TextHelper::reprPost($post)]);
LogHelper::log($fmt, ['post' => TextHelper::reprPost($post)]);
//after logging basic info, do the editing stuff
$this->doEdit($post, true);
@ -280,7 +280,7 @@ class PostController
$flagged []= $key;
SessionHelper::set('flagged', $flagged);
LogHelper::logEvent('post-flag', '{user} flagged {post} for moderator attention', ['post' => TextHelper::reprPost($post)]);
LogHelper::log('{user} flagged {post} for moderator attention', ['post' => TextHelper::reprPost($post)]);
StatusHelper::success();
}
}
@ -300,7 +300,7 @@ class PostController
$post->setHidden(true);
Model_Post::save($post);
LogHelper::logEvent('post-hide', '{user} hidden {post}', ['post' => TextHelper::reprPost($post)]);
LogHelper::log('{user} hidden {post}', ['post' => TextHelper::reprPost($post)]);
StatusHelper::success();
}
}
@ -320,7 +320,7 @@ class PostController
$post->setHidden(false);
Model_Post::save($post);
LogHelper::logEvent('post-unhide', '{user} unhidden {post}', ['post' => TextHelper::reprPost($post)]);
LogHelper::log('{user} unhidden {post}', ['post' => TextHelper::reprPost($post)]);
StatusHelper::success();
}
}
@ -339,7 +339,7 @@ class PostController
{
Model_Post::remove($post);
LogHelper::logEvent('post-delete', '{user} deleted {post}', ['post' => TextHelper::reprPost($id)]);
LogHelper::log('{user} deleted {post}', ['post' => TextHelper::reprPost($id)]);
StatusHelper::success();
}
}
@ -421,7 +421,7 @@ class PostController
Model_Property::set(Model_Property::FeaturedPostUserId, $this->context->user->id);
Model_Property::set(Model_Property::FeaturedPostDate, time());
StatusHelper::success();
LogHelper::logEvent('post-feature', '{user} featured {post} on main page', ['post' => TextHelper::reprPost($post)]);
LogHelper::log('{user} featured {post} on main page', ['post' => TextHelper::reprPost($post)]);
}
@ -578,7 +578,7 @@ class PostController
$post->setContentFromPath($srcPath);
if (!$isNew)
LogHelper::logEvent('post-edit', '{user} changed contents of {post}', ['post' => TextHelper::reprPost($post)]);
LogHelper::log('{user} changed contents of {post}', ['post' => TextHelper::reprPost($post)]);
}
elseif (InputHelper::get('url'))
{
@ -589,7 +589,7 @@ class PostController
$post->setContentFromUrl($url);
if (!$isNew)
LogHelper::logEvent('post-edit', '{user} changed contents of {post}', ['post' => TextHelper::reprPost($post)]);
LogHelper::log('{user} changed contents of {post}', ['post' => TextHelper::reprPost($post)]);
}
/* safety */
@ -604,7 +604,7 @@ class PostController
$newSafety = $post->safety;
if ($oldSafety != $newSafety)
LogHelper::logEvent('post-edit', '{user} changed safety for {post} to {safety}', ['post' => TextHelper::reprPost($post), 'safety' => PostSafety::toString($post->safety)]);
LogHelper::log('{user} changed safety for {post} to {safety}', ['post' => TextHelper::reprPost($post), 'safety' => PostSafety::toString($post->safety)]);
}
/* tags */
@ -619,10 +619,10 @@ class PostController
$newTags = array_map(function($tag) { return $tag->name; }, $post->sharedTag);
foreach (array_diff($oldTags, $newTags) as $tag)
LogHelper::logEvent('post-tag-del', '{user} untagged {post} with {tag}', ['post' => TextHelper::reprPost($post), 'tag' => TextHelper::reprTag($tag)]);
LogHelper::log('{user} untagged {post} with {tag}', ['post' => TextHelper::reprPost($post), 'tag' => TextHelper::reprTag($tag)]);
foreach (array_diff($newTags, $oldTags) as $tag)
LogHelper::logEvent('post-tag-add', '{user} tagged {post} with {tag}', ['post' => TextHelper::reprPost($post), 'tag' => TextHelper::reprTag($tag)]);
LogHelper::log('{user} tagged {post} with {tag}', ['post' => TextHelper::reprPost($post), 'tag' => TextHelper::reprTag($tag)]);
}
/* source */
@ -637,7 +637,7 @@ class PostController
$newSource = $post->source;
if ($oldSource != $newSource)
LogHelper::logEvent('post-edit', '{user} changed source for {post} to {source}', ['post' => TextHelper::reprPost($post), 'source' => $post->source]);
LogHelper::log('{user} changed source for {post} to {source}', ['post' => TextHelper::reprPost($post), 'source' => $post->source]);
}
/* relations */
@ -652,10 +652,10 @@ class PostController
$newRelatedIds = array_map(function($post) { return $post->id; }, $post->via('crossref')->sharedPost);
foreach (array_diff($oldRelatedIds, $newRelatedIds) as $post2id)
LogHelper::logEvent('post-relation-del', '{user} removed relation between {post} and {post2}', ['post' => TextHelper::reprPost($post), 'post2' => TextHelper::reprPost($post2id)]);
LogHelper::log('{user} removed relation between {post} and {post2}', ['post' => TextHelper::reprPost($post), 'post2' => TextHelper::reprPost($post2id)]);
foreach (array_diff($newRelatedIds, $oldRelatedIds) as $post2id)
LogHelper::logEvent('post-relation-add', '{user} added relation between {post} and {post2}', ['post' => TextHelper::reprPost($post), 'post2' => TextHelper::reprPost($post2id)]);
LogHelper::log('{user} added relation between {post} and {post2}', ['post' => TextHelper::reprPost($post), 'post2' => TextHelper::reprPost($post2id)]);
}
/* thumbnail */
@ -670,7 +670,7 @@ class PostController
$srcPath = $suppliedFile['tmp_name'];
$post->setCustomThumbnailFromPath($srcPath);
LogHelper::logEvent('post-edit', '{user} changed thumb for {post}', ['post' => TextHelper::reprPost($post)]);
LogHelper::log('{user} changed thumb for {post}', ['post' => TextHelper::reprPost($post)]);
}
}
}

View file

@ -67,7 +67,7 @@ class TagController
Model_Tag::remove($sourceTag);
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('tag', 'list'));
LogHelper::logEvent('tag-merge', '{user} merged {source} with {target}', ['source' => TextHelper::reprTag($suppliedSourceTag), 'target' => TextHelper::reprTag($suppliedTargetTag)]);
LogHelper::log('{user} merged {source} with {target}', ['source' => TextHelper::reprTag($suppliedSourceTag), 'target' => TextHelper::reprTag($suppliedTargetTag)]);
StatusHelper::success();
}
}
@ -102,7 +102,7 @@ class TagController
Model_Tag::save($sourceTag);
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('tag', 'list'));
LogHelper::logEvent('tag-rename', '{user} renamed {source} to {target}', ['source' => TextHelper::reprTag($suppliedSourceTag), 'target' => TextHelper::reprTag($suppliedTargetTag)]);
LogHelper::log('{user} renamed {source} to {target}', ['source' => TextHelper::reprTag($suppliedSourceTag), 'target' => TextHelper::reprTag($suppliedTargetTag)]);
StatusHelper::success();
}
}

View file

@ -65,7 +65,7 @@ class UserController
$encodedSubject = '=?UTF-8?B?' . base64_encode($subject) . '?=';
mail($recipientEmail, $encodedSubject, $body, implode("\r\n", $headers), '-f' . $senderEmail);
LogHelper::logEvent('mail', 'Sending e-mail with subject "{subject}" to {mail}', ['subject' => $subject, 'mail' => $recipientEmail]);
LogHelper::log('Sending e-mail with subject "{subject}" to {mail}', ['subject' => $subject, 'mail' => $recipientEmail]);
}
private static function sendEmailChangeConfirmation($user)
@ -165,7 +165,7 @@ class UserController
$flagged []= $key;
SessionHelper::set('flagged', $flagged);
LogHelper::logEvent('user-flag', '{user} flagged {subject} for moderator attention', ['subject' => TextHelper::reprUser($user)]);
LogHelper::log('{user} flagged {subject} for moderator attention', ['subject' => TextHelper::reprUser($user)]);
StatusHelper::success();
}
}
@ -186,7 +186,7 @@ class UserController
$user->banned = true;
Model_User::save($user);
LogHelper::logEvent('ban', '{user} banned {subject}', ['subject' => TextHelper::reprUser($user)]);
LogHelper::log('{user} banned {subject}', ['subject' => TextHelper::reprUser($user)]);
StatusHelper::success();
}
}
@ -207,7 +207,7 @@ class UserController
$user->banned = false;
Model_User::save($user);
LogHelper::logEvent('unban', '{user} unbanned {subject}', ['subject' => TextHelper::reprUser($user)]);
LogHelper::log('{user} unbanned {subject}', ['subject' => TextHelper::reprUser($user)]);
StatusHelper::success();
}
}
@ -226,7 +226,7 @@ class UserController
{
$user->staff_confirmed = true;
Model_User::save($user);
LogHelper::logEvent('reg-accept', '{user} confirmed account for {subject}', ['subject' => TextHelper::reprUser($user)]);
LogHelper::log('{user} confirmed account for {subject}', ['subject' => TextHelper::reprUser($user)]);
StatusHelper::success();
}
}
@ -264,7 +264,7 @@ class UserController
AuthController::doLogOut();
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index'));
LogHelper::logEvent('user-del', '{user} removed account for {subject}', ['subject' => TextHelper::reprUser($name)]);
LogHelper::log('{user} removed account for {subject}', ['subject' => TextHelper::reprUser($name)]);
StatusHelper::success();
}
}
@ -337,7 +337,7 @@ class UserController
$suppliedName = Model_User::validateUserName($suppliedName);
$oldName = $user->name;
$user->name = $suppliedName;
LogHelper::logEvent('user-edit', '{user} renamed {old} to {new}', ['old' => TextHelper::reprUser($oldName), 'new' => TextHelper::reprUser($suppliedName)]);
LogHelper::log('{user} renamed {old} to {new}', ['old' => TextHelper::reprUser($oldName), 'new' => TextHelper::reprUser($suppliedName)]);
}
if ($suppliedPassword1 != '')
@ -347,7 +347,7 @@ class UserController
throw new SimpleException('Specified passwords must be the same');
$suppliedPassword = Model_User::validatePassword($suppliedPassword1);
$user->pass_hash = Model_User::hashPassword($suppliedPassword, $user->pass_salt);
LogHelper::logEvent('user-edit', '{user} changed password for {subject}', ['subject' => TextHelper::reprUser($user)]);
LogHelper::log('{user} changed password for {subject}', ['subject' => TextHelper::reprUser($user)]);
}
if ($suppliedEmail != '' and $suppliedEmail != $user->email_confirmed)
@ -359,13 +359,13 @@ class UserController
$user->email_unconfirmed = $suppliedEmail;
if (!empty($user->email_unconfirmed))
$confirmMail = true;
LogHelper::logEvent('user-edit', '{user} changed e-mail to {mail}', ['mail' => $suppliedEmail]);
LogHelper::log('{user} changed e-mail to {mail}', ['mail' => $suppliedEmail]);
}
else
{
$user->email_unconfirmed = null;
$user->email_confirmed = $suppliedEmail;
LogHelper::logEvent('user-edit', '{user} changed e-mail for {subject} to {mail}', ['subject' => TextHelper::reprUser($user), 'mail' => $suppliedEmail]);
LogHelper::log('{user} changed e-mail for {subject} to {mail}', ['subject' => TextHelper::reprUser($user), 'mail' => $suppliedEmail]);
}
}
@ -374,7 +374,7 @@ class UserController
PrivilegesHelper::confirmWithException(Privilege::ChangeUserAccessRank, PrivilegesHelper::getIdentitySubPrivilege($user));
$suppliedAccessRank = Model_User::validateAccessRank($suppliedAccessRank);
$user->access_rank = $suppliedAccessRank;
LogHelper::logEvent('user-edit', '{user} changed access rank for {subject} to {rank}', ['subject' => TextHelper::reprUser($user), 'rank' => AccessRank::toString($suppliedAccessRank)]);
LogHelper::log('{user} changed access rank for {subject} to {rank}', ['subject' => TextHelper::reprUser($user), 'rank' => AccessRank::toString($suppliedAccessRank)]);
}
if ($this->context->user->id == $user->id)
@ -549,7 +549,7 @@ class UserController
elseif ($this->config->registration->staffActivation)
$message .= ' Your registration must be now confirmed by staff.';
LogHelper::logEvent('user-reg', '{subject} just signed up', ['subject' => TextHelper::reprUser($dbUser)]);
LogHelper::log('{subject} just signed up', ['subject' => TextHelper::reprUser($dbUser)]);
StatusHelper::success($message);
if (!$this->config->registration->needEmailForRegistering and !$this->config->registration->staffActivation)
@ -579,7 +579,7 @@ class UserController
R::store($dbToken);
Model_User::save($dbUser);
LogHelper::logEvent('user-activation', '{subject} just activated account', ['subject' => TextHelper::reprUser($dbUser)]);
LogHelper::log('{subject} just activated account', ['subject' => TextHelper::reprUser($dbUser)]);
$message = 'Activation completed successfully.';
if ($this->config->registration->staffActivation)
$message .= ' However, your account still must be confirmed by staff.';
@ -616,7 +616,7 @@ class UserController
R::store($dbToken);
Model_User::save($dbUser);
LogHelper::logEvent('user-pass-reset', '{subject} just reset password', ['subject' => TextHelper::reprUser($dbUser)]);
LogHelper::log('{subject} just reset password', ['subject' => TextHelper::reprUser($dbUser)]);
$message = 'Password reset successful. Your new password is **' . $randomPassword . '**.';
StatusHelper::success($message);

View file

@ -62,11 +62,6 @@ class LogHelper
if (self::$autoFlush)
self::flush();
}
public static function logEvent($event, $text, array $tokens = [])
{
return self::log(sprintf('[%s] %s', $event, $text), $tokens);
}
}
LogHelper::init();