andischerer / cordova-plugin-logtofile

Cordova plugin for custom logging to a logfile in the filesystem.
MIT License
16 stars 11 forks source link

in Ionic2 #3

Open eoherrer opened 7 years ago

eoherrer commented 7 years ago

Hi! I try it to use in Ionic2 App, the configure process say's that was configured successfully, but when I trying to use the writing any of the above, It doesn't do anything, doesn't throw any error, and also debug with the Android Studio with Logcat and nothing appears, do you know why??

window.logToFile.debug('Sample debug message'); window.logToFile.info('Sample info message'); window.logToFile.warn('Sample warn message'); window.logToFile.error('Sample error message');

Thanks in advance.

AramVave commented 6 years ago

I am able to write to file but it does not append to an existing file!

eoherrer commented 6 years ago

Hi AramVave! here's my ionic code:

declare var logToFile: any;

initLogToFile(): Promise { //Method to Initialize the LogToFile return new Promise((resolve, reject) => { ///Android/data/com.ups.mobileimaging/logs/log.txt

  this.checkAddPermission()
    .then(granted => {
      if (granted) {
        logToFile.setLogfilePath(`${this.log.filePath}/${this.log.currentFileName}`, function () {
          console.log("LogToFile Configured...");
          resolve(true)
        }, function (err) {
          console.log("LogToFile Error on Configure...: " + err);
          reject(false);
        });
      } else {
        console.log("Permission was not granted, the log will not work");
      }
    })
    .catch(err => {
      console.log("Error on granting permission: " + err);
    });
});

}

checkAddPermission(): Promise { //Method to check permissions in the device return new Promise((resolve, reject) => { let permissions = cordova.plugins.permissions;

  permissions.checkPermission(permissions.WRITE_EXTERNAL_STORAGE, function (status) {
    if (status.hasPermission) {
      console.log("Yes :D ");
      resolve(true);
    }
    else {
      console.log("No :( ");
      permissions.requestPermission(permissions.WRITE_EXTERNAL_STORAGE, function (status) {
        if (status.hasPermission) {
          console.log("Permission is now granted");
          resolve(true);
        } else {
          console.log('Permission is not turned on');
          resolve(false);
        }
      }, function (err) {
        console.log("Error requesting permission :" + err);
        reject(err);
      });
    }
  });
});

}

write(message: string) { //Public Method to call write everywere if (this.settingsService.developerMode) console.log(message);

logToFile.info(message);

}

Regards!!