You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
maybe this is a missing feature, or I do not know how to use attachTransport.
Snippet:
import { Logger, ILogObj } from "tslog";
const logger: Logger<ILogObj> = new Logger({
prettyLogTemplate: "{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}\t[{{logLevelName}}] ",
type: "pretty",
prettyLogTimeZone: "local"
});
logger.attachTransport((logObj) => {
console.log(JSON.stringify(logObj));
});
logger.info("I am a silly log.");
This gives on the console:
2023-07-19 20:55:27.967 [INFO] I am a silly log.
{"0":"I am a silly log.","_meta":{"runtime":"Nodejs","runtimeVersion":"v16.14.2","hostname":"juxe-PC","date":"2023-07-19T18:55:27.967Z","logLevelId":3,"logLevelName":"INFO","path":{"fullFilePath":"/home/juxeii/projects/tstest/myscript.js:12:8","fileName":"myscript.js","fileNameWithLine":"myscript.js:12","fileColumn":"8","fileLine":"12","filePath":"/myscript.js","filePathWithLine":"/myscript.js:12","method":"Object.<anonymous>"}}}
As you can see, I have created a pretty template.
But how can I just print the formatted output in the attachTransport function?
This function works with a JSON object, which is not formatted.
Do I really need to format again in attachTransport?
All I want, is that console.log(...) prints 2023-07-19 20:55:27.967 [INFO] I am a silly log.
EDIT: the exact same thing has been already requested here Issue205
Has this been addressed?
The text was updated successfully, but these errors were encountered:
As an alternative, you can also override transportFormatted which has the formatted string as the first argument. The only caveat with this is you have to do it when creating the logger, you can't attach the transport lazily or conditionally later.
Hi,
maybe this is a missing feature, or I do not know how to use
attachTransport
.Snippet:
This gives on the console:
As you can see, I have created a pretty template.
But how can I just print the formatted output in the
attachTransport
function?This function works with a JSON object, which is not formatted.
Do I really need to format again in
attachTransport
?All I want, is that
console.log(...)
prints2023-07-19 20:55:27.967 [INFO] I am a silly log.
EDIT: the exact same thing has been already requested here
Issue205
Has this been addressed?
The text was updated successfully, but these errors were encountered: