createLogger() is a utility that helps create standardized, tagged logger instances using Consola. It provides a consistent way to create loggers across our libraries with proper naming and optional custom configuration, making debugging and monitoring more effective.
import { createLogger } from '@nobears-front-end/utils';
// Create a basic tagged logger
const logger = createLogger('MyModule');
// Create a logger with custom options
const logger = createLogger('AuthService', {
level: 2,
fancy: true
});
Creates a tagged Consola logger instance with optional custom configuration.
| Prop | Default | Type |
|---|---|---|
name* | stringA tag name that identifies the logger | |
options | LoggerOptionsOptional configuration including Consola options and fancy mode |
Extended options for the logger, allowing standard Consola options plus an optional fancy flag.
| Prop | Default | Type |
|---|---|---|
fancy | booleanEnables fancy output for custom formatting/themes | |
level | numberLog level (0: silent, 1: fatal, 2: error, 3: warn, 4: log, 5: info, 6: success, 7: debug, 8: trace) | |
formatOptions | ConsolaFormatOptionsFormatting options for log messages | |
transport | LogType | LogObject | LogFnCustom transport for log messages |
import { createLogger } from '@nobears-front-end/utils';
const logger = createLogger('MyModule');
logger.info('Application started');
logger.warn('Deprecated feature used');
logger.error('Something went wrong');
logger.debug('Debug information');
import { createLogger } from '@nobears-front-end/utils';
const logger = createLogger('AuthService', {
level: 2, // Only show fatal and error logs
fancy: true
});
logger.error('Authentication failed');
logger.fatal('Critical security breach');
import { createLogger } from '@nobears-front-end/utils';
class UserService {
private logger = createLogger('UserService');
async createUser(userData: UserData) {
this.logger.info('Creating new user', { email: userData.email });
try {
const user = await this.createUserInDatabase(userData);
this.logger.success('User created successfully', { userId: user.id });
return user;
} catch (error) {
this.logger.error('Failed to create user', { error, email: userData.email });
throw error;
}
}
}
import { createLogger } from '@nobears-front-end/utils';
// Create loggers for different parts of your application
export const authLogger = createLogger('Auth', { level: 4 });
export const dbLogger = createLogger('Database', { level: 5 });
export const apiLogger = createLogger('API', { level: 5 });
// Use in different modules
authLogger.info('User authenticated');
dbLogger.debug('Database query executed');
apiLogger.warn('Rate limit approaching');