Skip to content

Commit

Permalink
Merge pull request #60 from nextcloud/logFolder
Browse files Browse the repository at this point in the history
Use app specific log folder
  • Loading branch information
mario authored May 15, 2017
2 parents 4281845 + b6968bb commit cab91b1
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/com/owncloud/android/lib/common/utils/Log_OC.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.owncloud.android.lib.common.utils;

import android.content.Context;
import android.util.Log;

import java.io.BufferedWriter;
Expand All @@ -18,7 +19,7 @@ public class Log_OC {

private static final String TAG = Log_OC.class.getSimpleName();

private static String mNextcloudDataFolderLog = "nextcloud_log";
private static String mNextcloudDataFolderLog;

private static File mLogFile;
private static File mFolder;
Expand All @@ -29,8 +30,8 @@ public class Log_OC {
private static boolean isMaxFileSizeReached = false;
private static boolean isEnabled = false;

public static void setLogDataFolder(String logFolder){
mNextcloudDataFolderLog = logFolder;
public static String getLogPath() {
return mNextcloudDataFolderLog;
}

public static void i(String TAG, String message){
Expand Down Expand Up @@ -73,30 +74,28 @@ public static void wtf(String TAG, String message) {

/**
* Start doing logging
* @param storagePath : directory for keeping logs
* @param context Context: used for determinated app specific folder
*/
synchronized public static void startLogging(String storagePath) {
String logPath = storagePath + File.separator +
mNextcloudDataFolderLog + File.separator + LOG_FOLDER_NAME;
mFolder = new File(logPath);
synchronized public static void startLogging(Context context) {
mNextcloudDataFolderLog = context.getFilesDir().getAbsolutePath() + File.separator + LOG_FOLDER_NAME;
mFolder = new File(mNextcloudDataFolderLog);
mLogFile = new File(mFolder + File.separator + mLogFileNames[0]);

boolean isFileCreated = false;
boolean isFolderCreated = false;

if (!mFolder.exists()) {
mFolder.mkdirs();
isFileCreated = true;
Log.d(TAG, "Log file created");
isFolderCreated = mFolder.mkdirs();
Log.d(TAG, "Log folder created at: " + mNextcloudDataFolderLog);
} else {
isFolderCreated = true;
}

try {

try {
// Create the current log file if does not exist
mLogFile.createNewFile();
isEnabled = mLogFile.createNewFile();
mBuf = new BufferedWriter(new FileWriter(mLogFile, true));
isEnabled = true;

if (isFileCreated) {
if (isFolderCreated && isEnabled) {
appendPhoneInfo();
}

Expand Down

0 comments on commit cab91b1

Please sign in to comment.