Slog
TS/JS client to server logging. This library is functional, but not actively maintained other than security updates.
Installation
yarn add -D @very-amused/slog
Setup
All configuration for Slog's server is done in slog.config.js
in your project directory. This file is expected to be an ES module, with the config as its default export. The config object should be typed using jsdoc as seen below.
// slog.config.js
/** @type {import('@very-amused/slog').ServerOptions}*/
export default {
certsDir: `${process.env.HOME}/.mycerts/example.tld`
}
Slog's server will only run over HTTPS, and it requires a certificate directory containing a fullchain.pem
and privkey.pem
file, these files containing a TLS certificate chain and private key respectively. This directory is specified using the certsDir
option in slog.config.js
.
Usage
- Start Slog's server.
yarn slog
- Create an Slog client instance in the clientside script you wish to send logs from.
- Use the available
log
,warn
,error
, ordebug
methods on the Slog instance to send logs to the server.
import { SlogClient } from '@very-amused/slog'
/* Slog recommends using Typescript, which will validate the format of client URLs at compile time.
No runtime validation is performed at the moment. */
const slog = new SlogClient(`https://example.tld:${SlogClient.DefaultPort}`)
// Any object can be logged (.toString() is used internally), but console CSS is not supported
slog.log('Important info')
slog.error({ message: 'something went wrong', code: 1 })
- Logs are displayed on the Slog server console.
Caveats
- Unless
useColor
is set tofalse
inslog.config.js
, output will be colorized. A terminal with standard ANSI colors is recommended, output may be difficult to read or understand with custom terminal color themes.