Skip to content

Commit

Permalink
Proper logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose committed Sep 21, 2024
1 parent eb18f18 commit 161ea6b
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kizitonwose.calendar.log

import android.util.Log

internal actual fun log(tag: String, message: String) {
Log.w(tag, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.kizitonwose.calendar.data.checkRange
import com.kizitonwose.calendar.data.getCalendarMonthData
import com.kizitonwose.calendar.data.getMonthIndex
import com.kizitonwose.calendar.data.getMonthIndicesCount
import com.kizitonwose.calendar.log.log
import kotlinx.datetime.DayOfWeek

/**
Expand Down Expand Up @@ -245,7 +246,7 @@ public class CalendarState internal constructor(

private fun getScrollIndex(month: YearMonth): Int? {
if (month !in startMonth..endMonth) {
println("CalendarState - Attempting to scroll out of range: $month")
log("CalendarState", "Attempting to scroll out of range: $month")
return null
}
return getMonthIndex(startMonth, month)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.kizitonwose.calendar.data.checkRange
import com.kizitonwose.calendar.data.getHeatMapCalendarMonthData
import com.kizitonwose.calendar.data.getMonthIndex
import com.kizitonwose.calendar.data.getMonthIndicesCount
import com.kizitonwose.calendar.log.log
import kotlinx.datetime.DayOfWeek

/**
Expand Down Expand Up @@ -218,7 +219,7 @@ public class HeatMapCalendarState internal constructor(

private fun getScrollIndex(month: YearMonth): Int? {
if (month !in startMonth..endMonth) {
println("CalendarState - Attempting to scroll out of range: $month")
log("HeatMapCalendarState", "Attempting to scroll out of range: $month")
return null
}
return getMonthIndex(startMonth, month)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.kizitonwose.calendar.data.getWeekCalendarAdjustedRange
import com.kizitonwose.calendar.data.getWeekCalendarData
import com.kizitonwose.calendar.data.getWeekIndex
import com.kizitonwose.calendar.data.getWeekIndicesCount
import com.kizitonwose.calendar.log.log
import kotlinx.datetime.DayOfWeek
import kotlinx.datetime.LocalDate

Expand Down Expand Up @@ -259,7 +260,7 @@ public class WeekCalendarState internal constructor(

private fun getScrollIndex(date: LocalDate): Int? {
if (date !in startDateAdjusted..endDateAdjusted) {
println("WeekCalendarState - Attempting to scroll out of range; $date")
log("WeekCalendarState", "Attempting to scroll out of range: $date")
return null
}
return getWeekIndex(startDateAdjusted, date)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.kizitonwose.calendar.data.checkRange
import com.kizitonwose.calendar.data.getCalendarYearData
import com.kizitonwose.calendar.data.getYearIndex
import com.kizitonwose.calendar.data.getYearIndicesCount
import com.kizitonwose.calendar.log.log
import kotlinx.datetime.DayOfWeek

/**
Expand Down Expand Up @@ -248,7 +249,7 @@ public class YearCalendarState internal constructor(

private fun getScrollIndex(year: Year): Int? {
if (year !in startYear..endYear) {
println("YearCalendarState - Attempting to scroll out of range: $year")
log("YearCalendarState", "Attempting to scroll out of range: $year")
return null
}
return getYearIndex(startYear, year)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.kizitonwose.calendar.log

internal expect fun log(tag: String, message: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.kizitonwose.calendar.log

import java.util.logging.Level
import java.util.logging.Logger

internal actual fun log(tag: String, message: String) {
logger.warning("$tag : $message")
}

private val logger = Logger.getLogger("Calendar").apply {
level = Level.WARNING
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kizitonwose.calendar.log

import platform.Foundation.NSLog

internal actual fun log(tag: String, message: String) {
NSLog("$tag : $message")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.kizitonwose.calendar.log

internal actual fun log(tag: String, message: String) {
consoleLog("$tag : $message")
}

@JsFun("(output) => console.log(output)")
private external fun consoleLog(vararg output: String?)

0 comments on commit 161ea6b

Please sign in to comment.