mirror of
https://github.com/cmclark00/RetroMusicPlayer.git
synced 2025-05-17 15:45:21 +01:00
refactor: Simplify Cast server logging to use Android Log only
- Removed file-based logging from CastServerUtils - Removed context initialization requirement from CastServerUtils - All logs now go to Android's logcat system for easier debugging
This commit is contained in:
parent
b6eab9d651
commit
3fe1823e1f
2 changed files with 0 additions and 36 deletions
|
@ -1,16 +1,10 @@
|
|||
package code.name.monkey.retromusic.cast
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
import java.net.ServerSocket
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
object CastServerUtils {
|
||||
private const val TAG = "CastServer"
|
||||
private const val LOG_FILE_NAME = "cast_server.log"
|
||||
|
||||
fun isPortAvailable(port: Int): Boolean {
|
||||
return try {
|
||||
|
@ -34,35 +28,9 @@ object CastServerUtils {
|
|||
|
||||
fun logInfo(message: String) {
|
||||
Log.i(TAG, message)
|
||||
writeToLogFile("INFO", message)
|
||||
}
|
||||
|
||||
fun logError(message: String) {
|
||||
Log.e(TAG, message)
|
||||
writeToLogFile("ERROR", message)
|
||||
}
|
||||
|
||||
private fun writeToLogFile(level: String, message: String) {
|
||||
try {
|
||||
val logDir = File(context.getExternalFilesDir(null), "logs")
|
||||
if (!logDir.exists()) {
|
||||
logDir.mkdirs()
|
||||
}
|
||||
|
||||
val logFile = File(logDir, LOG_FILE_NAME)
|
||||
val timestamp = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US).format(Date())
|
||||
|
||||
FileWriter(logFile, true).use { writer ->
|
||||
writer.append("$timestamp [$level] $message\n")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to write to log file: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var context: Context
|
||||
|
||||
fun init(appContext: Context) {
|
||||
context = appContext.applicationContext
|
||||
}
|
||||
}
|
|
@ -37,10 +37,6 @@ class RetroWebServer(val context: Context) : NanoHTTPD(findAndInitializePort())
|
|||
}
|
||||
}
|
||||
|
||||
init {
|
||||
CastServerUtils.init(context)
|
||||
}
|
||||
|
||||
override fun start() {
|
||||
try {
|
||||
super.start()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue