rn-imx-logger
v1.0.21
Published
Imaxeam logger for react-native
Downloads
9
Maintainers
Readme
IMX LOGGER FOR REACT NATIVE APP
Installation
Step1
yarn add rn-imx-logger sp-react-native-mqtt
or
npm install rn-imx-logger sp-react-native-mqtt --save
Step 2
under android/app/build.gradle add this lines of code :
android {
configurations{
all*.exclude module: 'conceal'
all*.exclude module: 'bcprov-jdk15on'
}
//The rest of the android code
}
Usage
import { imxRNLogger } from "rn-imx-logger";
const option = {
clientId: new Date().getTime().toString(),
uri: "mqtt://localhost:1883",
tls: false,
auth: true,
user: "user",
pass: "password",
};
const topicName = "logs"
const appName= "example_app_name"
const loggingStatus = {
enableDebug: true,
enableError: true
}
const callBacks = {
onConnectCallBack: () => console.log("Connected"),
onCloseCallBack() {
console.log("Diconnected");
},
onErrorCallBack:(msg) => console.log("error ", msg),
onMessageCallBack(msg) {
console.log("message ", msg);
},
}
useEffect(() => {
imxRNLogger.createMqttConnection(option,topicName,appName,loggingStatus,callBacks );
return () => {
imxLogger.disconnect()
};
}, []);
// send DEBUG logs
imxRNLogger.debug({
appName: "app_example",
context: "context_example1",
message: "message_example",
user?: "user_example",
extra?: any
})
// send ERROR logs
imxRNLogger.error({
appName: "app_example",
context: "context_example1",
message: "message_example",
user?: "user_example",
extra?: any
})
//getMqttConnection
imxRNLogger.getMqttConnection()
//connect
imxRNLogger.connect()
//Disconnect
imxRNLogger.disconnect()
//Set app name
imxRNLogger.setAppName("Hello world !")
// Check is Connected
imxRNLogger.isConnected()
//Reconnect
imxRNLogger.reconnect()
//Enable DEBUG logging
imxRNLogger.enableDebugLogging()
//Enable ERRORS logging
imxRNLogger.enableErrorLogging()
// Disable DEBUG Logging
imxRNLogger.disableDebugLogging()
// Disable ERROR Logging
imxRNLogger.disableErrorLogging()
// Check Error logging status
imxRNLogger.checkErrorLoggingStatus()
// Check DEBUG logging status
imxRNLogger.checkDebugLoggingStatus()
// check Logging enable or not
imxRNLogger.checkIsEnaled() // return {
// errorLoggingStatus: bool,
// debugLoggingStatus: bool,
// }
API
createClient(options, onCloseCallBack,onErrorCallBack,onMessageCallBack,onConnectCallBack)
create new client instance withoptions
, async operationuri
:protocol://host:port
, protocol is [mqtt | mqtts]host
: ipaddress or host name (override by uri if set)port
: port number (override by uri if set)tls
: true/false (override by uri if set to mqtts or wss)user
: string usernamepass
: string passwordauth
: true/false - override = true Set to true ifuser
orpass
existclientId
: string client idkeepalive
connect()
connect from the connection created to MQTTdisconnect()
disconnect from the connection created to MQTTgetMqttConnection()
get all the connectionObjectdebug({message: string, context: string,appName: string, user?: string})
: send logs as DEBUGerror({message: string, context: string,appName: string, user?: string})
: send logs as ERRORisConnected()
return Booleanreconnect()
reconnect from the connection created to MQTTon(event, callback)
: add event listener for- event:
connect
- client connected - event:
closed
- client disconnected - event:
error
- error - event:
message
- message object
- event:
enableErrorLogging()
to enable error loggingenableDebugLogging()
to enable debugloggingdisableErrorLogging()
to disable error loggingdisableDebugLogging()
to disable debug loggingcheckDebugLoggingStatus()
to check the debug logging statuscheckErrorLoggingStatus()
to check the error logging statuscheckIsEnaled()
to check the logging status of error and debugsetAppName()
to set the app name sending in logs