Centralized logging with environment-aware filtering and automatic AppInsights integration.
import { logger } from "@/services/loggerService";
logger.debug("Detailed debug info", { operation: "functionName" });
logger.info("General information", { operation: "functionName" });
logger.warn("Warning message", { operation: "functionName" });
logger.error("Error occurred", error, { operation: "functionName" });
logger.trace("Critical business event", { operation: "functionName" });| Level | Use Case | Example |
|---|---|---|
debug |
Detailed debugging, development | "Request payload: {...}" |
info |
General information flow | "User profile loaded" |
warn |
Non-critical issues | "API retry attempt 2/3" |
error |
Errors and exceptions | "Failed to load user data" |
trace |
Critical business events (always logged, wildcard) | "User logged in", "Account switched" |
Log levels have a priority system. Setting LOG_LEVEL enables that level and all higher-priority levels.
Note: trace is a wildcard that always logs regardless of LOG_LEVEL setting.
LOG_LEVEL |
debug |
info |
warn |
error |
trace (wildcard) |
|---|---|---|---|---|---|
| debug | ✅ Console + AppInsights | ✅ Console + AppInsights | ✅ Console + AppInsights | ✅ Console + AppInsights | ✅ Console + AppInsights |
| info (default) | ❌ | ✅ Console + AppInsights | ✅ Console + AppInsights | ✅ Console + AppInsights | ✅ Console + AppInsights |
| warn | ❌ | ❌ | ✅ Console + AppInsights | ✅ Console + AppInsights | ✅ Console + AppInsights |
| error | ❌ | ❌ | ❌ | ✅ Console + AppInsights | ✅ Console + AppInsights |
Always include operation - the only required field:
logger.info("Operation completed", { operation: "loadUserProfile" });
logger.error("Operation failed", error, { operation: "saveSettings" });Optional fields (use sparingly):
{
operation: 'required',
userId: '123', // User identifier (optional)
accountId: '456', // Account identifier (optional)
// Any other relevant data
}Automatic behavior:
- If log level is enabled for environment → logs to both console and AppInsights
warn/error→ sendstrackTraceto AppInsightserrorwith Error object → also sendstrackExceptionto AppInsights- No manual AppInsights calls needed (except for
trackEventfor business metrics)
Use logger.trace() for critical business events:
logger.trace("User logged in", { operation: "login" });
logger.trace("Account switched", { operation: "switchAccount" });Note: trace always logs to console and AppInsights, regardless of LOG_LEVEL configuration. Use it for events you always want to track in production.
Use appInsightsService.trackEvent() for metrics:
appInsightsService.trackEvent({
name: "FeatureUsed",
properties: { feature: "darkMode", enabled: true },
});❌ Don't:
console.log("Something happened"); // Banned by ESLint
console.info("User logged in");
console.error("Error:", error);✅ Do:
logger.trace("User logged in", { operation: "login" });
logger.error("Error occurred", error, { operation: "loadData" });Set log level via LOG_LEVEL environment variable:
debug- All logs (most verbose)info- Info and above (default)warn- Warnings and aboveerror- Errors only (least verbose)
Priority system: Higher log levels include all higher-priority logs. trace is a wildcard that always logs regardless of LOG_LEVEL.
See loggerService.ts for implementation.