Skip to content

Commit

Permalink
Convert RNLog to Kotlin
Browse files Browse the repository at this point in the history
Summary:
Convert RNLog to Kotlin

Changelog:
[Internal] [Changed] - Convert RNLog to Kotlin

Reviewed By: mdvacca

Differential Revision: D54010172

fbshipit-source-id: eff124f094248563a2b80575d5ca9e8dae2563f7
  • Loading branch information
cortinico authored and facebook-github-bot committed Feb 24, 2024
1 parent 8bced4b commit 48a7233
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 123 deletions.
16 changes: 8 additions & 8 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -5603,20 +5603,20 @@ public abstract interface class com/facebook/react/util/RCTLog : com/facebook/re
public abstract fun logIfNoNativeHook (Ljava/lang/String;Ljava/lang/String;)V
}

public class com/facebook/react/util/RNLog {
public final class com/facebook/react/util/RNLog {
public static final field ADVICE I
public static final field ERROR I
public static final field INSTANCE Lcom/facebook/react/util/RNLog;
public static final field LOG I
public static final field MINIMUM_LEVEL_FOR_UI I
public static final field TRACE I
public static final field WARN I
public fun <init> ()V
public static fun a (Ljava/lang/String;)V
public static fun e (Lcom/facebook/react/bridge/ReactContext;Ljava/lang/String;)V
public static fun e (Ljava/lang/String;)V
public static fun l (Ljava/lang/String;)V
public static fun t (Ljava/lang/String;)V
public static fun w (Lcom/facebook/react/bridge/ReactContext;Ljava/lang/String;)V
public static final fun a (Ljava/lang/String;)V
public static final fun e (Lcom/facebook/react/bridge/ReactContext;Ljava/lang/String;)V
public static final fun e (Ljava/lang/String;)V
public static final fun l (Ljava/lang/String;)V
public static final fun t (Ljava/lang/String;)V
public static final fun w (Lcom/facebook/react/bridge/ReactContext;Ljava/lang/String;)V
}

public class com/facebook/react/viewmanagers/ActivityIndicatorViewManagerDelegate : com/facebook/react/uimanager/BaseViewManagerDelegate {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.util

import android.util.Log
import com.facebook.common.logging.FLog
import com.facebook.react.bridge.ReactContext
import com.facebook.react.common.ReactConstants

/** Logging wrapper for FLog with LogBox support. */
object RNLog {

const val MINIMUM_LEVEL_FOR_UI = Log.WARN
const val LOG = Log.VERBOSE
const val TRACE = Log.DEBUG
const val ADVICE = Log.INFO
const val WARN = Log.WARN
const val ERROR = Log.ERROR

/**
* Log a log level message tagged as React Native to the console.
*
* @param message The message to log.
*/
@JvmStatic
fun l(message: String) {
FLog.i(ReactConstants.TAG, message)
}

/**
* Log a trace level message tagged as React Native to the console.
*
* @param message The message to log.
*/
@JvmStatic
fun t(message: String) {
FLog.i(ReactConstants.TAG, message)
}

/**
* Log a warning level message tagged as React Native to the console. This warning will not be
* shown in LogBox.
*
* @param message The message to log.
*/
@JvmStatic
fun a(message: String) {
FLog.w(ReactConstants.TAG, "(ADVICE)$message")
}

/**
* Log a warning level message tagged as React Native to the console and display in the app.
*
* @param context The React context of the application use to display the warning.
* @param message The message to log.
*/
@JvmStatic
fun w(context: ReactContext?, message: String) {
logInternal(context, message, WARN)
FLog.w(ReactConstants.TAG, message)
}

/**
* Log an error level message tagged as React Native to the console and display in the app.
*
* @param context The React context of the application use to display the error.
* @param message The message to log.
*/
@JvmStatic
fun e(context: ReactContext?, message: String) {
logInternal(context, message, ERROR)
FLog.e(ReactConstants.TAG, message)
}

/**
* Log an error level message tagged as React Native to the console. This error will not be shown
* in LogBox.
*
* @param message The message to log.
*/
@JvmStatic
fun e(message: String) {
FLog.e(ReactConstants.TAG, message)
}

private fun logInternal(context: ReactContext?, message: String?, level: Int) {
if (level >= MINIMUM_LEVEL_FOR_UI) {
if (context?.hasActiveReactInstance() == true && message != null) {
context.getJSModule(RCTLog::class.java).logIfNoNativeHook(levelToString(level), message)
}
}
}

private fun levelToString(level: Int): String =
when (level) {
LOG,
TRACE -> "log"
ADVICE,
WARN -> "warn"
ERROR -> "error"
else -> "none"
}
}

0 comments on commit 48a7233

Please sign in to comment.