0

I have a log4js configuration like the following (from the docs):

log4js.configure({
  appenders: {
    everything: { type: "file", filename: "all-the-logs.log" },
  },
  categories: {
    default: { appenders: ["everything"], level: "debug" },
  },
});
const logger = log4js.getLogger();

and when I log something, like so:

logger.debug("hello there!")

the word "default" is placed in front of all my logs, like so:

[2022-08-18T21:59:36.225] [DEBUG] default - hello there!

Is there a way to remove this? Thank you!

Evan
  • 1,892
  • 2
  • 19
  • 40

1 Answers1

1

log4js prints the logger category inside your logs because you are using the basic layout and the category token is present there. You can get rid of it by using a pattern layout that omits the category token

For example this pattern layout definition closly mimics your current configuration

layout: {
    type: "pattern",
    pattern: "[%d] [%p] %c - %m"
}

Notice the %c token, it will print the category, so just remove it

layout: {
    type: "pattern",
    pattern: "[%d] [%p] - %m"
}

So your new appenders configuration will look something like this

appenders: {
    everything: { 
        type: "file", 
        filename: "all-the-logs.log" 
        layout: {
            type: "pattern",
            pattern: "[%d] [%p] - %m"
        }
    },
}
svarog
  • 9,477
  • 4
  • 61
  • 77