This source file includes following definitions.
- isEnableLogOnDisk
- setEnableLogOnDisk
- setLogFile
- onCreate
- onDestroy
- onLog
- doLog
- getLoggedLevel
- setLoggedLevel
- getDefaultLoggedLevel
- setDefaultLoggedLevel
package com.gpac.Osmo4.logs;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Date;
import java.util.SortedSet;
import java.util.TreeSet;
import android.util.Log;
import com.gpac.Osmo4.GpacCallback.GF_Log_Module;
import com.gpac.Osmo4.GpacConfig;
public class GpacLogger {
public GpacLogger(GpacConfig gpacConfig) {
loggedModules.add(GF_Log_Module.GF_LOG_AUDIO);
loggedModules.add(GF_Log_Module.GF_LOG_MEDIA);
loggedModules.add(GF_Log_Module.GF_LOG_MODULE);
loggedModules.add(GF_Log_Module.GF_LOG_CORE);
logDir = gpacConfig.getGpacLogDirectory();
}
private boolean enableLogOnDisk = false;
public synchronized boolean isEnableLogOnDisk() {
return enableLogOnDisk;
}
public synchronized void setEnableLogOnDisk(boolean enableLogOnDisk) {
this.enableLogOnDisk = enableLogOnDisk;
}
private String logDir;
private String logFile;
public synchronized void setLogFile(String logFile) {
writer = null;
this.logFile = logDir + logFile;
}
public void onCreate() {
if (!enableLogOnDisk)
return;
if (writer == null) {
try {
writer = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File(logFile)), 128), true, "UTF-8");
} catch (Exception e) {
Log.e(GpacLogger.class.getSimpleName(), "Failed to create writer", e);
}
}
if (writer != null)
writer.println("New log $Revision$ at " + new Date());
}
public void onDestroy() {
if (!enableLogOnDisk)
return;
PrintStream w = this.writer;
writer = null;
if (w != null) {
w.println("Closing log file at " + new Date());
w.close();
}
}
public void onLog(int level, int module, String message) {
GF_Log_Module gModule = GF_Log_Module.getModule(module);
doLog(gModule, level, message);
}
private void doLog(GF_Log_Module module, int level, String message) {
Log.println(4, module.name(), message);
if (enableLogOnDisk) {
PrintStream s = writer;
if (s != null) {
s.println(module.name() + "\t" + message);
s.flush();
}
}
}
private final SortedSet<GF_Log_Module> loggedModules = new TreeSet<GF_Log_Module>();
private int loggedLevel = Log.DEBUG;
private int defaultLoggedLevel = Log.INFO;
public synchronized int getLoggedLevel() {
return loggedLevel;
}
public synchronized void setLoggedLevel(int loggedLevel) {
this.loggedLevel = loggedLevel;
}
public synchronized int getDefaultLoggedLevel() {
return defaultLoggedLevel;
}
public synchronized void setDefaultLoggedLevel(int defaultLoggedLevel) {
this.defaultLoggedLevel = defaultLoggedLevel;
}
private volatile PrintStream writer;
}