tslog
tslog copied to clipboard
Question- file transport formatting
I run an example file transport and see what's happens.
logger.attachTransport((logObj) => {
appendFileSync( path.resolve(process.cwd(),'./log',"logs.json"), JSON.stringify(logObj) + "\n");
});
the conclusion does not look readable at all
can you please show an example formatting - that you provide to output to console, but without colors?
I suggest that you console.log() the logObj to see its shape and the data it contains to build a custom message / object you want in your transport function. Your current solution just takes the full logObj and sends it as a json string to your file.
Here is an example of what I've done for one project:
function logFileTransport(logObject: ILogObj) {
// console.log(logObject); // Use this to see the shape of the log object.
const logMeta = logObject['_meta'] as IMeta;
let parentString = logMeta.parentNames?.join(':') || '';
if (parentString) { parentString = `${parentString}:`; }
appendFileSync('myLogFile.log'), `${logMeta.date.toISOString()} - ${logMeta.logLevelName}: [${parentString}${logMeta.name}] ${logObject[0]}\n`);
}