npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

front-logs

v1.0.3

Published

Frontend log engine with ability to send logs to server, auto retry when error occurs, use indexedDB to cache logs and auto resend

Downloads

6

Readme

Front Logs

Frontend log engine with ability to send logs to server, auto retry when error occurs, use indexedDB to cache logs and auto resend

Startup

npm install --save front-logs

To develop, require Node >= 14

Usage

Case

import { LogEngine, LogBean, LogRequest, LogHandler } from 'front-logs'

const engine = new LogEngine() // start log engine

const request = new LogRequest({
  baseDomain: 'http://localhost:3000',
  url: '/push/logs',
  params: { logs: [] }
}) // init log request
engine.setLogRequest(request) // register request as a default request of engine

const handler = new LogHandler()
handler.connect() // connect to log engine

if (!handler.logEngine) return // if connection failed, means engine does not exist and log will not be sent

const log = new LogBean('This is a warning', 'WARN')
handler.appendLog(log) // log
handler.sendLog() // call engine to send log to server

engine.destroy() // call destroy if engine is not used any more for preventing memory leaks

LogEngine

constructor(target: string = '$XFrontLogsEngine') {}

Log engine controls log to send, auto retry, cached using indexedDB and resend

target: indicates where log engine mounts itself, defaults to window.$XFrontLogsEngine

| Method | Arguments | ReturnValue | Description | | --- | --- | --- | --- | | appendLog | LogBean, custom: boolean | void | Append a log to engine, if auto send is not initialed, auto send will start. The second parameter indicates if this log is a custom log | | setSendInterval | interval: number(s) | LogEngine | defaults to 300(s, 5 minutes) | | send | LogRequest | void | Send log immediately if engine is available | | setLogRequest | LogRequest | LogEngine | Set default request of an engine | | destroy | void | void | Destroy an engine instance and cancel all event listeners |

LogHandler

constructor() {}

Log handler proxies log actions to append and send logs wherever

| Method | Arguments | ReturnValue | Description | | --- | --- | --- | --- | | connect | engineTarget | LogHandler | Connect to log engine, any first time you want to use log handler, you should call this method. The engineTarget indicates where to find a log engine instance | | appendLog | message: string, type: string | LogHandler | Append a log to engine | | appendCustomLog | LogBean | LogHandler | Append a custom log to engine | | sendLog | void | LogHandler | Call engine to send log immediately | | setRequest | LogRequest | LogHandler | Set request of handler, if specified, every time use this handler to send log will use this request |

LogBean

constructor(type?: string, message?: string) {}

Class for bearing log content. Auto generate log id and timestamp

| Method | Arguments | ReturnValue | Description | | --- | --- | --- | --- | | toJSON | void | object | Indicates how to transform log into JSON. Defaults to transform log type and message |

For custom log, create a class extends LogBean and overwritten toJSON()

Note: Needn't transform log id and timestamp those are sent automatically

LogRequest

constructor({ baseDomain, url, params }: { baseDomain?: string, url?: string, params?: any }) {}

Log request specifies data while send request

| Method | Arguments | ReturnValue | Description | | --- | --- | --- | --- | | setRequest | {baseDomain?: string, url?: string, params?: any } | LogRequest | Set every parameter of request | | getFullUrl | void | string | Return full url of a request. Equals to baseDomain + url | | getData | void | any | Return data of request. Data will merge data of globalArguments | | setGlobalArguments | { baseDomain, globalData } | void | See detailed Information below |

GlobalArguments

Most cases, there are some public parameters that every request should carry them such as xdaptoken

The reason this project don't use headers for carrying them is for compatible of sendBeacon() which does not support custom request headers

Turn to use setGlobalArguments to set them. For example:

LogRequest.setGlobalArguments({ baseDomain, globalData })

Global Arguments only effects those log request instances constructed after called setGlobalArguments()

Simple Demo

npm run build:demo

Run code above to generate browser.js under public directory and run a web server under this project to access public/index.html

Suggest Live Server which is an extension of VS code editor. In this case, access http://127.0.0.1:5500/public/index.html to see a very simple demo