scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.07k stars 323 forks source link

Mechanism to log json requests and responses, to and from client #321

Closed yyadavalli closed 5 years ago

yyadavalli commented 6 years ago

We should provide a way to log the json at the boundary to make sure different clients are working correctly. It also helps debug a lot of client related issues.

gabro commented 6 years ago

I believe logs are already there, simply disabled since they have status trace.

olafurpg commented 6 years ago

I think after we complete #318 it will be easier to programmatically set the log level based on a system property like -Dmetals.logger=trace. It's probably possible to do it with logback but I would prefer to invest in completing the migration to scribe first.

yyadavalli commented 6 years ago

@gabro is there a way to enable them?

olafurpg commented 6 years ago

You can update the logback xml configuration On Thu, 28 Jun 2018 at 20:50, Yash Yadavalli notifications@github.com wrote:

@gabro https://github.com/gabro is there a way to enable them?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/scalameta/metals/issues/321#issuecomment-401136186, or mute the thread https://github.com/notifications/unsubscribe-auth/ABV8XULFdYyMwLhZ3IwUd2W-hyvAjAHxks5uBSVdgaJpZM4U70LP .

olafurpg commented 5 years ago

Fixed in #337. All incoming and outgoing JSON requests can now be seen by following instructions that are printed during startup of the server

info  Tracing is disabled for protocol LSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /Users/olafurpg/Library/Caches/org.scalameta.metals/lsp.trace.json

If the trace file exists, then you can tail -f it or use less to see raw JSON payloads

{
  "jsonrpc": "2.0",
  "method": "build/taskFinish",
  "params": {
    "taskId": {
      "id": "1"
    },
    "eventTime": 1543340644550,
    "message": "Compiled \u0027test-workspace\u0027",
    "dataKind": "compile-report",
    "data": {
      "target": {
        "uri": "file:/Users/olafurpg/dev/metals/test-workspace/?id\u003dtest-workspace"
      },
      "errors": 0,
      "warnings": 0
    }
  }
}
{
  "jsonrpc": "2.0",
  "id": "6",
  "result": {
    "statusCode": 1
  }
}

This works for both LSP and BSP communication.