0

Currently, the "Hello World" does alway appear in the journal. How can I prevent this, e.g. have it only in the journal, if debug is 1?

int main(int argc, char *argv[]) {
        int debug = (argc >= 2 && !strcmp(argv[1], "--debug")) ? 1 : 0;
        /* must only appear in the journal, if debug == 1 */
        sd_journal_print(LOG_DEBUG, "Hello World");
        return 0;
}

I'm on a ressource limited system and cannot afford too much logging.

Thanks in advance!

Addition: I'm asking for an equivalent to Pythons logging.Logger.setLevel (https://docs.python.org/3/library/logging.html#logging.Logger.setLevel).

Martin
  • 31
  • 3
  • 1
    Put an `if` around your `sd_journal_print` statement? Seems like an easy fix. – tadman Apr 05 '19 at 16:45
  • 1
    How about putting `if (debug == 1) ` not in the comment? – Eugene Sh. Apr 05 '19 at 16:45
  • Are you asking how to set something globally that tells sd_journal_print to ignore all LOG_DEBUG and lower from this process, without changing the code that generates them? – Rup Apr 05 '19 at 16:46
  • I'm asking for an equivalent to Pythons `logging.Logger.setLevel` (https://docs.python.org/3/library/logging.html#logging.Logger.setLevel). – Martin Apr 05 '19 at 16:54

0 Answers0