Closed vinaypwheelocity closed 1 year ago
Hi, it seems that you have not provided a custom filter, by default the DevelopmentFilter
is used which by design doesn't log in release mode.
You can change that by providing the following to your logger:
Logger(
filter: ProductionFilter(),
// ...
)
Hi, it seems that you have not provided a custom filter, by default the
DevelopmentFilter
is used which by design doesn't log in release mode. You can change that by providing the following to your logger:Logger( filter: ProductionFilter(), // ... )
Even if the code is modified, the log cannot be written to the file in release mode, but it can be written to the file normally in debug mode. Method to reproduce this problem: package a release mode apk file and install the apk on the phone. The log cannot be written to the file.
Even if I use the following code, it doesn't work
class MyFilter extends LogFilter {
@override
bool shouldLog(LogEvent event) {
return true;
}
}
Hi @zzdota, I tried to reproduce your problem but wasn't able to identify any issues.
I created a FileOutput with a File in the ApplicationDocumentsDirectory
, used the ProductionFilter
and tried it in debug and release mode, as well as in an emulator and a real device (Android).
In every case, it successfully created the file with the proper log output.
Test Code:
late File logFile;
Directory applicationDir = await getApplicationDocumentsDirectory();
logFile = File("${applicationDir.path}${Platform.pathSeparator}test.log");
// ...
static final Logger log = Logger(
filter: ProductionFilter(),
output: !kIsWeb
? MultiOutput([
Logger.defaultOutput(),
FileOutput(file: logFile),
])
: Logger.defaultOutput(),
);
Hi @zzdota, I tried to reproduce your problem but wasn't able to identify any issues.
I created a FileOutput with a File in the
ApplicationDocumentsDirectory
, used theProductionFilter
and tried it in debug and release mode, as well as in an emulator and a real device (Android). In every case, it successfully created the file with the proper log output.Test Code:
late File logFile; Directory applicationDir = await getApplicationDocumentsDirectory(); logFile = File("${applicationDir.path}${Platform.pathSeparator}test.log"); // ... static final Logger log = Logger( filter: ProductionFilter(), output: !kIsWeb ? MultiOutput([ Logger.defaultOutput(), FileOutput(file: logFile), ]) : Logger.defaultOutput(), );
First of all, I admit that you are right, flutter build --release
, this way of debugging a mobile phone with a data cable is normal;
However, if you use flutter build apk
to package the apk, install the apk on your phone, and then run this application, this application uses the logger library to print logs and store the logs in files, something will appear. The log is not written to the file,
Hi @zzdota, again, I tried to reproduce it and couldn't find any problem. I built the APKs (release and debug), transferred them over to the phone, installed them manually and the log file was created just fine in both modes.
Another question, as the device file explorer isn't available for release builds, how do you check if the file exists? And in which location are you trying to save it?
Hi @zzdota, again, I tried to reproduce it and couldn't find any problem. I built the APKs (release and debug), transferred them over to the phone, installed them manually and the log file was created just fine in both modes.
Another question, as the device file explorer isn't available for release builds, how do you check if the file exists? And in which location are you trying to save it?
So, If
the device file explorer isn't available for release builds
how can you be sure that
the log file was created just fine in both modes.?
Is the device need to be root?
So, If
the device file explorer isn't available for release builds
how can you be sure that
the log file was created just fine in both modes.?
Is the device need to be root?
Hi @magic3584, my app tells me that. I just coded a simple file check that tells me if the log file exists and what its content is. Yeah, a rooted phone would work too.
@Bungeefan Thanks guy, I have written a demo and you are right.
Code :