Renamed LogHelper to Logger
This commit is contained in:
parent
cde25c8a64
commit
ee757f1149
34 changed files with 75 additions and 75 deletions
|
@ -8,7 +8,7 @@ class AcceptUserRegistrationJob extends AbstractUserJob
|
|||
$user->staffConfirmed = true;
|
||||
UserModel::save($user);
|
||||
|
||||
LogHelper::log('{user} confirmed {subject}\'s account', [
|
||||
Logger::log('{user} confirmed {subject}\'s account', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'subject' => TextHelper::reprUser($user)]);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ class ActivateUserEmailJob extends AbstractJob
|
|||
TokenModel::save($token);
|
||||
UserModel::save($user);
|
||||
|
||||
LogHelper::log('{subject} just activated account', [
|
||||
Logger::log('{subject} just activated account', [
|
||||
'subject' => TextHelper::reprUser($user)]);
|
||||
|
||||
return $user;
|
||||
|
|
|
@ -14,7 +14,7 @@ class AddCommentJob extends AbstractJob
|
|||
$comment->text = $text;
|
||||
|
||||
CommentModel::save($comment);
|
||||
LogHelper::log('{user} commented on {post}', [
|
||||
Logger::log('{user} commented on {post}', [
|
||||
'user' => TextHelper::reprUser($user),
|
||||
'post' => TextHelper::reprPost($comment->getPost()->id)]);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class AddPostJob extends AbstractJob
|
|||
public function execute()
|
||||
{
|
||||
$post = PostModel::spawn();
|
||||
LogHelper::bufferChanges();
|
||||
Logger::bufferChanges();
|
||||
|
||||
//basic stuff
|
||||
$anonymous = $this->getArgument(self::ANONYMOUS);
|
||||
|
@ -34,10 +34,10 @@ class AddPostJob extends AbstractJob
|
|||
PostModel::save($post);
|
||||
|
||||
//clean edit log
|
||||
LogHelper::setBuffer([]);
|
||||
Logger::setBuffer([]);
|
||||
|
||||
//log
|
||||
LogHelper::log('{user} added {post} (tags: {tags}, safety: {safety}, source: {source})', [
|
||||
Logger::log('{user} added {post} (tags: {tags}, safety: {safety}, source: {source})', [
|
||||
'user' => ($anonymous and !getConfig()->misc->logAnonymousUploads)
|
||||
? TextHelper::reprUser(UserModel::getAnonymousName())
|
||||
: TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
|
@ -47,7 +47,7 @@ class AddPostJob extends AbstractJob
|
|||
'source' => $post->source]);
|
||||
|
||||
//finish
|
||||
LogHelper::flush();
|
||||
Logger::flush();
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ class AddUserJob extends AbstractJob
|
|||
? AccessRank::Admin
|
||||
: AccessRank::Registered;
|
||||
|
||||
LogHelper::bufferChanges();
|
||||
Logger::bufferChanges();
|
||||
Api::disablePrivilegeChecking();
|
||||
Api::run((new EditUserJob)->skipSaving(), $arguments);
|
||||
Api::enablePrivilegeChecking();
|
||||
LogHelper::setBuffer([]);
|
||||
Logger::setBuffer([]);
|
||||
|
||||
if ($firstUser)
|
||||
$user->confirmEmail();
|
||||
|
@ -30,10 +30,10 @@ class AddUserJob extends AbstractJob
|
|||
//save the user to db if everything went okay
|
||||
UserModel::save($user);
|
||||
|
||||
LogHelper::log('{subject} just signed up', [
|
||||
Logger::log('{subject} just signed up', [
|
||||
'subject' => TextHelper::reprUser($user)]);
|
||||
|
||||
LogHelper::flush();
|
||||
Logger::flush();
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ class DeleteCommentJob extends AbstractJob
|
|||
|
||||
CommentModel::remove($this->comment);
|
||||
|
||||
LogHelper::log('{user} removed comment from {post}', [
|
||||
Logger::log('{user} removed comment from {post}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post)]);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ class DeletePostJob extends AbstractPostJob
|
|||
|
||||
PostModel::remove($post);
|
||||
|
||||
LogHelper::log('{user} deleted {post}', [
|
||||
Logger::log('{user} deleted {post}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post)]);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ class DeleteUserJob extends AbstractUserJob
|
|||
$name = $user->name;
|
||||
UserModel::remove($user);
|
||||
|
||||
LogHelper::log('{user} removed {subject}\'s account', [
|
||||
Logger::log('{user} removed {subject}\'s account', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'subject' => TextHelper::reprUser($name)]);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class EditCommentJob extends AbstractJob
|
|||
$comment->text = CommentModel::validateText($this->getArgument(self::TEXT));
|
||||
|
||||
CommentModel::save($comment);
|
||||
LogHelper::log('{user} edited comment in {post}', [
|
||||
Logger::log('{user} edited comment in {post}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($comment->getPost())]);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ class EditPostContentJob extends AbstractPostEditJob
|
|||
if (!$this->skipSaving)
|
||||
PostModel::save($post);
|
||||
|
||||
LogHelper::log('{user} changed contents of {post}', [
|
||||
Logger::log('{user} changed contents of {post}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post)]);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ class EditPostJob extends AbstractPostEditJob
|
|||
{
|
||||
$post = $this->post;
|
||||
|
||||
LogHelper::bufferChanges();
|
||||
Logger::bufferChanges();
|
||||
|
||||
$subJobs =
|
||||
[
|
||||
|
@ -37,7 +37,7 @@ class EditPostJob extends AbstractPostEditJob
|
|||
if (!$this->skipSaving)
|
||||
PostModel::save($post);
|
||||
|
||||
LogHelper::flush();
|
||||
Logger::flush();
|
||||
return $post;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class EditPostRelationsJob extends AbstractPostEditJob
|
|||
|
||||
foreach (array_diff($oldRelatedIds, $newRelatedIds) as $post2id)
|
||||
{
|
||||
LogHelper::log('{user} removed relation between {post} and {post2}', [
|
||||
Logger::log('{user} removed relation between {post} and {post2}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post),
|
||||
'post2' => TextHelper::reprPost($post2id)]);
|
||||
|
@ -25,7 +25,7 @@ class EditPostRelationsJob extends AbstractPostEditJob
|
|||
|
||||
foreach (array_diff($newRelatedIds, $oldRelatedIds) as $post2id)
|
||||
{
|
||||
LogHelper::log('{user} added relation between {post} and {post2}', [
|
||||
Logger::log('{user} added relation between {post} and {post2}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post),
|
||||
'post2' => TextHelper::reprPost($post2id)]);
|
||||
|
|
|
@ -16,7 +16,7 @@ class EditPostSafetyJob extends AbstractPostEditJob
|
|||
|
||||
if ($oldSafety != $newSafety)
|
||||
{
|
||||
LogHelper::log('{user} changed safety of {post} to {safety}', [
|
||||
Logger::log('{user} changed safety of {post} to {safety}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post),
|
||||
'safety' => $post->getSafety()->toString()]);
|
||||
|
|
|
@ -16,7 +16,7 @@ class EditPostSourceJob extends AbstractPostEditJob
|
|||
|
||||
if ($oldSource != $newSource)
|
||||
{
|
||||
LogHelper::log('{user} changed source of {post} to {source}', [
|
||||
Logger::log('{user} changed source of {post} to {source}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post),
|
||||
'source' => $post->source]);
|
||||
|
|
|
@ -18,7 +18,7 @@ class EditPostTagsJob extends AbstractPostEditJob
|
|||
|
||||
foreach (array_diff($oldTags, $newTags) as $tag)
|
||||
{
|
||||
LogHelper::log('{user} untagged {post} with {tag}', [
|
||||
Logger::log('{user} untagged {post} with {tag}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post),
|
||||
'tag' => TextHelper::reprTag($tag)]);
|
||||
|
@ -26,7 +26,7 @@ class EditPostTagsJob extends AbstractPostEditJob
|
|||
|
||||
foreach (array_diff($newTags, $oldTags) as $tag)
|
||||
{
|
||||
LogHelper::log('{user} tagged {post} with {tag}', [
|
||||
Logger::log('{user} tagged {post} with {tag}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post),
|
||||
'tag' => TextHelper::reprTag($tag)]);
|
||||
|
|
|
@ -13,7 +13,7 @@ class EditPostThumbJob extends AbstractPostEditJob
|
|||
if (!$this->skipSaving)
|
||||
PostModel::save($post);
|
||||
|
||||
LogHelper::log('{user} changed thumb of {post}', [
|
||||
Logger::log('{user} changed thumb of {post}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post)]);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ class EditPostUrlJob extends AbstractPostEditJob
|
|||
if (!$this->skipSaving)
|
||||
PostModel::save($post);
|
||||
|
||||
LogHelper::log('{user} changed contents of {post}', [
|
||||
Logger::log('{user} changed contents of {post}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post)]);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class EditUserAccessRankJob extends AbstractUserEditJob
|
|||
if (!$this->skipSaving)
|
||||
UserModel::save($user);
|
||||
|
||||
LogHelper::log('{user} changed {subject}\'s access rank to {rank}', [
|
||||
Logger::log('{user} changed {subject}\'s access rank to {rank}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'subject' => TextHelper::reprUser($user),
|
||||
'rank' => $newAccessRank->toString()]);
|
||||
|
|
|
@ -32,7 +32,7 @@ class EditUserEmailJob extends AbstractUserEditJob
|
|||
if (!$this->skipSaving)
|
||||
UserModel::save($user);
|
||||
|
||||
LogHelper::log('{user} changed {subject}\'s e-mail to {mail}', [
|
||||
Logger::log('{user} changed {subject}\'s e-mail to {mail}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'subject' => TextHelper::reprUser($user),
|
||||
'mail' => $newEmail]);
|
||||
|
|
|
@ -36,7 +36,7 @@ class EditUserJob extends AbstractUserEditJob
|
|||
{
|
||||
$user = $this->user;
|
||||
|
||||
LogHelper::bufferChanges();
|
||||
Logger::bufferChanges();
|
||||
|
||||
foreach ($this->subJobs as $subJob)
|
||||
{
|
||||
|
@ -57,7 +57,7 @@ class EditUserJob extends AbstractUserEditJob
|
|||
if (!$this->skipSaving)
|
||||
UserModel::save($user);
|
||||
|
||||
LogHelper::flush();
|
||||
Logger::flush();
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ class EditUserNameJob extends AbstractUserEditJob
|
|||
if (!$this->skipSaving)
|
||||
UserModel::save($user);
|
||||
|
||||
LogHelper::log('{user} renamed {old} to {new}', [
|
||||
Logger::log('{user} renamed {old} to {new}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'old' => TextHelper::reprUser($oldName),
|
||||
'new' => TextHelper::reprUser($newName)]);
|
||||
|
|
|
@ -18,7 +18,7 @@ class EditUserPasswordJob extends AbstractUserEditJob
|
|||
if (!$this->skipSaving)
|
||||
UserModel::save($user);
|
||||
|
||||
LogHelper::log('{user} changed {subject}\'s password', [
|
||||
Logger::log('{user} changed {subject}\'s password', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'subject' => TextHelper::reprUser($user)]);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class FeaturePostJob extends AbstractPostJob
|
|||
PropertyModel::set(PropertyModel::FeaturedPostDate, time());
|
||||
PropertyModel::set(PropertyModel::FeaturedPostUserName, Auth::getCurrentUser()->name);
|
||||
|
||||
LogHelper::log('{user} featured {post} on main page', [
|
||||
Logger::log('{user} featured {post} on main page', [
|
||||
'user' => TextHelper::reprPost(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post)]);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class FlagPostJob extends AbstractPostJob
|
|||
$flagged []= $key;
|
||||
SessionHelper::set('flagged', $flagged);
|
||||
|
||||
LogHelper::log('{user} flagged {post} for moderator attention', [
|
||||
Logger::log('{user} flagged {post} for moderator attention', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post)]);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class FlagUserJob extends AbstractUserJob
|
|||
$flagged []= $key;
|
||||
SessionHelper::set('flagged', $flagged);
|
||||
|
||||
LogHelper::log('{user} flagged {subject} for moderator attention', [
|
||||
Logger::log('{user} flagged {subject} for moderator attention', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'subject' => TextHelper::reprUser($user)]);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class MergeTagsJob extends AbstractJob
|
|||
TagModel::removeUnused();
|
||||
TagModel::merge($sourceTag, $targetTag);
|
||||
|
||||
LogHelper::log('{user} merged {source} with {target}', [
|
||||
Logger::log('{user} merged {source} with {target}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'source' => TextHelper::reprTag($sourceTag),
|
||||
'target' => TextHelper::reprTag($targetTag)]);
|
||||
|
|
|
@ -35,7 +35,7 @@ class PasswordResetJob extends AbstractJob
|
|||
TokenModel::save($token);
|
||||
UserModel::save($user);
|
||||
|
||||
LogHelper::log('{subject} just reset password', [
|
||||
Logger::log('{subject} just reset password', [
|
||||
'subject' => TextHelper::reprUser($user)]);
|
||||
|
||||
$x = new StdClass;
|
||||
|
|
|
@ -12,7 +12,7 @@ class RenameTagsJob extends AbstractJob
|
|||
TagModel::removeUnused();
|
||||
TagModel::rename($sourceTag, $targetTag);
|
||||
|
||||
LogHelper::log('{user} renamed {source} to {target}', [
|
||||
Logger::log('{user} renamed {source} to {target}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'source' => TextHelper::reprTag($sourceTag),
|
||||
'target' => TextHelper::reprTag($targetTag)]);
|
||||
|
|
|
@ -34,14 +34,14 @@ class TogglePostTagJob extends AbstractPostJob
|
|||
|
||||
if ($enable)
|
||||
{
|
||||
LogHelper::log('{user} tagged {post} with {tag}', [
|
||||
Logger::log('{user} tagged {post} with {tag}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post),
|
||||
'tag' => TextHelper::reprTag($tag)]);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper::log('{user} untagged {post} with {tag}', [
|
||||
Logger::log('{user} untagged {post} with {tag}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'post' => TextHelper::reprPost($post),
|
||||
'tag' => TextHelper::reprTag($tag)]);
|
||||
|
|
|
@ -9,7 +9,7 @@ class TogglePostVisibilityJob extends AbstractPostJob
|
|||
$post->setHidden(!$visible);
|
||||
PostModel::save($post);
|
||||
|
||||
LogHelper::log(
|
||||
Logger::log(
|
||||
$visible
|
||||
? '{user} unhidden {post}'
|
||||
: '{user} hidden {post}', [
|
||||
|
|
|
@ -9,7 +9,7 @@ class ToggleUserBanJob extends AbstractUserJob
|
|||
$user->banned = $banned;
|
||||
UserModel::save($user);
|
||||
|
||||
LogHelper::log(
|
||||
Logger::log(
|
||||
$banned
|
||||
? '{user} banned {subject}'
|
||||
: '{user} unbanned {subject}', [
|
||||
|
|
30
src/LogEvent.php
Normal file
30
src/LogEvent.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
class LogEvent
|
||||
{
|
||||
public $timestamp;
|
||||
public $text;
|
||||
public $ip;
|
||||
public $tokens;
|
||||
|
||||
public function __construct($text, array $tokens = [])
|
||||
{
|
||||
$this->timestamp = time();
|
||||
$this->text = $text;
|
||||
$this->ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
|
||||
$this->tokens = $tokens;
|
||||
}
|
||||
|
||||
public function getText()
|
||||
{
|
||||
return TextHelper::replaceTokens($this->text, $this->tokens);
|
||||
}
|
||||
|
||||
public function getFullText()
|
||||
{
|
||||
$date = date('Y-m-d H:i:s', $this->timestamp);
|
||||
$ip = $this->ip;
|
||||
$text = $this->getText();
|
||||
$line = sprintf('[%s] %s: %s', $date, $ip, $text);
|
||||
return $line;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
class LogHelper
|
||||
class Logger
|
||||
{
|
||||
static $context;
|
||||
static $config;
|
||||
|
@ -58,34 +58,4 @@ class LogHelper
|
|||
}
|
||||
}
|
||||
|
||||
class LogEvent
|
||||
{
|
||||
public $timestamp;
|
||||
public $text;
|
||||
public $ip;
|
||||
public $tokens;
|
||||
|
||||
public function __construct($text, array $tokens = [])
|
||||
{
|
||||
$this->timestamp = time();
|
||||
$this->text = $text;
|
||||
$this->ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
|
||||
$this->tokens = $tokens;
|
||||
}
|
||||
|
||||
public function getText()
|
||||
{
|
||||
return TextHelper::replaceTokens($this->text, $this->tokens);
|
||||
}
|
||||
|
||||
public function getFullText()
|
||||
{
|
||||
$date = date('Y-m-d H:i:s', $this->timestamp);
|
||||
$ip = $this->ip;
|
||||
$text = $this->getText();
|
||||
$line = sprintf('[%s] %s: %s', $date, $ip, $text);
|
||||
return $line;
|
||||
}
|
||||
}
|
||||
|
||||
LogHelper::init();
|
||||
Logger::init();
|
|
@ -44,7 +44,7 @@ class Mailer
|
|||
|
||||
self::$mailCounter ++;
|
||||
|
||||
LogHelper::log('Sending e-mail with subject "{subject}" to {mail}', [
|
||||
Logger::log('Sending e-mail with subject "{subject}" to {mail}', [
|
||||
'subject' => $subject,
|
||||
'mail' => $recipientEmail]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue