Skip to content
CCPEDIAby Unity Nodes
App Development

Logger in canton console

3 posts238 views2 likesLast activity May 2022

  1. kctamOP

    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

  2. Mate_Varga 1

    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

  3. kctam 1
    Mate_Varga:

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

    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