loggy 2.0.0+1 loggy: ^2.0.0+1 copied to clipboard
Logger for Dart applications, use mixin for easier separation when needed
import 'package:loggy/loggy.dart';
import 'extra_loggers.dart';
import 'socket_level.dart';
void main() {
Loggy.initLoggy(
logPrinter: const PrettyPrinter(),
logOptions: const LogOptions(
LogLevel.all,
stackTraceLevel: LogLevel.error,
),
filters: [
BlacklistFilter([BlacklistedLoggy]),
],
);
ExampleNetworkLoggy();
ExampleUiLoggy();
ExampleBlackListedLoggy();
ExampleWhatLoggyCanDo();
}
class ExampleNetworkLoggy with NetworkLoggy {
ExampleNetworkLoggy() {
loggy.debug('This is log from Network logger');
loggy.info('This is log from Network logger');
loggy.warning('This is log from Network logger');
loggy.error('This is log from Network logger');
loggy.socket('This is log with custom log level in Network logger');
}
}
class ExampleUiLoggy with UiLoggy {
ExampleUiLoggy() {
loggy.warning('This is log from UI logger');
loggy.warning('This is log from UI logger');
loggy.warning('This is log from UI logger');
loggy.warning('This is log from UI logger');
loggy.socket('This is log with custom log level in UI logger');
}
}
class ExampleBlackListedLoggy with BlacklistedLoggy {
ExampleBlackListedLoggy() {
loggy.info('This log is from Blacklisted logger and should not be visible!');
loggy.warning('This log is from Blacklisted logger and should not be visible!');
}
}
class ExampleWhatLoggyCanDo with ExampleLoggy {
ExampleWhatLoggyCanDo() {
/// This will evaluate only if line is actually logged
loggy.info('Loggys can do some stuff:');
loggy.info('You can pass function to the logger, it will evaluate only if log gets shown');
loggy.debug(() {
/// You can log in log
loggy.warning('Using logger inside of the logger #WeNeedToGoDeeper');
/// Do something here maybe? function returning something (list in this case)
const _secret = 0 / 0;
return List.generate(8, (_) => _secret).fold<String>('', (value, e) => value += e.toString()) + ' Batman';
});
final _childLoggy = newLoggy('Test');
/// Changing levels for independent loggy only works if hierarchicalLogging is set to true.
// _logger.level = LogOptions(LogLevel.warning);
_childLoggy.debug(
'I\'m new logger called "${_childLoggy.name}" and my parent logger name is "${_childLoggy.parent!.name}"');
_childLoggy.debug('Even if I\'m a new logger, I still share everything with my parent');
final _detachedLoggy = detachedLoggy('Detached logger');
_detachedLoggy.level = const LogOptions(LogLevel.all);
_detachedLoggy.printer = DefaultPrinter();
_detachedLoggy.debug(
'I\'m a detached logger. I don\'t have a parent and I have no connection or shared info with root logger!');
}
}