1.0.13 • Published 1 year ago

@logdoc/node v1.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Node js appender for LogDoc

LogDoc is a system for collecting, analyzing and storing logs.

Logs are sent via the network in any format using any protocol to LogDoc, where they are structured, analyzed and stored.

@logdoc/node

Motivation

LogDoc An open SDK and a simple protocol make it possible to support system formats (Syslog/Journald), industry standards (Java/Python/Go logging), monitoring (collection of metrics), and any proprietary product.

LogDoc uses the ClickHouse database as its main storage, which is great for analytics. But in addition, LogDoc also provides a toolkit for integration with SIEM systems, which allows you to analyze data structures on the fly, without waiting for them to enter the storage, and take appropriate actions earlier.

An important advantage of LogDoc is its flexibility and customizability. Working with data relies on structures rather than search, which significantly speeds up the overall process and allows you to get rigorous results.

By default, LogDoc implements its own role model of users and groups, but can also be integrated with any corporate access control system.

LogDoc supports two types of plug-ins: sink (listening to incoming data) and pipe (reacting to data in structures), which means that it is possible to implement any integration with any information system.

Simple Usage

npm i @logdoc/node
import LogDoc, { Protocol } from '@logdoc/node'
const logger = new LogDoc({ host: "example.host", port: 5555, protocol: Protocol.UDP,, app: 'name app', source: 'source app' })

logger.sendLog({
    msg: "Hello Wordl",
    tsrc: new Date(),
    lvl: "ERROR",
    ip: '234.234.234.23',
    pid: 12,
    src: 'Node src',
    fields: {
        custom: 'odin',
        jios: 'ddd',
        kkssss: 'ndddd'
    }
})

Logger creation parameters.:

NameDefaultDescription
hostexample.hostThe path to the connection host where to raise LogDoc
port5555Port LogDoc
protocoltcpRequired parameter. Enum type. Valid values tcp or udp or http
app | An optional parameter specifying the app name.

A logger accepts the following parameters message:

NameDefaultDescription
msg'info'The message body parameter. Required. If he is not. The message will not be delivered.
tsrcnew Date()Source time, optional
lvlINFORequired parameter. Enum type. Valid values INFO or PANIC or FATAL or ERROR or WARN or DEBUG or ERROR,
ip000.000.000.00An optional parameter specifying the source IP.
pidprocess.pidAn optional parameter specifying the pid of the source
srcos.hostname()Optional parameter
-------------------------------------------------------
fields{}Optional parameter in which you can specify any fields

Working with winston

const winston = require('winston')

const logger = winston.createLogger({
  level: config.env === 'development' ? 'debug' : 'info',
  format: winston.format.combine(
    enumerateErrorFormat(),
    config.env === 'development' ? winston.format.colorize() : winston.format.uncolorize(),
    winston.format.splat(),
    winston.format.printf(({ level, message }) => '{level}: {message}'),
  ),
  transports: [
    new winston.transports.Console({
      stderrLevels: ['error'],
    }),
    new LogdocTransport(),
  ],
})

module.exports = logger
import LogDoc from '@logdoc/node'
import config from './config'

const Transport = require('winston-transport')

const normalizeLog = (level) => {
  if (level.includes('info')) {
    return 'info'
  }
  if (level.includes('panic')) {
    return 'panic'
  }
  if (level.includes('fatal')) {
    return 'fatal'
  }
  if (level.includes('error')) {
    return 'error'
  }
  if (level.includes('warn')) {
    return 'warn'
  }
  if (level.includes('debug')) {
    return 'debug'
  }
  if (level.includes('trace')) {
    return 'trace'
  }
}

class LogDocTransport extends Transport {
  constructor(opts) {
    super(opts)
  }

  log(info, callback) {
    setImmediate(() => {
      this.emit('logged', info)
    })

    const { message } = info
   
    logger.sendLog({
    msg: message,
    tsrc: new Date(),
    lvl: normalizeLog(info.level),
    ip: '234.234.234.23',
    pid: 12,
    src: 'Node src',
    fields: {
        custom: 'odin',
        jios: 'ddd',
        kkssss: 'ndddd'
    }
})

    callback()
  }
}

module.exports = LogDocTransport                              
1.0.11

1 year ago

1.0.10

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.9

1 year ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago