0 purchases
proxima logger
Easy to use, customizable, expandable logger that prints beautiful logs.
π Proxima Logger is a logging package for your Flutter/Dart app that is easy to use and customize.
π¨ It offers a range of options and styles to customize your logs to your heartβs desire. You can print out debug messages and add some color to your logs to make them stand out.
π Proxima Logger is also highly extensible, allowing you to send your logs to a remote server for safekeeping and output logs from popular HTTP clients such as Dio.
π Plus, it has no dependencies, meaning it wonβt add any extra weight to your app or introduce any additional vulnerabilities.
Getting started #
Add package to the project:
dart pub add proxima_logger
copied to clipboard
Create an instance of Proxima Logger. You can set general settings for logging, including the order in which parts of the log are output, the style of the borders, and more if you like.
final logger = ProximaLogger(
settings: (logType) => switch (logType) {
Log.debug => const LogSettings(
logParts: [
LogPart.stack,
LogPart.message,
],
logDecorations: LogDecorations.rounded(),
),
Log.error => const LogSettings(
logDecorations: LogDecorations.thick(),
),
Log.wtf || Log.nothing => const LogSettings(
logDecorations: LogDecorations.thin(),
),
_ => const LogSettings(
logParts: [
LogPart.stack,
LogPart.error,
LogPart.time,
LogPart.divider,
LogPart.message,
],
printEmoji: true,
printTitle: true,
printLogTypeLabel: true,
),
}
);
copied to clipboard
Usage #
Use logger.log() or logger.info, logger.warning, logger.wtf, etc. anywhere in the program.
logger.log(
Log.info,
title: 'Log title',
);
logger.debug(message: 'Debug message');
try {
//...
} catch (e, s) {
logger.error(
title: 'Some error',
error: e,
stack: s,
);
}
copied to clipboard
Notes #
To handle errors automatically, add runZonedGuarded() to main().
void main() {
bool recordError(Object error, StackTrace stackTrace) {
logger.log(Log.error, error: error, stack: stackTrace);
return true;
}
void recordFlutterError(FlutterErrorDetails error) {
logger.log(Log.error, error: error, stack: error.stack);
}
FlutterError.onError = recordFlutterError;
PlatformDispatcher.instance.onError = recordError;
runApp(const MyApp());
}
copied to clipboard
You can write your own wrapper over the logger to quickly use the required logging types and conveniently log requests from an http client, such as Dio.
class MyLogger extends ProximaLoggerBase {
MyLogger({
super.settings,
super.typeSettings,
super.formatter,
super.decorator,
super.output,
});
void info(String message) {
log(Log.info, message: message);
}
void error(Error error, StackTrace stack, [String? message]) {
log(Log.error, error: error, stack: stack, message: message);
}
void response(Response response) {
log(
Log.response,
title:
'| ${response.requestOptions.method} | ${response.statusCode} | ${response.requestOptions.path}',
message: response.data,
);
}
}
copied to clipboard
If necessary, you can implement the LogType class and create your own log types.
enum Log implements ILogType {
custom(
label: 'custom',
emoji: 'π¦',
ansiPen: AnsiPen.purple(),
);
@override
final String label;
@override
final String emoji;
@override
final AnsiPen ansiPen;
@override
final AnsiPen ansiPenOnBackground;
const Log({
required this.label,
required this.emoji,
required this.ansiPen,
this.ansiPenOnBackground = const AnsiPen.black(),
});
}
copied to clipboard
Output #
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.