prisma1 icon indicating copy to clipboard operation
prisma1 copied to clipboard

Log the generated/executed SQL queries

Open divyenduz opened this issue 8 years ago • 31 comments

Is your feature request related to a problem? Please describe. Currently, it is not possible to see the logs for SQL queries generated/executed against executed GraphQL queries.

Describe the solution you'd like There should be a way to log the generated SQL queries. Maybe append them to the Prisma docker logs, probably behind a debug flag.

Describe alternatives you've considered It is possible to get the executing/executed queries from DB.

Additional context It will help debugging issues much easier.

divyenduz avatar Jul 30 '18 15:07 divyenduz

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 06 '18 15:12 stale[bot]

"This issue has been automatically marked as stale because it has not had recent activity."

Yes please

Im getting errors from psotgres and have no idea why since I can't see the query

AndrewRayCode avatar Jan 09 '19 05:01 AndrewRayCode

This is not stale. People aren't just commenting on it. This is something I would really like to see. Since prisma doesn't have a very good documentation I basically need to understand what query is it building in order to write the code correctly that calls the prisma API.

I'm trying to understand how _every, _some, _none works

pbassut avatar Feb 07 '19 13:02 pbassut

Up vote for this!

nambuntu avatar Mar 06 '19 07:03 nambuntu

This would be very helpful in development.

miketdonahue avatar Apr 11 '19 06:04 miketdonahue

@divyenduz - Any reason this feature request is so old? It seems like to me to be a very simple task that provides tremendous value to Prisma users in development and debugging, and it doesn't require much speccing (as the tag suggests) besides what you wrote yourself in the original description.

What should hinder the team in implementing this with the next release?

jhalborg avatar Apr 12 '19 20:04 jhalborg

This feature has been available since Prisma 1.30.x and can be used with the following environment variable:

Key LOG_LEVEL

Values: INFO -> default logging DEBUG -> more detailed logging, emits SQL TRACE -> logs everything

Please let me know if this works for you.

divyenduz avatar Apr 26 '19 12:04 divyenduz

@divyenduz Not for me.

I tried LOG_LEVEL at both DEBUG and TRACE - and even though I get DEBUG and TRACE tagged output in the console, no SQL queries are shown.

