make script stderr print into relay logs
This commit is contained in:
@@ -12,13 +12,14 @@ const rl = readline.createInterface({
|
||||
terminal: false
|
||||
});
|
||||
|
||||
// Log that script started
|
||||
// Log that script started - to both file and stderr
|
||||
fs.appendFileSync(filePath, `${Date.now()}: Policy script started\n`);
|
||||
console.error('[cs-policy] Policy script started');
|
||||
|
||||
// Process each line of input (policy events)
|
||||
rl.on('line', (line) => {
|
||||
try {
|
||||
// Log that we received an event
|
||||
// Log that we received an event (to file)
|
||||
fs.appendFileSync(filePath, `${Date.now()}: Received event: ${line.substring(0, 100)}...\n`);
|
||||
|
||||
// Parse the policy event
|
||||
@@ -27,7 +28,11 @@ rl.on('line', (line) => {
|
||||
// Log event details including access type
|
||||
const accessType = event.access_type || 'unknown';
|
||||
const eventKind = event.kind || 'unknown';
|
||||
fs.appendFileSync(filePath, `${Date.now()}: Event ID: ${event.id || 'unknown'}, Kind: ${eventKind}, Access: ${accessType}\n`);
|
||||
const eventId = event.id || 'unknown';
|
||||
|
||||
// Log to both file and stderr (stderr appears in relay log)
|
||||
fs.appendFileSync(filePath, `${Date.now()}: Event ID: ${eventId}, Kind: ${eventKind}, Access: ${accessType}\n`);
|
||||
console.error(`[cs-policy] Processing event ${eventId.substring(0, 8)}, kind: ${eventKind}, access: ${accessType}`);
|
||||
|
||||
// Respond with "accept" to allow the event
|
||||
const response = {
|
||||
@@ -38,8 +43,9 @@ rl.on('line', (line) => {
|
||||
|
||||
console.log(JSON.stringify(response));
|
||||
} catch (err) {
|
||||
// Log errors
|
||||
// Log errors to both file and stderr
|
||||
fs.appendFileSync(filePath, `${Date.now()}: Error: ${err.message}\n`);
|
||||
console.error(`[cs-policy] Error processing event: ${err.message}`);
|
||||
|
||||
// Reject on error
|
||||
console.log(JSON.stringify({
|
||||
@@ -51,4 +57,5 @@ rl.on('line', (line) => {
|
||||
|
||||
rl.on('close', () => {
|
||||
fs.appendFileSync(filePath, `${Date.now()}: Policy script stopped\n`);
|
||||
console.error('[cs-policy] Policy script stopped');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user