Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Logger for output logs to another terminal or file #603

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

EpicDima
Copy link
Contributor

@EpicDima EpicDima commented Jan 3, 2025

Solution for #494

Counter with logs
@file:JvmName("Main")

package example

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.jakewharton.mosaic.Logger
import com.jakewharton.mosaic.runMosaicBlocking
import com.jakewharton.mosaic.ui.Text
import kotlin.jvm.JvmName
import kotlinx.coroutines.delay

@Composable
fun Counter() {
	var count by remember { mutableIntStateOf(0) }

	Text("The count is: $count")

	LaunchedEffect(Unit) {
		for (i in 1..20) {
			delay(250)
			Logger.d { "Counter: $i" } // <-- log
			count = i
		}
	}
}

fun main() = runMosaicBlocking {
	Counter()
}
Result Screenshot 2025-01-03 at 03 39 34

The video demo is below in the comments - #603 (comment)


  • CHANGELOG.md's "Unreleased" section has been updated, if applicable.

Comment on lines 9 to 12
public enum class LogLevel(internal val envVarValue: String) {
VERBOSE(envVarValue = "verbose"),
DEBUG(envVarValue = "debug"),
}
Copy link
Contributor Author

@EpicDima EpicDima Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the logging levels and which ones are needed, especially considering the needs of the library and the needs of library users, as well as the use cases of each of the levels.

@EpicDima
Copy link
Contributor Author

EpicDima commented Jan 3, 2025

Added this to the demo sample in the TerminalInfo function:

LaunchedEffect(screenSize) {
    Logger.d { "Demo - terminal size: ${screenWidth}x${screenHeight}" }
}
Result (720p compressed video due to 10MB file size limits)
logger_demo_720.1.mov

This is a demo sample with animations that I did not attach in the mosaic-animation pull request (#600 (comment)), I am correcting myself here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant