Coder Social home page Coder Social logo

roarr-browser-log-writer's Introduction

Roarr Browser Log Writer

Travis build status Coveralls NPM version Canonical Code Style Twitter Follow

Roarr log writer for use in a web browser.

Chrome Console

Usage

Import the initialization code anywhere in your codebase, e.g.

import {
  createLogWriter,
} from '@roarr/browser-log-writer';

globalThis.ROARR = globalThis.ROARR ?? {};
globalThis.ROARR.write = createLogWriter();

Alternatively, import @roarr/browser-log-writer/init, which is equivalent to the above code.

import '@roarr/browser-log-writer/init';

If you are using Webpack, then consider using lazy loading, e.g.

import('@roarr/browser-log-writer/init');

Displaying Logs

Logs are produced using console.log. However, by default, no logs are printed.

The simplest way to view all logs is to define ROARR_LOG=true localStorage value, i.e.

Type in console localStorage.setItem('ROARR_LOG', 'true') and refresh the page. Now you should see all the logs.

Filtering Logs

By default all logs are displayed. However, you can narrow down logs using a special constant ROARR_FILTER.

The value of ROARR_FILTER is a Liqe query, e.g.

# Only print logs with `context.logLevel` greater than 10.
localStorage.setItem('ROARR_FILTER', 'context.logLevel:>10')

# Only print logs with `context.namespace` containing "slonik".
localStorage.setItem('ROARR_FILTER', 'context.namespace:slonik')

roarr-browser-log-writer's People

Contributors

gajus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

roarr-browser-log-writer's Issues

Customize context format to avoid "cyclic object value"

Hello @gajus,

thanks for your nice work on this lib :)

I try to move my project from debug to Roarr,

but if face an issue with the formatter, i have quite a few complex structure logged, and they crash the app with an error
"cyclic object value".

first, it's a bit sad to the whole app crash in logging, maybe we can be a bit more defensive while logging (like break the logging not the app)

but then we could maybe do like in debug, allow custom formatter for the logged values (%j for example) to customize it

wdyt ?

have pretty print on both browser and server side

I'm using NextJS and want logger to be prettily on both browser and server side,
however I found it a bit difficult to setup.

I'm currently doing something like this

const browserLogWriter = createLogWriter();
const nodeLogWriter = createNodeWriter();

ROARR.write = message => {
    if (typeof window !== 'undefined') {
        browserLogWriter(message);
    } else {
        nodeLogWriter(message);
    }
};

if (typeof window !== 'undefined') {
    localStorage.setItem('ROARR_LOG', 'true');
    localStore.setItem('ROARR_LOG', `context.logLevel:>${LOG_LEVEL}`);
}

is there a better way to use this browser writer without compromising node printing?

Add `peerDependencies` in package.json

The current version of 1.3.0 package.json does not configure peerDependencies, including version control for roarr, I use roarr-browser-log-writer in monorepo automatically depends on a very old version of roarr.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.