Logger ​
Medicus provides robust support for logging during health checks. You can configure custom logger functions to centralize and customize logging for your system.
Error Logger ​
The errorLogger is called whenever an error occurs during health check execution, whether in an automatic background check or during a manual check.
Custom Error Logger ​
The errorLogger receives the error and the name of the checker where it occurred, making it easy to integrate your logging solution.
import { } from 'medicus';
const = new ({
// Custom error handling implementation
(, ) {
.('Health check failed:', , );
}
});Default Error Logger ​
If no custom error logger is provided, Medicus uses a default implementation based on console.error. This is sufficient for development environments but can be replaced with a more robust solution for production.
import { } from 'medicus';
export const : = (
,
) => {
.(`Health check failed for ${}`, );
};Unhealthy Logger ​
The unhealthyLogger is called whenever a health check completes with a non-healthy status (either DEGRADED or UNHEALTHY). This is useful for monitoring and alerting when your system is experiencing issues.
Custom Unhealthy Logger ​
The unhealthyLogger receives the complete health check result, including all service details and the overall status.
import { } from 'medicus';
const = new ({
// Custom unhealthy status handler
() {
.('System health degraded:', {
: .,
: .
});
}
});When is it Called? ​
The unhealthyLogger is triggered after a health check completes if:
- The overall status is
UNHEALTHY, or - The overall status is
DEGRADED
It is not called when the status is HEALTHY.
Use Cases ​
Common use cases for the unhealthy logger include:
- Alerting: Send notifications to your team when services are degraded
- Metrics: Record degraded/unhealthy states to monitoring systems
- Audit trails: Log system health issues for later analysis
- Auto-remediation: Trigger automated recovery actions
import { , } from 'medicus';
const = new ({
() {
// Send alert if system is completely unhealthy
if (. === .) {
.('CRITICAL: System is unhealthy', );
// alertingService.critical('System is unhealthy', details);
}
// Log degraded services for monitoring
if (. === .) {
.('WARNING: System is degraded', .);
// metricsService.recordDegradation(details.services);
}
}
});Integrations ​
Pino ​
Medicus supports integration with Pino, a high-performance JSON logger that can be used for both error logging and unhealthy status logging.
Custom Integrations ​
Do you need to integrate another logging tool or a custom solution? Medicus is designed to be flexible, letting you add your own loggers with ease.
Have a great implementation you’d like to share? Contribute to Medicus by opening a pull request!