项目作者: fansipanio

项目描述 :
Hapi graylog plugin based on gelf-pro
高级语言: JavaScript
项目地址: git://github.com/fansipanio/hapi-graylog-pro.git
创建时间: 2020-08-27T03:50:09Z
项目社区:https://github.com/fansipanio/hapi-graylog-pro

开源协议:MIT License

下载


hapi-graylog-pro

Introduction

This plugin help HAPI sends logs to Graylog server.

Installation

  • Using npm
    shell script npm install --save hapi-graylog-pro
  • Using yarn
    shell script yarn add hapi-graylog-pro

Usage

Register the plugin with Hapi

  1. server.register(require('hapi-graylog-pro'), (err) => {
  2. if(err) console.log(err)
  3. //...
  4. })

or

  1. server.register([
  2. {
  3. plugin: require('hapi-graylog-pro'),
  4. options: {
  5. // see more in options
  6. }
  7. }
  8. ])

Configuration

  • Simple

    1. {
    2. adapterOptions: {
    3. host: 'my.glog-server.net', // optional; default: 127.0.0.1
    4. port: 12201 // optional; default: 12201
    5. }
    6. }
  • Advanced

    1. {
    2. fields: {facility: "example", owner: "Tom (a cat)"}, // optional; default fields for all messages
    3. filter: [], // optional; filters to discard a message
    4. transform: [], // optional; transformers for a message
    5. broadcast: [], // optional; listeners of a message
    6. levels: {}, // optional; default: see the levels section below
    7. aliases: {}, // optional; default: see the aliases section below
    8. adapterName: 'udp', // optional; currently supported "udp", "tcp" and "tcp-tls"; default: udp
    9. adapterOptions: { // this object is passed to the adapter.connect() method
    10. // common
    11. host: '127.0.0.1', // optional; default: 127.0.0.1
    12. port: 12201, // optional; default: 12201
    13. // ... and so on
    14. // tcp adapter example
    15. family: 4, // tcp only; optional; version of IP stack; default: 4
    16. timeout: 1000, // tcp only; optional; default: 10000 (10 sec)
    17. // udp adapter example
    18. protocol: 'udp4', // udp only; optional; udp adapter: udp4, udp6; default: udp4
    19. // tcp-tls adapter example
    20. key: fs.readFileSync('client-key.pem'), // tcp-tls only; optional; only if using the client certificate authentication
    21. cert: fs.readFileSync('client-cert.pem'), // tcp-tls only; optional; only if using the client certificate authentication
    22. ca: [fs.readFileSync('server-cert.pem')] // tcp-tls only; optional; only for the self-signed certificate
    23. }
    24. }

Levels

  • Default: {emergency: 0, alert: 1, critical: 2, error: 3, warning: 4, notice: 5, info: 6, debug: 7}
  • Example: log.emergency(...), log.critical(...), etc.
  • Custom example: {alert: 0, notice: 1, ...}

Aliases

  • Default: {log: 'debug', warn: 'warning'}
  • Example: log.log(...) -> log.debug(...), log.warn(...) -> log.warning(...), etc.
    Custom example:{red: ‘alert’, yellow: ‘notice’, …}`

To send logs

  • Server log
    1. server.log(['info'], `Server was starting at port ${PORT}`);
  • Request log
    1. request.log(['error'], { foo: 'bar' })

Contributing

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.