This is a simple yet powerful wrapper around @simplyhexagonal/logger that provides CLI capabilities, including piping the output of a command to the logger:
$ logger.debug This is a debug message
# [2022-01-13T23:54:00.600] DEBUG 🐞️:
#
# This is a debug message
$ uname -a | logger.debug
# [2022-01-13T23:55:01.933Z] DEBUG 🐞️:
#
# Linux 5.11.0-40-generic #44~20.04.2-Ubuntu SMP Tue Oct 26 18:55:01 UTC 2022 x86_64 GNU/Linux
More importantly, configuring transports is supported as well!
We have the following officially supported transports:
This project is open to updates by its users, I ensure that PRs are relevant to the community. In other words, if you find a bug or want a new feature, please help us by becoming one of the contributors ✌️ ! See the contributing section
Please consider:
- Buying me a coffee ☕
- Supporting Simply Hexagonal on Open Collective 🏆
- Starring this repo on Github 🌟
# recommended global install
npm install -g @simplyhexagonal/logger-cli
# or as project dependency
pnpm i @simplyhexagonal/logger-cli
# or
yarn add @simplyhexagonal/logger-cli
# or
npm install @simplyhexagonal/logger-cli
# simply pass your message(s) as arguments
logger.<log-level> <message> [...message]
# or pipe the output of a command to the logger
command | logger.<log-level>
The following log levels are supported:
logger.debug
logger.info
logger.warn
logger.error
logger.fatal
logger.all
logger.raw
By default the logger will be configured to log to the console.
To configure the logger you can use the logger.config
command:
logger.config <config-file>.js
The config file is expected to be a .js
file that exports a config
object, e.g.:
const os = require('os');
module.exports = {
optionsByLevel: {
warn: [], // leaving this array means the logs will output to console
info: [
{
transport: 'discord',
options: {
destination: (process.env.DISCORD_WEBHOOK || ''),
},
},
],
debug: [],
error: [
// you can configure more than one transport per log level
{
transport: 'discord',
options: {
destination: (process.env.DISCORD_WEBHOOK || ''),
},
},
{
transport: 'email',
options: {
destination: (process.env.ERROR_NOTIFICATION_EMAIL || ''),
},
},
],
fatal: [],
all: [],
raw: [],
},
appIdentifiers: {
clusterType: 'TEST',
cluster: 'CI',
hostname: os.hostname(),
app: 'logger-cli',
},
};
This configuration file will be symlinked to ~/.config/logger/logger.config.js
. This means
that everywhere on your system that you logger-cli commands, you will be able to use the same
configuration.
As you can see in the example above, you can also define environment variables and they will be used by @simplyhexagonal/logger-cli.
For more information on the available configuration options, please see @simplyhexagonal/logger.
Yes, thank you! This plugin is community-driven, most of its features are from different authors.
Please update the docs and tests and add your name to the package.json
file.
Thanks goes to these wonderful people (emoji key):
Jean Lescure 🚧 💻 📓 |
Copyright (c) 2022-Present Package Contributors.
Licensed under the Apache License 2.0.