Code Monkey home page Code Monkey logo

logtowa-client's Introduction

LogTowa Client

Quality Gate Status Maintainability Rating Security Rating Vulnerabilities Bugs Duplicated Lines (%)

This package provides a minimal client for LogTowa providing a console logger and an interface to log to the LogTowa cloud.

LogTowa is a simple self hosted service which helps you keeping track of your logs in a simple and clear web UI.

Installation

Yarn

yarn add logtowa-client

NPM

npm install logtowa-client

Usage

import { LogTowaClient } from 'logtowa-client';

// This information can be found in the web UI
const HOST = 'https://your-api-endpoint';
const API_TOKEN = 'your-api-token';
const APP_KEY = 'app-key';

const logger = new LogTowaClient({
  level: 'verbose', // the minimum level to log; if undefined, all levels will be logged; default: undefined
  console: {
    enabled: true, // enable/disable console logging; default: true
    level: 'verbose', // the minimum level to log; if undefined, all levels will be logged; default: undefined
    timestamps: true, // enable/disable timestamps in console logs; default: true
  },
  cloud: {
    enabled: true,  // enable/disable console logging; default: true
    level: 'verbose', // the minimum level to log; if undefined, all levels will be logged; default: undefined
    host: HOST,
    token: API_TOKEN,
    appKey: APP_KEY,
  }
});

There are several ways how you can log a message. You can add metadata which provides more information about the log. You can also add a scope (e.g. "db" for all database related logs, "auth" for all authentication related logs). The scope allows you to easily filter the logs in the web UI.

Basic Log Message

logger.info('Hello world.');
logger.log('info', 'Hello world.');

Log Message with metadata

logger.info('User signed in.', { name: 'Tobias', age: 24 });
logger.log('info', 'User signed in.', { name: 'Tobias', age: 24 });

Log Messages with scope

logger.scope('db');
logger.debug('Initializing DB connection...');
logger.info('Initialization successful.');
logger.unscope();

Send a single message with a given scope

logger.scope('db');
logger.debug('Initializing DB connection...');

logger.scoped('other scope').info('Info log with other scope.');
// OR
logger.info('Info log with other scope.', { scope: 'other scope' });
logger.scoped('other scope').info('Info log with another scope.', { scope: 'another scope' }); // meta scope will overwrite other scopes

logger.info('Initialization successful.');
logger.unscope();

logtowa-client's People

Contributors

tobiaswaelde avatar

Watchers

 avatar

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.