Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Use the application's structured logger instead of console.*
In apps that provide a structured/leveled logger, route all logs through it rather than console.log/console.error so output is leveled, formatted, and centrally configurable.
Bad example
| 1 | // Bypasses the app's logger: no level, no context, no transport config |
| 2 | this.cache.set(key, value, ttl).catch(console.error); |
Explanation (EN)
console.error ignores the application's logging configuration — log level, formatting, context labels, and transports (file, JSON, log aggregation) are all lost.
Objašnjenje (HR)
console.error ignorira konfiguraciju logiranja aplikacije — razina logiranja, formatiranje, kontekstne oznake i transporti (datoteka, JSON, agregacija logova) se gube.
Good example
| 1 | this.cache |
| 2 | .set(key, value, ttl) |
| 3 | .catch((err) => this.logger.error(`Failed to cache value: ${err.message}`, err.stack)); |
Explanation (EN)
Using the injected/structured logger keeps the message at the right level with stack context and routes it through the same transports as the rest of the app's logs.
Objašnjenje (HR)
Koristenje strukturiranog/injektiranog loggera drzi poruku na ispravnoj razini s kontekstom stacka i salje je kroz iste transporte kao i ostatak logova aplikacije.
Exceptions / Tradeoffs (EN)
Quick local debugging scripts, build tooling, or code that runs before the logger is initialized may legitimately use console.*.
Iznimke / Tradeoffi (HR)
Brze lokalne debug skripte, build alati ili kod koji se izvrsava prije inicijalizacije loggera mogu legitimno koristiti console.*.