0

I am using Memgraph with Memgraph Platform Docker image, version 2.4.0 on MacOS. I started developing my own Python query module procedure in Memgraph Lab. It is not loading correctly because I have an error in my code, and then I am seeing the reason why in the logs. But to be able to fix the bug, it would help me to print out the certain values from my code. I found that the debugging process is pretty hard and I am wondering if there is a way to log certain messages? I tried using a simple logger and print, but none of those work.

KateLatte
  • 611
  • 1
  • 12

1 Answers1

0

You are lucky, because in Memgraph Platform 2.4.0 (that is Memgraph 2.4.0) there is a new feature - extension of Python API to enable logging on different levels. This means that you can use class Logging from the mgp. Here is the documentation for the Logger Objects. To be able to use this object, please make sure to first set Memgraph flag --also-log-to-stderr to true. You can do that by specifying the configuration options in the Docker run command when starting Memgraph Platform image. For example:

docker run -it -p 7687:7687 -p 7444:7444 -p 3000:3000 -e MEMGRAPH="--also-log-to-stderr=true" memgraph/memgraph-platform:2.4.0

Here is the example usage of the Logger object:

import mgp

@mgp.read_proc
def myProcedure(ctx: mgp.ProcCtx) -> mgp.Record(return_statement = mgp.Nullable[str]):

    logger = mgp.Logger()
    logger.info("Logging my procedure")

    return mgp.Record(return_statement = "hello logging in procedure")

If you run the procedure in the Query execution tab in Memgraph Lab:

CALL test_module.myProcedure() YIELD return_statement;

you are going to see the 'hello logging in procedure' output.

The logged messages will be seen in Memgraph logs once the procedure is run. If you are using Memgraph Lab, then simply head over to the Logs tab and check what's new after you run your procedure.

enter image description here

If you want to check the logs directly in the Memgraph log file, instead of in the Memgraph Lab, please read the how-to guide for accessing logs.

KateLatte
  • 611
  • 1
  • 12