Skip to content

Commit c8c57f4

Browse files
committed
refactor(logging): add explicit category handling and align clientDebug facilities (user for UI/AJAX, daemon for cron)
1 parent 3ef12e2 commit c8c57f4

10 files changed

Lines changed: 198 additions & 187 deletions

File tree

source/compose.manager/compose.manager.settings.page

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,27 +2141,27 @@ $acePath = file_exists('/usr/local/emhttp/plugins/dynamix/javascript/ace/ace.js'
21412141
for (var i = 0; i < allowed.length; i++) {
21422142
var cfg = <?= json_encode($cfg); ?>;
21432143
var showCompose = (cfg['SHOW_COMPOSE_IN_HEADER_MENU'] || '').toString().toLowerCase();
2144-
composeClientDebug('Checking referrer path ' + ref.pathname + ' against allowed path ' + allowed[i] + ' with showCompose=' + showCompose, null, 'debug', 'daemon');
2144+
composeClientDebug('Checking referrer path ' + ref.pathname + ' against allowed path ' + allowed[i] + ' with showCompose=' + showCompose, null, 'user', 'debug', 'settings');
21452145
if (existingPath && existingPath.toLowerCase() === '/docker' && showCompose === 'true') {
2146-
composeClientDebug('Referrer is /Docker and showCompose is true, returning /Compose', null, 'warn', 'daemon');
2146+
composeClientDebug('Referrer is /Docker and showCompose is true, returning /Compose', null, 'user', 'warn', 'settings');
21472147
return '/Compose' + (ref.search || '');
21482148
} else if (existingPath && existingPath.toLowerCase() === '/compose' && showCompose === 'false') {
2149-
composeClientDebug('Referrer is /Compose and showCompose is false, returning /Docker', null, 'warn', 'daemon');
2149+
composeClientDebug('Referrer is /Compose and showCompose is false, returning /Docker', null, 'user', 'warn', 'settings');
21502150
return '/Docker' + (ref.search || '');
21512151
}
21522152
if (p.toLowerCase() === allowed[i].toLowerCase()) {
2153-
composeClientDebug('Referrer matches allowed path ' + allowed[i], null, 'debug', 'daemon');
2153+
composeClientDebug('Referrer matches allowed path ' + allowed[i], null, 'user', 'debug', 'settings');
21542154
return ref.pathname + (ref.search || '');
21552155
}
21562156
if (allowed[i].toLowerCase().endsWith('/') && p.toLowerCase().startsWith(allowed[i].toLowerCase())) {
2157-
composeClientDebug('Referrer matches allowed path prefix ' + allowed[i], null, 'debug', 'daemon');
2157+
composeClientDebug('Referrer matches allowed path prefix ' + allowed[i], null, 'user', 'debug', 'settings');
21582158
return ref.pathname + (ref.search || '');
21592159
}
21602160
}
2161-
composeClientDebug('Referrer path ' + ref.pathname + ' does not match any allowed paths', null, 'warn', 'daemon');
2161+
composeClientDebug('Referrer path ' + ref.pathname + ' does not match any allowed paths', null, 'user', 'warn', 'settings');
21622162
return null;
21632163
} catch (e) {
2164-
composeClientDebug('Error parsing referrer URL: ' + e.message, null, 'error', 'daemon');
2164+
composeClientDebug('Error parsing referrer URL: ' + e.message, null, 'user', 'error', 'settings');
21652165
return null;
21662166
}
21672167
}

source/compose.manager/include/AutoUpdate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
}
154154
// Security: validate path is under allowed directories
155155
if (!isAllowedAutoUpdatePath($path)) {
156-
clientDebug("[autoupdate] Rejected invalid path: " . sanitizeLogText($path), null, 'daemon', 'error');
156+
clientDebug('Rejected invalid path: ' . sanitizeLogText($path), null, 'user', 'error', 'autoupdate');
157157
http_response_code(403);
158158
echo json_encode(array('error' => 'Path not allowed'));
159159
break;
@@ -176,7 +176,7 @@
176176
$projectName = preg_replace('/[^A-Za-z0-9_\-]/', '_', $projectName);
177177
}
178178

179-
clientDebug("[autoupdate] Running manual auto-update for: $projectName", null, 'daemon', 'info');
179+
clientDebug("Running manual auto-update for: $projectName", null, 'user', 'info', 'autoupdate');
180180

181181
$script = $plugin_root . "scripts/compose_autoupdate.sh";
182182
// Allow overriding the shell command via environment for tests; default to sh

source/compose.manager/include/AutoUpdateRunner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
// Validate path is within allowed locations for security
5151
if (!isAllowedAutoUpdatePath($path)) {
52-
clientDebug("[autoupdate] Skipping disallowed path: " . sanitizeLogText($path), null, 'daemon', 'warn');
52+
clientDebug('Skipping disallowed path: ' . sanitizeLogText($path), null, 'daemon', 'warn', 'autoupdate');
5353
continue;
5454
}
5555

@@ -109,7 +109,7 @@
109109
}
110110

111111
// Log the scheduled auto-update trigger
112-
clientDebug("[autoupdate] Scheduled auto-update triggered for: $projectName ($schedule)", null, 'daemon', 'info');
112+
clientDebug("Scheduled auto-update triggered for: $projectName ($schedule)", null, 'daemon', 'info', 'autoupdate');
113113

114114
$script = $plugin_root . "scripts/compose_autoupdate.sh";
115115
// Allow overriding the shell command via environment for tests; default to sh

source/compose.manager/include/BackupFunctions.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function applyRetentionPolicy($destination)
123123
foreach ($toDelete as $archive) {
124124
$filePath = $destination . '/' . $archive['filename'];
125125
@unlink($filePath);
126-
logger("Retention: deleted old backup " . $archive['filename']);
126+
clientDebug("Retention: deleted old backup " . $archive['filename'], null, 'daemon', 'info', 'backup');
127127
}
128128
}
129129
}
@@ -336,17 +336,6 @@ function formatBytes($bytes)
336336
return $bytes . ' B';
337337
}
338338

339-
/**
340-
* Log a message to syslog with compose.manager tag.
341-
* Guarded to avoid redeclaration when Helpers.php is also loaded.
342-
*/
343-
if (!function_exists('logger')) {
344-
function logger($message)
345-
{
346-
exec("logger -t 'compose.manager' " . escapeshellarg("[backup] " . $message));
347-
}
348-
}
349-
350339
/**
351340
* Resolve the full path to an archive given a filename.
352341
* Looks in the optional directory first, then configured destination, falls back to the provided path.

0 commit comments

Comments
 (0)