Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attachTransport to have the formatted string only #246

Open
juxeii opened this issue Jul 19, 2023 · 2 comments
Open

attachTransport to have the formatted string only #246

juxeii opened this issue Jul 19, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@juxeii
Copy link

juxeii commented Jul 19, 2023

Hi,

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?

@juxeii juxeii added the enhancement New feature or request label Jul 19, 2023
@JustinGrote
Copy link

I added some workaround notes because this annoyed me too: #205 (comment)

@JustinGrote
Copy link

JustinGrote commented Sep 14, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants