logtowa-client
v1.0.5
Published
Minimal client for LogTowa
Downloads
3
Readme
LogTowa Client
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();