README
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-logger
2. 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:
date
DateTime of the when the log was createdcategory
What grouping of logs this falls underdescription
What happened? For example, the Logout button brought the user to the AreYouSure pagejsonOne
Field for dumping information. Ordered by priority.jsonTwo
Field for dumping information.jsonThree
Field for dumping information.jsonFour
Field for dumping information.additionalInfo
Field for dumping information.userName
User 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:
Uuid
Unique device identifiermanufacturer
Manufacturer of the device e.g. 'Apple'brand
The brand of the device e.g. 'Apple/htc'model
The model of the device e.g. 'iPhone 5'deviceId
The device's id or for Android the board e.g. 'iPhone 6' or 'goldfish'systemName
The operating system name e.g. 'iOS'systemVersion
The numbered version of the operating system e.g. '4.4.2'bundleId
Namespace of the bundle e.g. 'com.example.mobileapp'buildNumber
Version of the application on the phone e.g. '1.1.0.40'userAgent
Combined information of current OS user.userName
User's usernamelocale
Locale set in the operating system e.g. en-UStimeZone
Current time of the userappInEmulator
Is the application running inside of an emulator?pinOrFingerprintSet
Is 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:
apiKey
Uuid that authenticates the SDK for every API callsessionId
Uuid that lives for the lifetime of the applicationsdkVersion
Version of the SDK itselfapplicationVersion
Version 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);