Have you ever mocked your logger in a test, or wished you could? That is something like

TEST(some test name)

    mockLogger logger

    logger.expect_call(log("some string"))

    DoSomething(logger)

#programming

  • @breadsmasher
    link
    English
    1
    edit-2
    2 months ago

    Nothing something I have felt the need to test directly, or mock.

    But you absolutely can in Moq c#

  • tve
    link
    fedilink
    02 months ago

    @bluGill If you have a need to mock a logger, you probably should have an interface dedicated to those logs.

    It is also recommended to have dedicated loggers used in each domain, rather than allowing logging everything and everywhere, which may lead to sanitizing log inputs everywhere to be in control and not expose any security issues.

    But in many cases that may also be overkill. As always, it depends.

    • bluGillOP
      link
      fedilink
      12 months ago

      @tve I didn’t ask how to do it, I asked if anyone else has done it.

  • macniel
    link
    fedilink
    02 months ago

    Why would you want to mock a logger? Aren’t the different Log Levels already enough?

    • bluGillOP
      link
      fedilink
      12 months ago

      @DmMacniel so you can prove some interesting thing is really logged? maybe someone else has a different reason.