question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: New level option

See original GitHub issue

Thanks for providing this fantastic module.

Would be great to know if is possible to consider a new level option in order to segregate logs per level. Like in the standard Winston File transport:

new transports.File({ filename: 'error.log', level: 'error' })

Thank you!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
mattberthercommented, Dec 31, 2019

This should already work - please re-open if you find it does not.

var winston = require('winston');
require('winston-daily-rotate-file');

var transport = new winston.transports.DailyRotateFile({
    filename: './logs/application-%DATE%',
    level: 'error'
});

var logger = winston.createLogger({
    transports: [
        transport
    ]
});

logger.error("This will log to the winston-daily-rotate-file transport.");
logger.info("This will not log to the winston-daily-rotate-file transport.");
0reactions
mattberthercommented, May 12, 2020

I must be missing something here - the following code works as expected here. Can you please try this and let me know if you see similar results?

~/projects/winstonjs/winston-daily-rotate-file master*
❯ cat level-test.js
var winston = require('winston');
require('winston-daily-rotate-file');

const dailyErrors = new winston.transports.DailyRotateFile({
    level: 'error',
    filename: 'errors-%DATE%.log',
    format: winston.format.combine(winston.format.timestamp({
        format: 'MM/DD/YYYY HH:mm:ss'
    }), winston.format.errors({
        stack: true
    }), winston.format.printf(function(info) {
        return `${info.timestamp} ${info.level}: ${info.message}\n${info.stack}`;
    }))
});

const logger = winston.createLogger({
    transports: [dailyErrors]
});

logger.error("This will log to the winston-daily-rotate-file transport.", new Error('testing'));
logger.info("This will not log to the winston-daily-rotate-file transport.");

~/projects/winstonjs/winston-daily-rotate-file master*
❯ rm errors-2020-05-12.log&& node level-test.js

~/projects/winstonjs/winston-daily-rotate-file master*
❯ cat errors-2020-05-12.log
05/12/2020 17:26:31 error: This will log to the winston-daily-rotate-file transport.testing
Error: testing
    at Object.<anonymous> (/Users/matt/projects/winstonjs/winston-daily-rotate-file/test.js:22:75)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

~/projects/winstonjs/winston-daily-rotate-file master*
❯
Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature Requests: What are they and how to manage them
Feature requests are a form of product feedback you may frequently encounter as a SaaS product manager. They typically come in the form...
Read more >
7 Useful Tips to Manage Feature Requests - Craft.io
Feature requests can provide product managers with great ideas for product improvement, but they must be managed correctly. Here are our top tips....
Read more >
Feature Request - Allow Product and Services Selection when ...
Solved: Hello, I'm currently working on syncing up our CoConstruct page with our QuickBooks transactions. CoConstruct leverages the Product ...
Read more >
Is this the right forum for feature requests?
Solved: Hi, just wondering how new features should be requested, voted on etc. ... Your best options: feedback link inside the application ...
Read more >
10 Tips for Responding Graciously to Customer Feature ...
Picture this scenario: A customer requests a feature. Support politely tells them that it can't be done while still providing top quality service....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found