Skip to content
This repository has been archived by the owner on Jan 3, 2022. It is now read-only.

Only first log is saved (again) #31

Open
panwauu opened this issue Dec 24, 2021 · 1 comment
Open

Only first log is saved (again) #31

panwauu opened this issue Dec 24, 2021 · 1 comment
Assignees

Comments

@panwauu
Copy link

panwauu commented Dec 24, 2021

I have a weird problem where only the first log is saved to the database. Afterwards no logs are saved.
After 16 logs also my other transport (Console) does not work anymore.

When I try to query it I always get no results (See console output below). The first log is saved so the database does exist and maybe work? I can query the table from psql and there I see more than 10 records.

{ undefined: [ count: 0, command: 'SELECT' ] }

I am glad to deliver more information. I have seen that it should have been fixed in #27
I would also enjoy the typescript pr. It would be great if you could join it.

@ofkindness ofkindness self-assigned this Dec 26, 2021
@ofkindness
Copy link
Owner

@panwauu Yes, I can confirm this behaviour Unfortunately for this time it's more likely issue on a winston level I've found similar issue winstonjs/winston#1757 Unfortunately, this problem can only be solved by re-instantiation.

Here is a working solution for express integration (in conjunction with morgan)

const winston = require('winston');
const PostgresTransport = require('winston-postgres-transport');

const options = {
  level: 'info',
  name: 'Postgres',
  postgresOptions: {
    debug: console.log,
  },
  postgresUrl: 'postgres://winston:[email protected]:5432/winston',
  tableName: 'winston_logs',
};

const logger = () => winston.createLogger({
    level: 'info',
    format: winston.format.json(),
    transports: [new PostgresTransport(options)],
  });

// create a stream object with a 'write' function that will be used by `morgan`
logger.stream = {
    write(message, _encoding) {
    logger().info(message);
  },
};

module.exports = logger;

logger().info(message); will resolve issue in this case

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants