Warner Examples
Real-world examples and common patterns for using Warner in your applications.
Build System Warnings
Track warnings during a build process:
ts
import { Warner } from "@briklab/lib/warner";
class BuildSystem {
private warner: Warner;
constructor() {
this.warner = new Warner({
level: "summary",
packageName: "BuildSystem"
});
}
compile(files: string[]): void {
files.forEach(file => {
if (file.includes("deprecated")) {
this.warner.warn({
message: `Deprecated syntax in ${file}`,
source: "compiler",
hint: "Update to modern syntax"
});
}
});
}
reportResults(): void {
this.warner.finalize();
}
}
const build = new BuildSystem();
build.compile(["utils.ts", "deprecated-lib.ts"]);
build.reportResults();Data Migration Warnings
Monitor warnings during data processing:
ts
import { Warner } from "@briklab/lib/warner";
const warner = new Warner({
level: "full",
packageName: "DataMigration"
});
const records = [
{ id: 1, name: "Alice" },
{ id: 2 }, // Missing name
{ id: 3, name: "Charlie" }
];
records.forEach((record, i) => {
if (!record.name) {
warner.warn({
message: `Record ${i} missing required field: name`,
source: "migration",
level: "warn",
hint: `Set default name or skip record`
});
}
});
warner.finalize();API Client Warnings
Track API deprecations and issues:
ts
import { Warner } from "@briklab/lib/warner";
class ApiClient {
private warner: Warner;
constructor() {
this.warner = new Warner({
level: "summary",
packageName: "ApiClient"
});
}
callEndpoint(endpoint: string, version: number): void {
if (version < 3) {
this.warner.warn({
message: `Using deprecated API version ${version}`,
source: endpoint,
hint: `Upgrade to API v3 or higher`
});
}
}
report(): void {
this.warner.finalize();
}
}
const client = new ApiClient();
client.callEndpoint("/users", 1);
client.callEndpoint("/posts", 2);
client.report();Live Demo - Real-world Warnings
Console
No logs yet.
Configuration Validation with Warnings
Warn on suboptimal configuration:
ts
import { Warner } from "@briklab/lib/warner";
interface AppConfig {
debug: boolean;
logLevel: string;
cacheSize: number;
timeoutMs: number;
}
function validateConfig(config: AppConfig): void {
const warner = new Warner({
level: "full",
packageName: "ConfigValidator"
});
if (config.debug && config.logLevel !== "debug") {
warner.warn({
message: "Debug enabled but log level not set to debug",
hint: "Set logLevel: 'debug' for better debugging"
});
}
if (config.cacheSize > 1000) {
warner.warn({
message: "Cache size is very large",
hint: "Consider reducing for lower memory usage"
});
}
if (config.timeoutMs < 100) {
warner.warn({
message: "Timeout is very short",
hint: "May cause premature connection drops"
});
}
warner.finalize();
}
const config: AppConfig = {
debug: true,
logLevel: "info",
cacheSize: 2000,
timeoutMs: 50
};
validateConfig(config);Testing with Warner
Use Warner in test assertions:
ts
import { Warner } from "@briklab/lib/warner";
class TestRunner {
warnings: number = 0;
runTests(): void {
const warner = new Warner({
level: "silent"
});
// Run tests...
warner.warn({ message: "Test suite warning 1" });
warner.warn({ message: "Test suite warning 2" });
this.warnings = 2; // Track count
}
assert(): void {
if (this.warnings > 0) {
console.log(`Tests passed with ${this.warnings} warnings`);
}
}
}
const runner = new TestRunner();
runner.runTests();
runner.assert();Next Steps
- Advanced Usage: Complex patterns
- Getting Started: Back to basics