0.7.5 • Published 10 months ago

@tycrek/log v0.7.5

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

tlog

NPMCBT badge

My custom logger library

Features

  • 🌈 Colours, timestamps, & labels
  • 🔧 Easily configurable
  • 🔗 Method chaining
  • Utility logs
  • 📝 Comments
  • 🔌 Express.js middleware
  • 🚀 No console wrapping

Installation

Install using npm i @tycrek/log, then load it into your project:

// Import TLog
import { TLog } from '@tycrek/log';
// or
const TLog = require('@tycrek/log');

// Set up a new instance
const logger = new TLog();

// or, set a level
const logger = new TLog('info');

Prints an info log:

logger.info('Hello, hell!');

Methods return the logger instance, allowing for method chaining:

logger
    .warn('Wait, why are we in hell?')
    .debug('Because we\'re not using industry standard logging libs!');

You can configure TLog options with the following methods:

MethodDescription
.setLevel(level)Sets the minimum log level to print.
.setTimestamp({})Enables or disables the timestamp, or configures colour, preset, & format.
.setLabel({})Enables or disables the label, or configures padding, case, & alignment.
.setTitle({})Sets the title delimiter.
.setExtra({})Sets the extra prefix & suffix.
.setComments({})Sets the comment character & colour.

Timestamps use Luxon. To see what options are available for timestamp.preset & timestamp.format, review the Luxon documentation:

General log methods

logger.[level](title, message?, extra?)

Prints a log with the specified level. The title is printed in bold & colour, followed by the message in normal text. If extra is provided, it is printed in italics after the message.

You may pass 1, 2, or 3 parameters to these methods (message; title & message; title, message, & extra).

Possible levels are:

LevelSeverity
debug100
info200
warn300
error400
fatal500

Additional log levels are available for your convenience:

LevelSeverity
utils100
success200
express200

Utility logs

MethodDescription
.pid()Prints the current process ID.
.cwd()Prints the current working directory.
.epoch()Prints the current Unix epoch in milliseconds.
.uptime()Prints the process uptime in seconds.
.comment(message)Prints a comment-like log. Useful for demoing outputs.
.basic(message)Prints a basic log with a timestamp (if enabled).

Invisible utility logs

MethodDescription
.blank()Prints a blank line.
.clear()Clears the console using Unicode escape sequences. May behave differently on different platforms.
.callback(cb)Calls the provided cb function.

Express.js middleware

TLog comes with an included Express middleware. To use it, simply import it & add it to your Express app:

import { TLog } from '@tycrek/log';
import express from 'express';

const logger = new TLog();
const app = express();

app.use(logger.express());
app.get('/', (req, res) => res.send('Hello, world!'));
app.listen(3000);

The middleware is still a bit of a work-in-progress following the TypeScript rewrite, but it should work fine for most use cases.

You can configure the middleware with the following options:

OptionDescription
excludePathsAn array of paths to exclude from logging.
excludeMethodsAn array of HTTP methods to exclude from logging.
trimPathsMust be either false or an Object.
trimPaths.maxLengthAny paths longer than this will be trimmed.
trimPaths.delimiterThe character to use to replace trimmed path segments.
morganModeMimics the behaviour of morgan. Not yet implemented.

🍁 Colours.

Colours. I am Canadian. It is colours. If you don't like it, go fork yourself.

0.7.5

10 months ago

0.7.0-4

11 months ago

0.7.2

10 months ago

0.7.1

11 months ago

0.7.4

10 months ago

0.7.3

10 months ago

0.7.0

11 months ago

0.7.0-3

11 months ago

0.7.0-2

11 months ago

0.7.0-1

11 months ago

0.7.0-0

11 months ago

0.6.0-2

2 years ago

0.6.0-1

2 years ago

0.6.0-0

2 years ago

0.6.0-7

2 years ago

0.6.0-6

2 years ago

0.6.0-5

2 years ago

0.6.0-4

2 years ago

0.6.0-3

2 years ago

0.5.8

3 years ago

0.5.7

3 years ago

0.5.9

3 years ago

0.5.6

3 years ago

0.5.5

3 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.4.2-3

3 years ago

0.5.0

3 years ago

0.4.2-2

3 years ago

0.4.2-1

3 years ago

0.4.2-0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.2.2

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago