microsoft / kernel-memory

RAG architecture: index and query any data using LLM and natural language, track sources, show citations, asynchronous memory patterns.
https://microsoft.github.io/kernel-memory
MIT License
1.63k stars 313 forks source link

How to configure logging to turn off console logging for Microsoft.KernelMemory.*? #798

Closed vksv closed 2 months ago

vksv commented 2 months ago

Context / Scenario

I am getting the below console logging when executing windows C# (.NET6.0) console applications built using kernel-memory. How do I configure so I don't get them? I have set the logger = null for both the kernel and kernel-memory. It didn't help. I have changed configurations between Release vs Debug. It didn't help. This interferes with my console application output.

consolelogging

What happened?

No console logging to happen after setting the logger = null for both the kernel and kernel-memory

Importance

I cannot use Kernel Memory

Platform, Language, Versions

C#, .NET6.0, Windows Console Application

Relevant log output

info: Microsoft.KernelMemory.Handlers.TextExtractionHandler[0]
      Handler 'extract' ready
info: Microsoft.KernelMemory.Handlers.TextPartitioningHandler[0]
      Handler 'partition' ready
info: Microsoft.KernelMemory.Handlers.SummarizationHandler[0]
      Handler 'summarize' ready
info: Microsoft.KernelMemory.Handlers.GenerateEmbeddingsHandler[0]
      Handler 'gen_embeddings' ready, 1 embedding generators
info: Microsoft.KernelMemory.Handlers.SaveRecordsHandler[0]
      Handler save_records ready, 1 vector storages
info: Microsoft.KernelMemory.Handlers.DeleteDocumentHandler[0]
      Handler 'private_delete_document' ready
info: Microsoft.KernelMemory.Handlers.DeleteIndexHandler[0]
      Handler 'private_delete_index' ready
info: Microsoft.KernelMemory.Handlers.DeleteGeneratedFilesHandler[0]
      Handler 'delete_generated_files' ready
fail: Microsoft.KernelMemory.Search.SearchClient[0]
      Memory record 'd=225fc38398225b1968004a33503347cd76641efb5358f764999c76fb518ac0d3//p=2eb0d84a610042af9f208e7acad6f5b7' doesn't contain a '__part_n' tag
fail: Microsoft.KernelMemory.Search.SearchClient[0]
      Memory record 'd=10209d0ab365e54a2612b7c011749e570634d1c35e8c89ef3838d4def6ffbdcb//p=81213c79947c4494ba86808416e94023' doesn't contain a '__part_n' tag
fail: Microsoft.KernelMemory.Search.SearchClient[0]
      Memory record 'd=10209d0ab365e54a2612b7c011749e570634d1c35e8c89ef3838d4def6ffbdcb//p=5b5f8dc3736d420c8e0169ed277ae322' doesn't contain a '__part_n' tag
fail: Microsoft.KernelMemory.Search.SearchClient[0]
      Memory record 'd=d5024cd536a84248682471e77472e47cb8483dee8a2e9f457da68cb73f8280d0//p=6ecc934dcf504645aae582c27b657c74' doesn't contain a '__part_n' tag
fail: Microsoft.KernelMemory.Search.SearchClient[0]
      Memory record 'd=1099c1c6350ae5847e9f2b8981199bc9e14637ca7d27e91d90169cc99f5b6da2//p=ef81ccd7f13749429a75f3532ac0b8fd' doesn't contain a '__part_n' tag
fail: Microsoft.KernelMemory.Search.SearchClient[0]
      Memory record 'd=225fc38398225b1968004a33503347cd76641efb5358f764999c76fb518ac0d3//p=9de43344300f44058dd092adf590412b' doesn't contain a '__part_n' tag
marcominerva commented 2 months ago

You can disable logging at all for Kernel Memory by setting the logging minimum level of its LoggerFactory:

Microsoft.KernelMemory.Diagnostics.DefaultLogger.Factory = LoggerFactory.Create(builder =>
{
    builder.SetMinimumLevel(LogLevel.None);
});

If you don't have to disable all the logging, you can use the builder parameter to configure logging destinations and their settings in a more granular way.

dluc commented 2 months ago

With memory builder you can use this:

var builder = new KernelMemoryBuilder()
            .Configure(builder => builder.Services.AddLogging(l =>
            {
                l.SetMinimumLevel(LogLevel.None);
            }))
           ...

or this, if you want to see errors:

var builder = new KernelMemoryBuilder()
            .Configure(builder => builder.Services.AddLogging(l =>
            {
                l.SetMinimumLevel(LogLevel.Error);
                l.AddSimpleConsole(c =>
                {
                    c.SingleLine = true;
                    c.UseUtcTimestamp = false;
                    c.TimestampFormat = "[HH:mm:ss.fff] ";
                });
            }))
           ...

You could also log to file, see here for example https://learn.microsoft.com/en-us/answers/questions/1377949/logging-in-c-to-a-text-file

As @marcominerva mentioned, you can configure a lot of other options.