initLogger function exported
Last updated: 2026-03-01T23:25:47.125Z
Location
Metrics
LOC: 50
Complexity: 16
Params: 0
Signature
initLogger(): : Promise<void>
Summary
Inicializa o logger lendo as configurações do chrome.storage. Deve ser chamado uma vez no bootstrap de cada contexto (background, content, popup). Se chrome não estiver disponível (ex.: testes unitários), usa os padrões.
Architecture violations
- [warning] max-cyclomatic-complexity: 'initLogger' has cyclomatic complexity 16 (max 10)
Source Code
export async function initLogger(): Promise<void> {
// Initialize the persistent log store
await initLogStore();
if (typeof chrome === "undefined" || !chrome.storage) {
initializing = false;
flushBuffer();
return;
}
const SETTINGS_KEY = "fill_all_settings";
try {
const result = await chrome.storage.local.get(SETTINGS_KEY);
const settings = result[SETTINGS_KEY] as
| { debugLog?: boolean; logLevel?: LogLevel; logMaxEntries?: number }
| undefined;
if (settings) {
const enabled = settings.debugLog ?? false;
configureLogger({
enabled,
// Se debugLog ligado mas logLevel não salvo, assume "debug" — caso contrário "warn"
level: settings.logLevel ?? (enabled ? "debug" : "warn"),
});
configureLogStore({ maxEntries: settings.logMaxEntries ?? 1000 });
}
} catch {
// Silently ignore — logger stays with defaults.
}
// Libera a fila de mensagens acumuladas antes do init terminar.
initializing = false;
flushBuffer();
// Atualiza em tempo real quando as configurações mudarem.
chrome.storage.onChanged.addListener((changes, area) => {
if (area !== "local" || !changes[SETTINGS_KEY]) return;
const newSettings = changes[SETTINGS_KEY].newValue as
| { debugLog?: boolean; logLevel?: LogLevel; logMaxEntries?: number }
| undefined;
if (!newSettings) return;
const enabled = newSettings.debugLog ?? false;
configureLogger({
enabled,
level: newSettings.logLevel ?? (enabled ? "debug" : "warn"),
});
configureLogStore({ maxEntries: newSettings.logMaxEntries ?? 1000 });
});
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| initLogStore | calls |
| flushBuffer | calls |
| configureLogger | calls |
| configureLogStore | calls |
| SETTINGS_KEY | dynamic_call |
Impact (Incoming)
| Source | Type |
|---|---|
| handleMessage | uses |
| FillableElement | uses |
| render | uses |