I want to release my Flutter app and I want to find a way to disable all logs in my app
late Logger logger;
void main() async {
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
await initializeDependencies();
logger = Logger(
printer: PrettyPrinter(
methodCount: 0,
errorMethodCount: 0,
lineLength: 150,
colors: true,
printEmojis: true));
runApp(const MyApp());
}
2
Answers
While there isn’t a direct way to accomplish this, here’s what you can do:
Log statement know looks like : –
It seems you want to disable the logs in the release mode. In this case, you don’t have to worry about it.
The default
filter
of TheLogger
behaves as only logging in debug mode. Citing from the documentation:The default value of the
filter
parameter would beDevelopmentFilter
, which means:However, you can create a custom filter (for whatever reason, such as hiding logs based on their levels). Citing from the documentation:
And interestingly, it’s mentioned that:
which is exactly what you want to avoid according to what you are looking for!