Coder Social home page Coder Social logo

winston-mysql's People

Contributors

charles-zh avatar mhoffmeyerdc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

winston-mysql's Issues

suggested feature

Hi,

I made some changes to match my use which I hope others may find useful:

I needed a small addition...to add a column telling me which env the code is running in:

 CREATE TABLE IF NOT EXISTS sys_logs_default (
 id INT NOT NULL AUTO_INCREMENT,
 env VARCHAR(100) default 0,
 level VARCHAR(16) NOT NULL,
 message VARCHAR(2048) NOT NULL,
 meta VARCHAR(2048) NOT NULL,
 timestamp DATETIME NOT NULL,
 PRIMARY KEY (id));

so I tweaked the class to serve my needs
example use:

var ip = require("ip");
....
  const myFormatter = format((info) => {
    info.env = ip.address()
    return info;
  })();

...
  const SqlLogger = createLogger({
...
  format: combine(timestamp(), errors({ stack: true }), myFormatter, json()),
...
    new winstonMysql({
      host: process.env.DB_HOST,
      user: process.env.DB_USER,
      password: process.env.DB_PASSWORD,
      database: 'logging_nodejs',
      table: 'sys_logs_default',
      charset: 'utf8_general_ci',
      fields: { env: 'env', level: 'level', meta: 'meta', message: 'message', timestamp: 'timestamp' }
    })
...

in contructor - I allowed for semi-custom table structure thus allowing more columns to be used defined by user.

  if (!options.fields) {
      this.options.fields = {};
      //use default names
      this.fields = {
        level: 'level',
        meta: 'meta',
        message: 'message',
        timestamp: 'timestamp'
      }
    } else {
      //use custom table field names
      const { level, meta, message, timestamp } = this.options.fields;
      this.fields = {
        // for custome fields
        ...this.options.fields,
        level,
        meta,
        message,
        timestamp
      }
    }
 const log = {};
        log[this.fields.meta] = JSON.stringify(winstonMeta);
        log[this.fields.level] = level;
        log[this.fields.message] = message;
        log[this.fields.timestamp] = new Date();

        for (const key in info) {
          if (!['meta', 'level', 'message', 'timestamp'].includes(key) && this.fields.hasOwnProperty(key)) {
            log[key] = info[key]
          }
        }

I'd be happy to open a PR if the author finds these changes of interest.

script keeps running and is not ending

I used the example code in the installation guide and everything works as expected but the script is not ending and keeps running.

grafik

When commenting out this part below nothing is really happening, but the script ends. So it has something to do with the actual logger function.

logger.debug(msg, {message: msg, type: 'demo'});
logger.error(msg, {message: msg, type: 'demo'});
logger.info(msg, {message: msg, type: 'demo'});
logger.warn(msg, {message: msg, type: 'demo'}); 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.