Turning on logging of the Mapnik SQL query during map rendering

73 Views Asked by At

I am using the npm package Mapnik with PostGIS and I want to enable logging to the console of the SQL query that Mapnik is executing, including the value of the bbox parameter, when running the render() function.

import * as mapnik from "mapnik";


async function main() {
  mapnik.register_default_input_plugins();
  mapnik.settings.log.level = "debug"; // something like that???

...

  const vectorTile = new VectorTile(parseInt(z), parseInt(x), parseInt(y));
  const map = new Map(256, 256);
  new RouteLayer(vectorTile).apply(map);
  map.zoomAll();

  map.render(vectorTile, (err, vectorTile) => { // how to log executed sql query?
      if (err) {
        return rej(err);
      }

      return res(vectorTile.getData());
    });
}

main();

...
// RouteLayer
private apply(map: mapnik.Map): void {
    const config = this.createPostgisConfig(`
            select 
                id,
                geometry
            from nordic_sector
            where 
                deleted_at is null
              and st_intersects(st_transform(geometry, 3857),!bbox!)
        `);
    const layer = new (mapnik as any).Layer(
      "nordic-sector-back",
      PROJECTION_3857
    );
    layer.datasource = new mapnik.Datasource(config);

    (map as any).add_layer(layer);
  }



EDIT1:

Unsuccessful attempts:

 (mapnik as any).logger.set_severity((mapnik as any).severity_type.Debug);
 (mapnik as any).Logger.setSeverity((mapnik as any).Logger.DEBUG);
1

There are 1 best solutions below

3
Wesley LeMahieu On

In Mapnik you can configure the default logging severity level like this:

mapnik.logger.set_severity(mapnik.severity_type.Debug)