getAlias static method
Gets the alias for a logger provider type.
Extracts the alias by removing the "LoggerProvider" suffix from the type name. If the type doesn't follow the naming convention, returns null.
Examples:
- ConsoleLoggerProvider returns "Console"
- DebugLoggerProvider returns "Debug"
- MyCustomProvider returns null
Implementation
static String? getAlias(Type providerType) {
final typeName = providerType.toString();
// Check if type follows the *LoggerProvider pattern
if (typeName.endsWith('LoggerProvider')) {
// Extract the prefix before "LoggerProvider"
final alias = typeName.substring(
0,
typeName.length - 'LoggerProvider'.length,
);
// Return alias only if it's not empty
return alias.isNotEmpty ? alias : null;
}
return null;
}