Deno: Disable warning logs (WARN) in console

Viewed 550

I'm new to Deno and I see that Deno is showing all warning logs (WARN) in the console. Is there an option to disable this behavior?

UPDATE: eventually, I think I need to be able to change the log level of Deno's default logger for its consoleHandler. for example, when I'm using the Deno's fetch API, I don't want to see a lot of warnings about request/response size, etc.

2 Answers

I have not tested but I guess this is the option you can pass along when running code

-L, --log-level <log-level>
            Set log level [possible values: debug, info]

Also, check this out code snippet from official docs for customizing logger

import * as log from "https://deno.land/std/log/mod.ts";

// Simple default logger out of the box. You can customize it
// by overriding logger and handler named "default", or providing
// additional logger configurations. You can log any data type.
log.debug("Hello world");
log.info(123456);
log.warning(true);
log.error({ foo: "bar", fizz: "bazz" });
log.critical("500 Internal server error");

// custom configuration with 2 loggers (the default and `tasks` loggers)
await log.setup({
  handlers: {
    console: new log.handlers.ConsoleHandler("DEBUG"),

    file: new log.handlers.FileHandler("WARNING", {
      filename: "./log.txt",
      // you can change format of output message using any keys in `LogRecord`
      formatter: "{levelName} {msg}",
    }),
  },

  loggers: {
    // configure default logger available via short-hand methods above
    default: {
      level: "DEBUG",
      handlers: ["console", "file"],
    },

    tasks: {
      level: "ERROR",
      handlers: ["console"],
    },
  },
});

let logger;

// get default logger
logger = log.getLogger();
logger.debug("fizz"); // logs to `console`, because `file` handler requires "WARNING" level
logger.warning(41256); // logs to both `console` and `file` handlers

// get custom logger
logger = log.getLogger("tasks");
logger.debug("fizz"); // won't get output because this logger has "ERROR" level
logger.error({ productType: "book", value: "126.11" }); // log to `console`

// if you try to use a logger that hasn't been configured
// you're good to go, it gets created automatically with level set to 0
// so no message is logged
const unknownLogger = log.getLogger("mystery");
unknownLogger.info("foobar"); // no-op

There is Fen framework for deno that can do that: here is link

Related