Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in Ionic2 #3

Open
eoherrer opened this issue Jun 15, 2017 · 2 comments
Open

in Ionic2 #3

eoherrer opened this issue Jun 15, 2017 · 2 comments

Comments

@eoherrer
Copy link

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
Copy link

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

@eoherrer
Copy link
Author

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!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants