Add debug logging to feeds. Add route info to all debug logs. (#39)
Reviewed-on: https://gitea.subcultureofone.org/greg/tkr/pulls/39 Co-authored-by: Greg Sarjeant <greg@subcultureofone.org> Co-committed-by: Greg Sarjeant <greg@subcultureofone.org>
This commit is contained in:
parent
8b5a249450
commit
dc0abf8c7c
@ -67,6 +67,9 @@ if (strpos($path, $config->basePath) === 0) {
|
|||||||
|
|
||||||
// strip the trailing slash from the resulting route
|
// strip the trailing slash from the resulting route
|
||||||
$path = trim($path, '/');
|
$path = trim($path, '/');
|
||||||
|
|
||||||
|
// Set route context for logging
|
||||||
|
Log::setRouteContext("$method $path");
|
||||||
Log::debug("Path requested: {$path}");
|
Log::debug("Path requested: {$path}");
|
||||||
|
|
||||||
// if this is a POST and we aren't in setup,
|
// if this is a POST and we aren't in setup,
|
||||||
|
@ -13,6 +13,7 @@ class FeedController extends Controller {
|
|||||||
|
|
||||||
public function rss(){
|
public function rss(){
|
||||||
$generator = new RssGenerator($this->config, $this->ticks);
|
$generator = new RssGenerator($this->config, $this->ticks);
|
||||||
|
Log::debug("Generating RSS feed with " . count($this->ticks) . " ticks");
|
||||||
|
|
||||||
header('Content-Type: ' . $generator->getContentType());
|
header('Content-Type: ' . $generator->getContentType());
|
||||||
echo $generator->generate();
|
echo $generator->generate();
|
||||||
@ -20,6 +21,7 @@ class FeedController extends Controller {
|
|||||||
|
|
||||||
public function atom(){
|
public function atom(){
|
||||||
$generator = new AtomGenerator($this->config, $this->ticks);
|
$generator = new AtomGenerator($this->config, $this->ticks);
|
||||||
|
Log::debug("Generating Atom feed with " . count($this->ticks) . " ticks");
|
||||||
|
|
||||||
header('Content-Type: ' . $generator->getContentType());
|
header('Content-Type: ' . $generator->getContentType());
|
||||||
echo $generator->generate();
|
echo $generator->generate();
|
||||||
|
@ -3,6 +3,8 @@ class AtomGenerator extends FeedGenerator {
|
|||||||
public function generate(): string {
|
public function generate(): string {
|
||||||
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||||
$xml .= $this->buildFeed();
|
$xml .= $this->buildFeed();
|
||||||
|
|
||||||
|
Log::debug("Generated Atom feed: " . strlen($xml) . " bytes");
|
||||||
return $xml;
|
return $xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11,6 +13,7 @@ class AtomGenerator extends FeedGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function buildFeed(): string {
|
private function buildFeed(): string {
|
||||||
|
Log::debug("Building Atom feed for " . $this->config->siteTitle);
|
||||||
$feedTitle = Util::escape_xml($this->config->siteTitle . " Atom Feed");
|
$feedTitle = Util::escape_xml($this->config->siteTitle . " Atom Feed");
|
||||||
$siteUrl = Util::escape_xml(Util::buildUrl($this->config->baseUrl, $this->config->basePath));
|
$siteUrl = Util::escape_xml(Util::buildUrl($this->config->baseUrl, $this->config->basePath));
|
||||||
$feedUrl = Util::escape_xml(Util::buildUrl($this->config->baseUrl, $this->config->basePath, 'feed/atom'));
|
$feedUrl = Util::escape_xml(Util::buildUrl($this->config->baseUrl, $this->config->basePath, 'feed/atom'));
|
||||||
|
@ -5,6 +5,8 @@ class RssGenerator extends FeedGenerator {
|
|||||||
$xml .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">' . "\n";
|
$xml .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">' . "\n";
|
||||||
$xml .= $this->buildChannel();
|
$xml .= $this->buildChannel();
|
||||||
$xml .= '</rss>' . "\n";
|
$xml .= '</rss>' . "\n";
|
||||||
|
|
||||||
|
Log::debug("Generated RSS feed: " . strlen($xml) . " bytes");
|
||||||
return $xml;
|
return $xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13,6 +15,7 @@ class RssGenerator extends FeedGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function buildChannel(): string {
|
private function buildChannel(): string {
|
||||||
|
Log::debug("Building RSS channel for " . $this->config->siteTitle);
|
||||||
ob_start();
|
ob_start();
|
||||||
?>
|
?>
|
||||||
<channel>
|
<channel>
|
||||||
|
@ -10,6 +10,7 @@ class Log {
|
|||||||
private static $logFile;
|
private static $logFile;
|
||||||
private static $maxLines = 1000;
|
private static $maxLines = 1000;
|
||||||
private static $maxFiles = 5;
|
private static $maxFiles = 5;
|
||||||
|
private static $routeContext = '';
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
self::$logFile = STORAGE_DIR . '/logs/tkr.log';
|
self::$logFile = STORAGE_DIR . '/logs/tkr.log';
|
||||||
@ -22,6 +23,10 @@ class Log {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function setRouteContext(string $route): void {
|
||||||
|
self::$routeContext = $route ? "[$route]" : '';
|
||||||
|
}
|
||||||
|
|
||||||
public static function debug($message) {
|
public static function debug($message) {
|
||||||
self::write('DEBUG', $message);
|
self::write('DEBUG', $message);
|
||||||
}
|
}
|
||||||
@ -52,7 +57,8 @@ class Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$timestamp = date('Y-m-d H:i:s');
|
$timestamp = date('Y-m-d H:i:s');
|
||||||
$logEntry = "[{$timestamp}] {$level}: " . Util::getClientIp() . " - {$message}\n";
|
$context = self::$routeContext ? ' ' . self::$routeContext : '';
|
||||||
|
$logEntry = "[{$timestamp}] {$level}: " . Util::getClientIp() . "{$context} - {$message}\n";
|
||||||
|
|
||||||
// Rotate if we're at the max file size (1000 lines)
|
// Rotate if we're at the max file size (1000 lines)
|
||||||
if (file_exists(self::$logFile)) {
|
if (file_exists(self::$logFile)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user