ant-lab-logger-test v0.0.43
Ant Lab Logger
The Anthroware Laboratory (Ant Lab) Logger is a node framework to log information to a self hosted or Anthroware hosted external API.
Dependencies
- jest - We use Jest as our primary testing framework
- axios - For any network calls, Axios is used
- axios-mock-adapter - Mocking Axios requests when testing
- flow - Static type checking
Logger
1. Installation
Install the library using npm.
npm install --save ant-lab-logger2. Initialize the SDK
The SDK needs to be initialized. It will also fetch the logging level from the API.
Logger.Init ( apiToken, metaInfo, deviceInfo )3. Log using the SDK
The SDK exposes the Logger.debug( logInfo, metaInfo, deviceInfo ) method for sending off debug level logs to the webservice.
Models
Log
Log object sent to the API resource.
Fields:
dateDateTime of the when the log was createdcategoryWhat grouping of logs this falls underdescriptionWhat happened? For example, the Logout button brought the user to the AreYouSure pagejsonOneField for dumping information. Ordered by priority.jsonTwoField for dumping information.jsonThreeField for dumping information.jsonFourField for dumping information.additionalInfoField for dumping information.userNameUser who owns the information inside the application
Type information:
Log: {
date: Date,
category: string,
description: string,
jsonOne: Object,
jsonTwo: Object,
jsonThree: Object,
jsonFour: Object,
additionalInfo: string,
username: string,
}Device Info
Device specific information. Currently using react-native-device-infofor fetching the information. Implementation may vary depending on how and what information is fetched.
Fields:
UuidUnique device identifiermanufacturerManufacturer of the device e.g. 'Apple'brandThe brand of the device e.g. 'Apple/htc'modelThe model of the device e.g. 'iPhone 5'deviceIdThe device's id or for Android the board e.g. 'iPhone 6' or 'goldfish'systemNameThe operating system name e.g. 'iOS'systemVersionThe numbered version of the operating system e.g. '4.4.2'bundleIdNamespace of the bundle e.g. 'com.example.mobileapp'buildNumberVersion of the application on the phone e.g. '1.1.0.40'userAgentCombined information of current OS user.userNameUser's usernamelocaleLocale set in the operating system e.g. en-UStimeZoneCurrent time of the userappInEmulatorIs the application running inside of an emulator?pinOrFingerprintSetIs the pin or fingerprint set for the user?
Type information:
DeviceInfo: {
uuid: string,
manufacturer: string,
brand: string,
model: string,
deviceId: string,
systemName: string,
systemVersion: string,
bundleId: string,
buildNumber: string,
userAgent: string,
locale: string,
timeZone: string,
appInEmulator: boolean,
pinOrFingerprintSet: boolean,
}MetaInfo
Information about the application, SDK, and current user.
Fields:
apiKeyUuid that authenticates the SDK for every API callsessionIdUuid that lives for the lifetime of the applicationsdkVersionVersion of the SDK itselfapplicationVersionVersion of the application that is consuming the SDK
Type information:
MetaInfo: {
apiKey: string,
sessionId: string,
sdkVersion: string,
applicationVersion: string,
}Example Usage
Ths example imports the logger, initialize with an Api Token and logs a debug log.
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View } from 'react-native';
import Logger from './log/resource/Logger';
export default class logger extends Component {
render() {
var deviceInfo = {
Uuid: 'sample string 1',
Manufacturer: 'sample string 2',
Brand: 'sample string 3',
Model: 'sample string 4',
DeviceId: 'sample string 5',
SystemName: 'sample string 6',
SystemVersion: 'sample string 7',
BundleId: 'sample string 8',
BuildNumber: 'sample string 9',
UserAgent: 'sample string 10',
Locale: 'sample string 11',
TimeZone: 'sample string 12',
AppInEmulator: true,
PinOrFingerprintSet: true,
};
const metaInfo = {
apiKey: 'sample string 1',
sessionId: 'sample string 2',
sdkVersion: 'sample string 3',
applicationVersion: 'sample string 6',
};
const log = {
date: new Date(),
category: 'sample string 1',
description: 'sample string 2',
jsonOne: { k: 100 },
jsonTwo: { k: 100 },
jsonThree: { k: 100 },
jsonFour: { k: 100 },
additionalInfo: 'sample string 3',
userName: 'sample string 4',
};
Logger.init('apitoken', metaInfo, deviceInfo);
Logger.debug(log, metaInfo, deviceInfo)
.then(success => {
console.log('success', success);
})
.catch(e => {
console.log('error', e);
});
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('logger', () => logger);