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.
yarn add logtowa-client
npm install logtowa-client
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.
logger.info('Hello world.');
logger.log('info', 'Hello world.');
logger.info('User signed in.', { name: 'Tobias', age: 24 });
logger.log('info', 'User signed in.', { name: 'Tobias', age: 24 });
logger.scope('db');
logger.debug('Initializing DB connection...');
logger.info('Initialization successful.');
logger.unscope();
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();