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
I am trying to include extra information in every log. I have tried to do that with the overwrite settings but nothing seems to work. Here is an example how I am trying to do it:
import { ILogObj, ILogObjMeta, Logger } from 'tslog';
let type: 'json' | 'pretty' = 'pretty';
// Use the lease url as a proxy for running on AWS.
// Send machine readable logs.
if (process.env.PUREWEB_LEASE_URL) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type = 'json';
}
const ipRegex = /\b\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\b/g;
interface ICustomLogObj extends ILogObj {
launchRequestId?: string;
}
We're looking at the same thing. addMeta doesn't include the default meta and only includes what is returned from this method.
The default meta method has access to the runtime to populate default meta values, which I can't see an easy way to get from a addMeta implementation.
I'm updating addMeta to optionally fetch the default meta and include it in the logObj.[metaProperty] object passed into addMeta for a project. Will open a PR for the change to see if there is any interest in incorporating it.
I am trying to include extra information in every log. I have tried to do that with the overwrite settings but nothing seems to work. Here is an example how I am trying to do it:
import { ILogObj, ILogObjMeta, Logger } from 'tslog';
let type: 'json' | 'pretty' = 'pretty';
// Use the lease url as a proxy for running on AWS.
// Send machine readable logs.
if (process.env.PUREWEB_LEASE_URL) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type = 'json';
}
const ipRegex = /\b\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\b/g;
interface ICustomLogObj extends ILogObj {
launchRequestId?: string;
}
let launchRequestId: string | undefined;
const logger: Logger = new Logger({
maskValuesRegEx: [ipRegex],
type: type,
overwrite: {
addMeta: (logObj: any, logLevelId: number, logLevelName: string) => {
logObj[0] = logObj[0] + ' launchRequestId:' + launchRequestId;
return { logObj, _meta: { logLevelId, logLevelName, launchRequestId } };
}
}
});
export const setLaunchRequestId = (id: string) => {
launchRequestId = id;
};
export default logger;
What I need is when I issue any log eg: logger.info('test log'), the log also contains launchRequestId. How this can be done?
The text was updated successfully, but these errors were encountered: