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

@mycloudlab/escriba-browser

v0.8.16

Published

Log library, for usage on browser and aggregate logs into server and loki dashboard

Downloads

6

Readme

Escriba-Browser

This library is part of the mycloudlab/escriba solution. It serves to collect the logs and send the logging data from the frontend to the backend.

Features

  • Multiple levels of frontend and server logs
  • Multiple transport formats fetch, xhr, websockets
  • Send logs with no blocking Main Thread
  • MDC (mapped diagnostic context) is supported
  • Ignore source map processing in frontend, source maps are processed in backend

Usage

To use the library you can do via unpkg cdn:

<script type="module" src="https://unpkg.com/[email protected]/dist/stacktrace.min.js"></script>
<script type="module" src="https://unpkg.com/@mycloudlab/escriba-browser/dist/escriba.min.mjs"></script>

or use npm install:

npm i @mycloudlab/escriba-browser 

Now it is necessary to initialize Escriba:

import { Escriba, HTTPTransport } from '@mycloudlab/escriba-browser';

const logger = await Escriba.init({
    transport: new HTTPTransport("http://localhost:8888/api/logs")
});

// use 
logger.warn("this a warn log message");
logger.info("this a info log message");
logger.debug("this a debug log message");
logger.error("an error occurred",errorObject);
logger.trace("this a trace log message");

Configure the transport to send the log to the server, modify the server address to the correct address where the service is running: mycloudlab/escriba-server.

config initialization

Escriba is very configurable, below are the possible initialization parameters:

| Parameter name | Description | Options | Default | | ------------------------ | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ | -------------- | | level | Used to determine browser logging level | OFF, ERROR, WARN, INFO, DEBUG, TRACE | LogLevel.TRACE | | enableServerLogging | determines whether logs should be sent to the server | true, false | true | | serverLogLevel | determines what level of logging will be sent to the server | OFF, ERROR, WARN, INFO, DEBUG, TRACE | LogLevel.TRACE | | transport | determines how the log will be sent to the server | NOOPTransport, HTTPTransport, WebSocketTransport | NOOPTransport | | browserErrorHandler | defines whether to manage browser errors globally, defining a Listener in the window.onerror event | true, false | true | | instrumentConsoleLogging | defines whether to override the default console api behavior for the log, error, info, trace, debug, warn functions | true, false | true |

Log Level

Log levels are hierarchical, so when defining:

| Log Level | Hierarchy
| -------------- | -----------------------------------------------------| | OFF | no logs is processed | | ERROR | only error logs is processed | | WARN | error and warn logs is processed | | INFO | error, warn and info logs is processed | | DEBUG | error, warn, info and debug logs is processed | | TRACE | error, warn, info, debug and trace logs is processed |

Transport

Each transport has specific parameters for its correct initialization. Below is a description of each available transport:

NOOPTransport

This transport does not send the message anywhere.

HTTPTransport

The HTTPTransport sends the requests using fetch api, it is necessary to pass the address of the backend api in the constructor.

WebSocketTransport

Websocket transport is being implemented.

Mapped Diagnostic Context (MDC)

Mapped Diagnostic Context provides a way to enrich log messages with information that could be unavailable in the scope where the logging actually occurs but that can be indeed useful to better track the execution of the program.

MDC is introduced to address this gap. This will help developers to store specific information in its internal data structure and append the information to the log as per configuration.

For example, when an error occurs, it can be useful to know which user was logged into the application that the error occurred, or let's say that tracing is being used to track the user's activity, it is useful to add the traceId in the log to correlate the information from trace with the messages in the log.

to use the MDC the escriba provides the following methods:

// put data into mdc context
logger.mdc.set(key: string, value: string);

// unset key in mdc context 
logger.mdc.clear(key: string);

// clear all keys in mdc context
logger.mdc.clearAll();

// retrive data mdc context
logger.mdc.entries();

the information placed in the mdc context is sent for each generated log.

For the information to appear correctly in Loki, it is necessary to configure the promtail to store the information sent via MDC.