/** * Log the project. * * @param string $message * @param int $time * @param int $priority * @return void */ public function log($message, $time = null, $priority = \Pop\Log\Logger::INFO) { if (null !== $this->logger) { if (null !== $time) { $end = stripos($message, 'send') === false && (stripos($message, 'kill') !== false || stripos($message, 'end') !== false) ? PHP_EOL : null; $message = "[" . ($time - $this->start) . " seconds]\t\t" . $message . $end; } $this->logger->log($priority, $message); } }
<?php require_once '../../bootstrap.php'; use Pop\Log; use Pop\Log\Writer; try { $emails = array('Bob Smith' => '*****@*****.**', 'Bubba Smith' => '*****@*****.**'); $options = array('subject' => 'Test App Log Entry:', 'headers' => array('From' => 'Test App Logger <*****@*****.**>', 'Reply-To' => 'Test App Logger <*****@*****.**>', 'X-Mailer' => 'PHP/' . phpversion(), 'X-Priority' => '3')); $logger = new Log\Logger(new Writer\Mail($emails)); $logger->addWriter(new Writer\File('../tmp/app.log')); $logger->emerg('Yo stuff is whack man!', $options)->info("Here's some, yo, you know, info stuff", $options); echo 'Done.'; } catch (\Exception $e) { echo $e->getMessage(); }
/** * Log a user login * * @param \Phire\Table\UserTypes $type * @param \Phire\Table\Users $user * @return void */ protected function log($type, $user) { $exclude = array(); if ($type->log_exclude != '') { $exclude = explode(',', $type->log_exclude); } $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']); if (!in_array($_SERVER['REMOTE_ADDR'], $exclude)) { $emails = explode(',', $type->log_emails); $noreply = Table\Config::findById('reply_email')->value; $options = array('subject' => 'Phire CMS ' . ucfirst(strtolower($type->type)) . ' ' . $this->i18n->__('Login Notification') . ' (' . $domain . ')', 'headers' => array('From' => $noreply . ' <' . $noreply . '>', 'Reply-To' => $noreply . ' <' . $noreply . '>')); $msg = $this->i18n->__('Someone has logged in as a %1 from %2 using %3.', array(strtolower($type->type), $_SERVER['REMOTE_ADDR'], $user->username)); $logger = new Log\Logger(new Log\Writer\Mail($emails)); $logger->notice($msg, $options); } }
<?php require_once '../../bootstrap.php'; use Pop\Log; use Pop\Log\Writer; try { $logger = new Log\Logger(new Writer\File('../tmp/app.log')); $logger->addWriter(new Writer\File('../tmp/app.xml')); $logger->emerg('Yo stuff is whack man!')->info("Here's some, yo, you know, info stuff"); echo 'Done.'; } catch (\Exception $e) { echo $e->getMessage(); }
public function testWriterDb() { $w = new Db(new Logs()); $this->assertInstanceOf('Pop\\Log\\Writer\\Db', $w); $l = new Logger($w); $l->debug('Test log message'); $entries = Logs::findAll(); $this->assertEquals(1, count($entries->rows)); foreach ($entries->rows as $row) { $e = Logs::findById($row->id); if (isset($e->id)) { $e->delete(); } } }
/** * Log session * * @param mixed $config * @param mixed $user * @param boolean $success * @return void */ public static function log($config, $user, $success) { if ($config->log_type == 3 || $config->log_type == 2 && $success || $config->log_type == 1 && !$success) { $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']); $noreply = 'noreply@' . $domain; $options = ['subject' => ($success ? 'Successful' : 'Failed') . ' Login (' . $domain . ') : Phire CMS Session Notification', 'headers' => ['From' => $noreply . ' <' . $noreply . '>', 'Reply-To' => $noreply . ' <' . $noreply . '>']]; $message = $success ? 'Someone has logged in at ' . $_SERVER['REQUEST_URI'] . ' as \'' . $user->username . '\' from ' . $_SERVER['REMOTE_ADDR'] : 'Someone attempted to log in at ' . $_SERVER['REQUEST_URI'] . ' as \'' . $user->username . '\' from ' . $_SERVER['REMOTE_ADDR']; $emails = explode(',', $config->log_emails); if (count($emails) > 0) { $logger = new Log\Logger(new Log\Writer\Mail($emails, $options)); $logger->alert($message); } } }