headless-manager-client
v0.1.9
Published
Client to submit logs and events to the Headless Manager
Downloads
2
Readme
Headless Manager Client
Installation
Using Yarn
yarn add headless-manager-client
Or NPM
npm install headless-manager-client
Usage
- Create the logger
// src/util/logger.ts
import Logger from 'headless-manager-client';
import axios from 'axios';
const logger = new Logger({
appId: process.env.HM_APP_ID,
apiUrl: process.env.HM_API_URL,
submitEnabled: process.env.NODE_ENV !== 'development',
// when using server side, also include a fetch client, e.g. node-fetch or axios
fetchInstance: axios,
});
export default logger;
- Start logging
// src/lib/funcName.ts
import logger from '../util/logger';
const myAsyncFunc = async () => {
logger.info('myAsyncFunc', 'Starting some async stuff');
try {
// some async logic
logger.http('myAsyncFunc', 'Successfully did some logic');
} catch (e) {
logger.error('myAsyncFunc', 'Failed the async logic!', e);
}
}
Log levels
- error
- warn
- info
- http
- verbose
- debug
- silly