mirror of
https://github.com/unraid/api.git
synced 2026-01-24 01:18:39 -06:00
36 lines
797 B
TypeScript
36 lines
797 B
TypeScript
/*!
|
|
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
|
|
* Written by: Alexis Tyler
|
|
*/
|
|
|
|
import { Notifier, NotifierOptions, NotifierSendOptions } from './notifier';
|
|
import { log } from '../log';
|
|
|
|
/**
|
|
* Console notifier.
|
|
*/
|
|
export class ConsoleNotifier extends Notifier {
|
|
private readonly log: typeof log;
|
|
|
|
constructor(options: NotifierOptions) {
|
|
super(options);
|
|
|
|
this.level = options.level || 'info';
|
|
this.helpers = options.helpers ?? {};
|
|
this.template = options.template ?? '{{{ json }}}';
|
|
this.log = log;
|
|
}
|
|
|
|
/**
|
|
* Send notification.
|
|
*/
|
|
send(options: NotifierSendOptions) {
|
|
const { title, data } = options;
|
|
const { level, helpers } = this;
|
|
// Render template
|
|
const template = this.render({ ...data }, helpers);
|
|
|
|
this.log[level](title, template);
|
|
}
|
|
}
|