anurag008w commited on
Commit
62f946b
Β·
1 Parent(s): c3c95c3

Keep key rotator logs off stdout

Browse files
Files changed (1) hide show
  1. multi-provider-key-rotator.cjs +8 -3
multi-provider-key-rotator.cjs CHANGED
@@ -19,6 +19,11 @@
19
  const http = require('node:http');
20
  const https = require('node:https');
21
 
 
 
 
 
 
22
  // ─── Provider definitions ────────────────────────────────────────────────────
23
  //
24
  // hostname – regex tested against the request hostname (case-insensitive)
@@ -185,7 +190,7 @@ const providerState = PROVIDERS.map(p => {
185
  : normalizeKeys(process.env.LLM_API_KEY || '');
186
 
187
  if (hasDedicated) {
188
- console.log(`[key-rotator] ${p.name}: ${keys.length} key${keys.length === 1 ? '' : 's'}`);
189
  } else if (!keys.length) {
190
  console.warn(`[key-rotator] No keys for provider "${p.name}"`);
191
  }
@@ -202,7 +207,7 @@ const fallbackCount = providerState.filter(p => {
202
  return dedicated.length === 0 && p.keys.length > 0;
203
  }).length;
204
  if (fallbackCount > 0) {
205
- console.log(`[key-rotator] ${fallbackCount} provider(s) using LLM_API_KEY fallback`);
206
  }
207
 
208
  // ─── Runtime helpers ─────────────────────────────────────────────────────────
@@ -332,4 +337,4 @@ patchFetch();
332
  patchHttpModule(http);
333
  patchHttpModule(https);
334
 
335
- console.log('[key-rotator] loaded β€” all providers active');
 
19
  const http = require('node:http');
20
  const https = require('node:https');
21
 
22
+ // This file is preloaded through NODE_OPTIONS, so it also runs inside npm and
23
+ // OpenClaw helper subprocesses that may emit machine-readable JSON on stdout.
24
+ // Keep rotator diagnostics on stderr to avoid corrupting those stdout streams.
25
+ const log = (...args) => console.error(...args);
26
+
27
  // ─── Provider definitions ────────────────────────────────────────────────────
28
  //
29
  // hostname – regex tested against the request hostname (case-insensitive)
 
190
  : normalizeKeys(process.env.LLM_API_KEY || '');
191
 
192
  if (hasDedicated) {
193
+ log(`[key-rotator] ${p.name}: ${keys.length} key${keys.length === 1 ? '' : 's'}`);
194
  } else if (!keys.length) {
195
  console.warn(`[key-rotator] No keys for provider "${p.name}"`);
196
  }
 
207
  return dedicated.length === 0 && p.keys.length > 0;
208
  }).length;
209
  if (fallbackCount > 0) {
210
+ log(`[key-rotator] ${fallbackCount} provider(s) using LLM_API_KEY fallback`);
211
  }
212
 
213
  // ─── Runtime helpers ─────────────────────────────────────────────────────────
 
337
  patchHttpModule(http);
338
  patchHttpModule(https);
339
 
340
+ log('[key-rotator] loaded β€” all providers active');