Skip to content

Commit

Permalink
Merge branch 'release/v2.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmarban committed Aug 6, 2019
2 parents 6a46130 + 644f480 commit dd65611
Show file tree
Hide file tree
Showing 5 changed files with 383 additions and 254 deletions.
43 changes: 43 additions & 0 deletions lib/winston-telegram.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import TransportStream from "winston-transport"

declare class WinstonTelegram extends TransportStream {
constructor(options: WinstonTelegram.Options)
}

declare namespace WinstonTelegram {
export interface Options {
/** The Telegram bot authentication token. */
token: string
/** The chatid you want to send to. */
chatId: number
/** Level of messages that this transport should log. (default "info") */
level?: string
/** Handle uncaught exceptions. (default false) */
handleExceptions?: boolean
/** Whether to log only the declared level and none above. (default false) */
unique?: boolean
/** Whether to suppress output. (default false) */
silent?: boolean
/** Sends the message silently. (default false) */
disableNotification?: boolean
/** ? (default "winston-telegram") */
name?: string
/** Format output message. (default "[{level}] [message]") */
template?: string
/** Format output message by own method. */
formatMessage?: (params: WinstonTelegram.FormatOptions) => string
/** Time in ms within which to batch messages together. (default = 0) (0 = disabled) */
batchingDelay?: number
/** String with which to join batched messages with (default "\n\n") */
batchingSeparator?: string
}

export interface FormatOptions {
level: string,
message: string,
metadata: any
}

}

export default WinstonTelegram
14 changes: 7 additions & 7 deletions lib/winston-telegram.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Transport = require('winston-transport')

/**
* @constructs
* @param {Object} options - Options
* @param {object} options - Options.
* @param {string} options.token - Telegram bot authentication token.
* @param {string} options.chatId - Telegram unique identifier for chat.
* @param {string} [options.level='info'] - Level of messages that this transport should log.
Expand All @@ -20,8 +20,8 @@ const Transport = require('winston-transport')
* @param {boolean} [options.silent=false] - Whether to suppress output.
* @param {boolean} [options.disableNotification=false] - Sends the message silently.
* @param {string} [options.name='winston-telegram'] - Logger's name.
* @param {Object} [options.template='[{level}] {message}'] - Format output message based on named arguments.
* @param {function} [options.formatMessage] - Format output message by own method.
* @param {object} [options.template='[{level}] {message}'] - Format output message based on named arguments.
* @param {Function} [options.formatMessage] - Format output message by own method.
* @param {number} [options.batchingDelay=0] - Time in ms within which to batch messages together.
* @param {string} [options.batchingSeparator='\n\n'] - String with which to join batched messages with.
*/
Expand Down Expand Up @@ -61,12 +61,12 @@ module.exports = class Telegram extends Transport {
* @returns {undefined}
*/
log (info, callback) {
let self = this
const self = this

if (this.unique && this.level !== info.level) return callback(null, true)

let messageText = null
let formatOptions = {
const formatOptions = {
level: info.level,
message: info.message,
metadata: info.metadata
Expand All @@ -83,7 +83,7 @@ module.exports = class Telegram extends Transport {

if (!this.batchingTimeout) {
this.batchingTimeout = setTimeout(function () {
let combinedMessages = self.batchedMessages.join(self.batchingSeparator)
const combinedMessages = self.batchedMessages.join(self.batchingSeparator)
self.send(combinedMessages)
self.batchedMessages = []
self.batchingTimeout = 0
Expand All @@ -104,7 +104,7 @@ module.exports = class Telegram extends Transport {
* @private
*/
send (messageText) {
let self = this
const self = this

const requestData = JSON.stringify({
chat_id: this.chatId,
Expand Down
Loading

0 comments on commit dd65611

Please sign in to comment.