prisma.yml (note that I added the var both under the root environment as well as the PRISMA_CONFIG, not sure where it was supposed to go and there seems to be no docs on it:

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.30.1
    restart: always
    ports:
    - "4466:4466"
    environment:
      LOG_LEVEL: TRACE # Log SQL queries
      PRISMA_CONFIG: |
        port: 4466
        # uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
        managementApiSecret: my-secret
        LOG_LEVEL: TRACE # Log SQL queries
        databases:
          default:
            connector: mysql
            host: mysql
            port: 3306
            user: root
            password: prisma
            migrations: true
            rawAccess: true
  mysql:
    image: mysql:5.7
    restart: always
    ports:
    - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: prisma
    volumes:
      - mysql:/var/lib/mysql
volumes:
  mysql:

Output from a query

prisma_1  | [DEBUG] resuming
prisma_1  | [TRACE][Jwt-rs] Verify - handing out: 0x7f79c0422750
prisma_1  | [TRACE][Jwt-rs] Dropping buffer at: 0x7f79c0422750
prisma_1  | [DEBUG] {} - configuration:
prisma_1  | [DEBUG] allowPoolSuspension.............false
prisma_1  | [DEBUG] autoCommit......................true
prisma_1  | [DEBUG] catalog.........................null
prisma_1  | [DEBUG] connectionInitSql..............."set names utf8mb4;"
prisma_1  | [DEBUG] connectionTestQuery.............null
prisma_1  | [DEBUG] connectionTimeout...............5000
prisma_1  | [DEBUG] dataSource......................null
prisma_1  | [DEBUG] dataSourceClassName............."slick.jdbc.DriverDataSource"
prisma_1  | [DEBUG] dataSourceJNDI..................null
prisma_1  | [DEBUG] dataSourceProperties............{user=root, url=jdbc:mysql://mysql:3306/?autoReconnect=true&useSSL=false&requireSSL=false&serverTimeZone=UTC&useUnicode=true&characterEncoding=UTF-8&socketTimeout=60000&usePipelineAuth=false&cachePrepStmts=true, password=<masked>}
prisma_1  | [DEBUG] driverClassName.................null
prisma_1  | [DEBUG] healthCheckProperties...........{}
prisma_1  | [DEBUG] healthCheckRegistry.............null
prisma_1  | [DEBUG] idleTimeout.....................600000
prisma_1  | [DEBUG] initializationFailFast..........false
prisma_1  | [DEBUG] isolateInternalQueries..........false
prisma_1  | [DEBUG] jdbc4ConnectionTest.............false
prisma_1  | [DEBUG] jdbcUrl.........................null
prisma_1  | [DEBUG] leakDetectionThreshold..........0
prisma_1  | [DEBUG] maxLifetime.....................1800000
prisma_1  | [DEBUG] maximumPoolSize.................9
prisma_1  | [DEBUG] metricRegistry..................null
prisma_1  | [DEBUG] metricsTrackerFactory...........null
prisma_1  | [DEBUG] minimumIdle.....................9
prisma_1  | [DEBUG] password........................<masked>
prisma_1  | [DEBUG] poolName........................"database"
prisma_1  | [DEBUG] readOnly........................false
prisma_1  | [DEBUG] registerMbeans..................false
prisma_1  | [DEBUG] scheduledExecutorService........null
prisma_1  | [DEBUG] threadFactory...................null
prisma_1  | [DEBUG] transactionIsolation............null
prisma_1  | [DEBUG] username........................null
prisma_1  | [DEBUG] validationTimeout...............1000
prisma_1  | [INFO] {} - Started.
prisma_1  | [DEBUG] {} - {}stats (total={}, active={}, idle={}, waiting={})
prisma_1  | [DEBUG] {} - Added connection {}
prisma_1  | [DEBUG] {} - Added connection {}
prisma_1  | [DEBUG] {} - Added connection {}
prisma_1  | [DEBUG] {} - Added connection {}
prisma_1  | [DEBUG] {} - Added connection {}
prisma_1  | [DEBUG] {} - Added connection {}
prisma_1  | [DEBUG] {} - Added connection {}
prisma_1  | [DEBUG] {} - Added connection {}
prisma_1  | [DEBUG] {} - Added connection {}
prisma_1  | [DEBUG] {} - {}stats (total={}, active={}, idle={}, waiting={})
prisma_1  | [DEBUG] #1: SimpleJdbcAction
prisma_1  | [TRACE][Jwt-rs] Verify - handing out: 0x7f7954138f20
prisma_1  | [TRACE][Jwt-rs] Dropping buffer at: 0x7f7954138f20
prisma_1  | [DEBUG] #1: SimpleJdbcAction
prisma_1  | [DEBUG] #1: SimpleJdbcAction
prisma_1  | [DEBUG] #1: SimpleJdbcAction
prisma_1  | [DEBUG] #1: SimpleJdbcAction
prisma_1  | [DEBUG] #1: SimpleJdbcAction
prisma_1  | [DEBUG] #1: SimpleJdbcAction
prisma_1  | [DEBUG] #1: SimpleJdbcAction
prisma_1  | [DEBUG] {} - {}stats (total={}, active={}, idle={}, waiting={})
prisma_1  | [DEBUG] #1: SimpleJdbcAction
prisma_1  | [DEBUG] pausing
prisma_1  | [DEBUG] resuming
prisma_1  | [DEBUG] {} - {}stats (total={}, active={}, idle={}, waiting={})
prisma_1  | [DEBUG] {} - {}stats (total={}, active={}, idle={}, waiting={})
prisma_1  | [DEBUG] #1: SimpleJdbcAction
prisma_1  | [DEBUG] pausing
prisma_1  | [DEBUG] resuming

jhalborg avatar Apr 29 '19 10:04 jhalborg

me too. LOG_LEVEL: TRACE doesn't show any sql queries. Here is my console log:

prisma_1    | [DEBUG] resuming
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] pausing
prisma_1    | [DEBUG] resuming
prisma_1    | [DEBUG] {} - {}stats (total={}, active={}, idle={}, waiting={})
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] pausing
prisma_1    | [DEBUG] resuming
prisma_1    | [DEBUG] {} - {}stats (total={}, active={}, idle={}, waiting={})
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction
prisma_1    | [DEBUG] #1: SimpleJdbcAction

bkstorm avatar May 08 '19 11:05 bkstorm

I confirm that this does not work on v1.32

paulrostorp avatar May 14 '19 09:05 paulrostorp

Doesn't work for Prisma CLI version: prisma/1.32.0 (darwin-x64) node-v10.4. Only prints SQL statements for the initial creation of the tables in the prisma database

toriaezunama avatar May 15 '19 17:05 toriaezunama

Friendly ping @divyenduz 😄

jhalborg avatar May 16 '19 10:05 jhalborg

Any progress here? I'd love to see SQL queries too

peterrogov avatar Jun 11 '19 10:06 peterrogov

I think this would be my number one request at this point. Suggested something similar here #3936.

joshhopkins avatar Jun 11 '19 14:06 joshhopkins

As a workaround I switched prisma to a local MySQL installation (instead of docker container) and switched on general log on MySQL Server where it logs all incoming SQL queries. Lets me see prisma's queries.

peterrogov avatar Jun 11 '19 19:06 peterrogov

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 26 '19 19:07 stale[bot]

Go away stale bot 😅

jhalborg avatar Jul 31 '19 07:07 jhalborg

Any word on this? I love the LOG_LEVEL idea, except it doesn't work...

tedb19 avatar Aug 24 '19 08:08 tedb19

Really curious - how do Prisma devs themselves know whether the generated queries are good or not if there's no way to see them?

dvelitchkov avatar Sep 25 '19 16:09 dvelitchkov

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 09 '19 17:11 stale[bot]