You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2018/10/16 14:55:11 UTC
[GitHub] ThibertT opened a new issue #262: Unable to write multiple times in
same file
ThibertT opened a new issue #262: Unable to write multiple times in same file
URL: https://github.com/apache/cordova-plugin-file/issues/262
I am using this plugin to create a log file to log some of my app's logs in order to be able to debug some production errors (a service will email me the logs.txt).
Here is what I was trying to do ti be sure that this plugin is what I was looking for :
- Create a logs.txt in "cordova.file.externalDataDirectory" folder without replace it if already exist (working perfectly)
- Write multiple lines in this logs.txt at multiple times (application lifecycle) (don't work...)
**Here is my testing code :**
```
this.platform.ready().then(() => {
this.file.createFile(cordova.file.externalDataDirectory, 'logs.txt', false).then(() => {
console.log("Create new file logs.txt");
for(let i = 0; i< 10; i ++){
setTimeout(()=>{
this.file.writeFile(cordova.file.externalDataDirectory,'logs.txt','helloWorld'+i+' \n',{ replace: false, append: true }).then(() => {
console.log("Write file OK");
})
.catch((err) => {
console.error("Write file err : " +err);
});
}, 1000);
}
//If file already exist file.createFile() goes here :
}).catch((err) => {
console.log("File logs.txt already exist : " + err);
for(let i = 0; i< 10; i ++){
setTimeout(()=>{
this.file.writeFile(cordova.file.externalDataDirectory,'logs.txt','helloWorld'+i+' \n',{ replace: false, append: true }).then(() => {
console.log("Write file OK");
})
.catch((err) => {
console.error("Write file err : " +err);
});
}, 2000);
}
});;
});
```
In my console output I can see ten "Write file OK", so writes process should be good. I was looking to find ten lines of "helloWorld"+i in the logs.txt file. But no...
Sometimes there is one line, sometimes three lines, sometimes two (never the same).
Should I need to close the file before writing in again ? Documentation on that plugin is quite not explicit and relevant.
Do you know any other plugin that will allow me to create a persistant file and write into it ?
Thank for your help !
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org