aptible / supercronic

Cron for containers
MIT License
1.84k stars 112 forks source link

Combine job's json log with supercronic's log together. #65

Closed yayayahei closed 4 years ago

yayayahei commented 4 years ago

These days find supercronic is a great cron tool to run as non root user in container. Great job! 👍

Our project requires json log format with specified fields, like

{
"time":"",
"message":"",
"level":"",
"thread",""
...
}

Our job's stdout outprint is above json. But supercronic wrap the job's message to 'msg' field, it will destroy our format to view on kibana.

I want one option to disable rich logging in supercronic, just print what job's log, not wrap it in msg field. I know the supercronic's log is useful to watch cron's activity, maybe it is perfect to combine json structure between supercronic and job's own json log, but it will be difficult to implement. So we accept that the log format of supercronic to be as it is, but we want that our job's logs output standalone, not as 'msg' field.

yayayahei commented 4 years ago

Ha, found https://github.com/aptible/supercronic/pull/58

This is my version:

func parseJsonOrPrintText(line []byte, readerLogger *logrus.Entry) {
    var someJson map[string]interface{}

    err := json.Unmarshal(line, &someJson)
    if err != nil {
        readerLogger.Info(string(line))
    } else {
        readerLogger.WithFields(someJson).Info(string(line))
    }
}

Can combine job json with supercronic json log. Very good!

But I'm not sure it's recommanded to create a PR for this?

krallin commented 4 years ago

I submitted #67 to let you tell Supercronic to pass through your logs as-is, and not decorate them / wrap them in this msg field.