@very-amused/slog
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

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

  1. Start Slog's server.
yarn slog
  1. Create an Slog client instance in the clientside script you wish to send logs from.
  2. Use the available log, warn, error, or debug 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 })
  1. Logs are displayed on the Slog server console.

Caveats

  1. Unless useColor is set to false in slog.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.

Readme

Keywords

none

Package Sidebar

Install

npm i @very-amused/slog

Weekly Downloads

1

Version

0.5.0

License

MIT

Unpacked Size

32.2 kB

Total Files

15

Last publish

Collaborators

  • very-amused