Cannot modify logger format in TypeScript
See original GitHub issuePlease tell us about your environment:
winston
version?-
winston@2
-
winston@3
-
node -v
outputs: 8.9.4- Operating System? macOS and Linux
- Language? TypeScript 2.7.2
What is the problem?
I want to be able to modify the default Logger of winston in my own log
module and access that same logger from all other modules in my project. This worked just fine in Node, but I cannot modify the format in TypeScript.
When I try to customize the format, I receive the error
error 2339: Property ‘format’ does not exist on type ‘Winston’.
export const logger = new winston.Logger({
level: 'debug',
// same error on the next 3 lines
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
transports: [
new winston.transports.File({ filename: 'server_error.log', level: 'error' }),
new winston.transports.File({ filename: 'server_all.log' })
]
});
What do you expect to happen instead?
This was the code I used in Node:
const winston = require('winston');
const logger = winston.createLogger({
level: 'debug', // Levels: error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
transports: [
new winston.transports.File({ filename: 'server_error.log', level: 'error'}),
new winston.transports.File({ filename: 'server_all.log'})
]
});
// If we're not in production then log to the `console` with the format:
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
if (process.env.NODE_ENV !== 'production') {
logger.add(new winston.transports.Console({
format: winston.format.simple()
}));
}
exports.logger = logger;
I expect the same format customization to work in TypeScript as well.
Other information
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Cannot format code on visual studio when using TypeScript
The problem was that I haven't installed any Visual Studio features that support javascript & typescript. The solution is press "Tools" ...
Read more >typescript-logging - npm
TypeScript Logging core written in and to be used by TypeScript (this is the core project, you need to install a flavor too)....
Read more >Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >tslog - Extensible TypeScript Logger for Node.js and Browser ...
Extensible TypeScript Logger for Node.js and Browser: Dependency free, Fully customizable, Pretty errors, stack traces, and JSON output to attachable ...
Read more >TypeScript debugging with Visual Studio Code
json and the VS Code Node.js debugger can't map your TypeScript source code to the running JavaScript. Turn on source maps and rebuild...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Example:
Thanks, for the moment I added all 3
.d.ts
files manually, which works fine and will update to RC6 as soon as its out!