[Parser]: Log Level Label
psteinroe opened this issue ยท 9 comments
Feature Request
This is a direct follow up of #535. I forgot that the cloud providers, e.g. google, sometimes do not use level but severity as the key for the level. Hence, for Staackdriver to pick up the logs, the level value must be put into the severity field.
Is your feature request related to a problem? Please describe.
Stackdriver does not pick up the level.
Describe the solution you'd like
Either a config option to set the key name like a "key map" or a function that allows modification of the json before it is written would be great.
Okay, so something possibly like
const ogma = new Ogma({ levelMap: customLevelMap, levelKey: 'severity' })
Which would end up with
{
"severity": "INFO",
...
}
Or whatever else.
And to take care of the CLI we could add a new -k
for the level key where we could let it default to level
, but could be used as severity
or whatever else, so it can still be printed out in the default format
Sounds good! If you want me to do a PR, let me know. :)
I think it should be pretty straight forward. I use pnpm as a dependency and workspace manager, so make sure you've got that installed. I believe the following packages will need updates
common for the type updates
logger for the implementation
cli for the, well, cli update
Alright, I will get to it next week :)
Is the cli update even necessary? The level is picked up from ool
and level
is ignored:
private writeLog(log: OgmaLog, color: boolean): void {
const { time, hostname, application, context, pid, ool, level: _level, ...rest } = log;
let logMessage = this.ogmaGetter.wrapInParens(time) + ' ';
logMessage += this.ogmaGetter.getLevel(ool, color) + ' ';
logMessage += this.ogmaGetter.getVal(hostname, color, Color.MAGENTA) + ' ';
if (application) {
logMessage += this.ogmaGetter.getVal(application, color, Color.YELLOW) + ' ';
}
logMessage += pid + ' ';
if (context) {
logMessage += this.ogmaGetter.getVal(context, color, Color.CYAN) + ' ';
}
logMessage += this.ogmaGetter.getMessage(log, rest) + '\n';
process.stdout.write(Buffer.from(logMessage));
}
You know what, you're absolutely right! That was the whole point of that additional field.
I added the option, but having problems with typescript. It seems like the ts paths config is not picked up properly, because all ogma imports are failing with Cannot find module '@ogma/common' or its corresponding type declarations
. Am I missing a setup step? So far, I just ran pnpm install
.
Run pnpm build
to propagate the changes
2.1.0 has been published