This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | private fun writeLog(logFile: File, log: String) { | |
| val writer = FileWriter(logFile, true) | |
| writer.append(log) | |
| writer.flush() | |
| writer.close() | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class CrashlyticsLogTree(private val firebaseCrashlytics: FirebaseCrashlytics) : Timber.Tree() { | |
| override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { | |
| if (t != null) { | |
| firebaseCrashlytics.recordException(CrashlyticsNonFatalError("$tag : $message", t)) | |
| } else { | |
| firebaseCrashlytics.log("$priority/$tag: $message") | |
| } | |
| } | |
| class CrashlyticsNonFatalError constructor(message: String, cause: Throwable) : | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | val reportFile = generateReportFile(context) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package com.canopas.nolonely.utils.log | |
| import android.util.Log | |
| import timber.log.Timber | |
| import java.io.ByteArrayOutputStream | |
| import java.io.File | |
| import java.io.FileOutputStream | |
| import java.io.FileWriter | |
| import java.io.IOException | |
| import java.io.RandomAccessFile | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | @Throws(IOException::class) | |
| fun zip(files: List<String>, zipFile: File) { | |
| var origin: BufferedInputStream | |
| val outputStream = ZipOutputStream(BufferedOutputStream(FileOutputStream(zipFile))) | |
| outputStream.use { out -> | |
| val data = ByteArray(4096) | |
| for (i in files.indices) { | |
| val fi = FileInputStream(files[i]) | |
| origin = BufferedInputStream(fi) | |
| try { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | @Throws(IOException::class) | |
| private fun ensureLogSize(logFile: File) { | |
| if (logFile.length() < maxLogSize) return | |
| // We remove first 25% part of logs | |
| val startIndex = logFile.length() / 4 | |
| val randomAccessFile = RandomAccessFile(logFile, "r") | |
| randomAccessFile.seek(startIndex) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | private fun writeLog(logFile: File, log: String) { | |
| val writer = FileWriter(logFile, true) | |
| writer.append(log) | |
| writer.flush() | |
| writer.close() | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | private fun getPriorityString(priority: Int): String { | |
| return when (priority) { | |
| Log.VERBOSE -> "VERBOSE" | |
| Log.DEBUG -> "DEBUG" | |
| Log.INFO -> "INFO" | |
| Log.WARN -> "WARN" | |
| Log.ERROR -> "ERROR" | |
| Log.ASSERT -> "ASSERT" | |
| else -> "" | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | private fun generateLog(priority: Int, tag: String?, message: String): String { | |
| val logTimeStamp = dateFormat.format(Date()) | |
| return StringBuilder().append(logTimeStamp).append(" ") | |
| .append(getPriorityString(priority)).append(": ") | |
| .append(tag).append(" - ") | |
| .append(message).append('\n').toString() | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | private val maxLogSize = 5 * 1024 * 1024 // 5 MB | |
| private val dateFormat = SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS", Locale.US) | |
| override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { | |
| if (priority >= Log.DEBUG) { | |
| val log = generateLog(priority, tag, message) | |
| if (!logFile.exists()) { | |
| logFile.createNewFile() | |
| } | |
| writeLog(logFile, log) | 
NewerOlder