Fantastic! Would you mind sharing the code of the AppLoggy
mixin?
It’s really just a getter to service locator to get that logger service, which then adds log to Loggy package.
Note: I experimented with late final AppLoggerService logger
, but while it works it turned out it does not support the mixin being on const classes.
mixin AppLogger {
AppLoggerService get logger => GetIt.I<AppLoggerService>();
static AppLoggerService get instance => GetIt.I<AppLoggerService>();
}
then setup of the Loggy instance is something like this
Loggy.initLoggy(
logPrinter: CombinedLogPrinter(
printers: [
if (AppEnvironment.current.isBugfenderEnabled)
BugfenderLogPrinter(bugfenderFacade: GetIt.I<BugfenderFacade>()),
if (AppEnvironment.current.isCrashlyticsEnabled)
LogGroup(
logKeys: FirebaseKeysHandler(crashlyticsFacade: GetIt.I<FirebaseCrashlyticsFacade>()),
logPrinter: FirebaseLogPrinter(crashlyticsFacade: GetIt.I<FirebaseCrashlyticsFacade>()),
),
if (AppEnvironment.current.isConsoleLoggingEnabled) PrettyConsoleLogPrinter(),
if (AppEnvironment.current.isSeqEnabled) SeqLogPrinter(seqFacade: GetIt.I<SeqFacade>()),
],
),
)
And again, those classes like CombinedLogPrinter, BugfenderLogPrinter, FirebaseLogPrinter are shared, just the platform connection to i.e. crashlytics is added using the facade. (so we dont have to have firebase etc. as dependency of the shared package, and rather apps should decide what and which version to use)
And these our shared printers basically just format message for given logging service and also parse error if that is using our interface etc.
And CombinedLogPrinter
is basically a printer for Loggy package that accepts our printers (we decided to abstract those so we can build list of printers in our app rather than having wired up printers in the shared package between all of those apps.