Android Open Source - Timetable Logger






From Project

Back to project page Timetable.

License

The source code is released under:

GNU General Public License

If you think the Android project Timetable listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.timetable.android;
//from  w  w w.j a  v  a2s.c o  m
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.acra.ACRA;

import com.timetable.android.utils.DateFormatFactory;
import com.timetable.android.utils.Utils;

import android.util.Log;

/*
 * Class, that helps to log debug and error's information.
 */
public class Logger {
  
  public static final String logTag = "Timetable";
  
  //If set to false, logger will not write anything to logcat.
  public static boolean debugging = false;
  
  //If set to true, report will be send to server, when error is found.
  public static boolean sendReport = true;
  
  //If set to true, addition log to file will be saved.
  public static boolean logToFile = true;
  
  //If set to true, logger has logged error messages.
  private static boolean errorFound = false;
  
  
  private static final String FILE_NAME = "sdcard/Timetable.log";
  
  private static final String ERROR_TAG = "Error";
  
  private static final String DEBUG_TAG = "Debug";
  
  public static void verbose(String message) {
    if (debugging && message != null) {
      Log.v(logTag, message);
      logToFile(DEBUG_TAG, message);
    }
  }
  
  public static void log(String message) {
    if (debugging && message != null) {
      Log.i(logTag, message);
      logToFile(DEBUG_TAG, message);
    }
  }
  
  public static void error(String message) {
    if (debugging && message != null) {
      Log.e(logTag, message);
      logToFile(ERROR_TAG, message);
      errorFound = true;
    }
  }
  
  /*
   * Send ACRA report.
   */
  public static void sendReport() {
    if (debugging && errorFound && sendReport) {
      ACRA.getErrorReporter().handleException(null);
    }
  }
  
  /*
   * Log message to file.
   */
  public static void logToFile(String tag, String message) {
    if (!logToFile) {
      return;
    }
    File logFile = new File(FILE_NAME);
    if (!logFile.exists()) {
          try {
             logFile.createNewFile();
          } 
          catch (IOException e) {
            //Log.e(logTag, e.getMessage());
          //that's bad.
          }
       }
       try {
        String messageToLog = DateFormatFactory.getLongDateTimeFormat().format(Utils.getCurrDateTime());
        messageToLog += "; " + message; 
          //BufferedWriter for performance, true to set append to file flag
          BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); 
          buf.append(messageToLog);
          buf.newLine();
          buf.close();
       }
       catch (IOException e)
       {
         //Log.e(logTag, e.getMessage());
         //that's bad
       }
    }
}




Java Source Code List

com.timetable.android.AlarmSoundPreference.java
com.timetable.android.BroadcastActions.java
com.timetable.android.DeviceMuteService.java
com.timetable.android.EventBroadcastSender.java
com.timetable.android.EventChecker.java
com.timetable.android.EventController.java
com.timetable.android.EventPager.java
com.timetable.android.EventPeriod.java
com.timetable.android.EventService.java
com.timetable.android.EventViewProvider.java
com.timetable.android.EventView.java
com.timetable.android.Event.java
com.timetable.android.IllegalEventDataException.java
com.timetable.android.Logger.java
com.timetable.android.ServiceStarter.java
com.timetable.android.TimetableApp.java
com.timetable.android.TimetableDatabase.java
com.timetable.android.activities.EventAddActivity.java
com.timetable.android.activities.EventCopyActivity.java
com.timetable.android.activities.EventDayViewActivity.java
com.timetable.android.activities.EventEditActivity.java
com.timetable.android.activities.SettingsActivity.java
com.timetable.android.alarm.AlarmDialogActivity.java
com.timetable.android.alarm.AlarmService.java
com.timetable.android.alarm.EventAlarm.java
com.timetable.android.uitests.AlarmDialogActivityTestCase.java
com.timetable.android.uitests.EventAddActivityTestCase.java
com.timetable.android.uitests.TimetableUiTestCase.java
com.timetable.android.utils.DateFormatFactory.java
com.timetable.android.utils.DateUtils.java
com.timetable.android.utils.FakeTimeProvider.java
com.timetable.android.utils.SimpleTimeProvider.java
com.timetable.android.utils.TestAlarmStarter.java
com.timetable.android.utils.TimeProvider.java
com.timetable.android.utils.Utils.java