1.0.3 • Published 2 years ago

easy-log-report v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

EasyLogReport

npm CI Coverage Status

EasyLogReport is a Typescript library for dealing with log reporting.

Installation

yarn add easy-log-report

or

npm install easy-log-report --save

Usage

Config and Init

Create your Report log by sendBeacon function

import EasyLogReport from 'easy-log-report'
import { SEND_TYPE } from 'easy-log/build/interface'

const easyLogReport = new EasyLogReport({
    acceptEventType: ['onLaunch', 'onLoad', 'onUnload', 'onShow', 'request', 'onError', 'click'],
    sendInterval: 1000 * 30,
    sendQueueSize: 30,
    sendUrl: 'http://localhost:8080/api/log/beacon/',
    sendType: SEND_TYPE.BEACON,
    singleMode: false,
    getCurrentPage: () => window.location.href,
    getInitialEventContent: () => {
        return {
            appInfo: {
                // appID,
                // version,
                // appName,
            },
            systemInfo: {
                ua: navigator.userAgent,
                is_cookie: window.navigator.cookieEnabled ? 1 : 0,
                cookie: document.cookie || '',
                screen_height: window.screen.availHeight,
                screen_width: window.screen.availWidth,
            },
            userInfo: {
                // userId,
                // openId,
            },
        }
    },
})

export default easyLogReport

OR report log by your custom sendFn

import EasyLogReport from 'easy-log-report'

const easyLogReport = new EasyLogReport({
    acceptEventType: ['onLaunch', 'onLoad', 'onUnload', 'onShow', 'request', 'onError', 'click'],
    sendInterval: 1000 * 30,
    sendQueueSize: 30,
    sendFn: e => {
        doReportSend(e)
        console.log('EasyLogReport', e)
    },
    singleMode: false,
    getCurrentPage: () => window.location.href,
    getInitialEventContent: () => {
        return {
            appInfo: {
                // appID,
                // version,
                // appName,
            },
            systemInfo: {
                ua: navigator.userAgent,
                is_cookie: window.navigator.cookieEnabled ? 1 : 0,
                cookie: document.cookie || '',
                screen_height: window.screen.availHeight,
                screen_width: window.screen.availWidth,
            },
            userInfo: {
                // userId,
                // openId,
            },
        }
    },
})

easyLogReport.init(() => {
    console.log('EasyLogReport init!')
})

export default easyLogReport

Record Log

easyLogReport.log({
    eventType: 'onLoad',
    elemId: 'App',
    extraParams: {
        // other extra params
        type: 'onLoad'
    }
})

Config Props

PropertyDescriptionTypeDefault
acceptEventTypelog event types that are allowed to be reportedstring[]'onLaunch', 'onLoad', 'onUnload', 'onShow', 'request', 'onError', 'click'
sendIntervalsend function trigger interval(millisecond)number1000 * 30
sendQueueSizethe maximum number of logs in queuenumber50
singleModeIf it`s singleMode, report log immediately | boolean | false
sendUrlreport urlnumber-
sendTypereporting modeSEND_TYPE.IMG / SEND_TYPE.BEACON-
sendFncustom sendFn, If sendFn is set, sendUrl and sendType would be remove(content: ReportContent) => void-
getCurrentPageget current page route() => string-
getInitialEventContentget the default log content() => InitialReportContent-

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago