Logger in canton console

Hi team,

I see some examples in the canton doc that logger is used. When I use this I see it’s not found.

cmd4.sc:1: not found: type ConsoleEnvironment
def pruneAllNodes(pruneUpToIncluding: CantonTimestamp)(implicit env: ConsoleEnvironment): Unit = {
                                                                     ^
cmd4.sc:16: not found: value logger
        logger.warn(
        ^
cmd4.sc:26: not found: value logger
      case None => logger.info(s"Nothing to prune up to ${pruneUpToIncluding}")
                   ^
Compilation Failed

Please advise where I can use logger.

Thanks in advance.

kc

Hi KC

You should be able to use a logger in any canton console environment, but it is not available by default.
First import these to be able to grab a logger for your script:

import com.digitalasset.canton.logging.NamedLoggerFactory
import com.typesafe.scalalogging.Logger

Then produce the logger:

val loggerFactory = consoleEnvironment.environment.loggerFactory
val logger = Logger(loggerFactory.getLogger(this.getClass))

ConsoleEnvironment is also available after you import it:

import com.digitalasset.canton.console.{ConsoleEnvironment}

Hope this helps,
Mate

1 Like

Hi Mate,
Thanks for your reply. As I see a lot of examples where logger is used, see if the doc can mention this somewhere.
cheers,
kc

1 Like