Skip to content

Commit

Permalink
switch to new subscription for logs query and add my-logs flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pistachiobaby committed Sep 18, 2024
1 parent 8f61c61 commit 44e1c6a
Show file tree
Hide file tree
Showing 12 changed files with 921 additions and 1,565 deletions.
2,409 changes: 880 additions & 1,529 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions spec/commands/__snapshots__/root.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ Options
--allow-different-app Syncs with a different app using the --app command, instead of the one specified in the .gadget/sync.json file
--log-level <level> Sets the log level for incoming application logs (default: info)
--no-logs Disables outputting application logs to the console
--my-logs Only outputs user sourced logs
Ignoring files
ggt dev uses a .ignore file, similar to .gitignore, to exclude specific files and
Expand Down Expand Up @@ -201,6 +202,7 @@ Options
--allow-different-app Syncs with a different app using the --app command, instead of the one specified in the .gadget/sync.json file
--log-level <level> Sets the log level for incoming application logs (default: info)
--no-logs Disables outputting application logs to the console
--my-logs Only outputs user sourced logs
Ignoring files
ggt dev uses a .ignore file, similar to .gitignore, to exclude specific files and
Expand Down
44 changes: 22 additions & 22 deletions spec/commands/status.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe("status", () => {
------------------------
Preview https://test--development.gadget.app
Editor https://test.gadget.app/edit/development
Playground https://test.gadget.app/api/playground/graphql?environment=development
Playground https://test.gadget.app/api/playground/javascript?environment=development
Docs https://docs.gadget.dev/api/test
⠙ Calculating file changes.
Expand All @@ -58,7 +58,7 @@ describe("status", () => {
------------------------
Preview https://test--development.gadget.app
Editor https://test.gadget.app/edit/development
Playground https://test.gadget.app/api/playground/graphql?environment=development
Playground https://test.gadget.app/api/playground/javascript?environment=development
Docs https://docs.gadget.dev/api/test
⠙ Calculating file changes.
Expand Down Expand Up @@ -91,7 +91,7 @@ describe("status", () => {
------------------------
Preview https://test--development.gadget.app
Editor https://test.gadget.app/edit/development
Playground https://test.gadget.app/api/playground/graphql?environment=development
Playground https://test.gadget.app/api/playground/javascript?environment=development
Docs https://docs.gadget.dev/api/test
⠙ Calculating file changes.
Expand Down Expand Up @@ -119,24 +119,24 @@ describe("status", () => {
await status.run(testCtx, makeArgs(status.args));

expectStdout().toMatchInlineSnapshot(`
"Application test
Environment development
Branch test-branch
------------------------
Preview https://test--development.gadget.app
Editor https://test.gadget.app/edit/development
Playground https://test.gadget.app/api/playground/graphql?environment=development
Docs https://docs.gadget.dev/api/test
⠙ Calculating file changes.
✔ Calculated file changes. 12:00:00 AM
Your local files have changed.
+ local-file.txt created
Your environment's files have also changed.
+ gadget-file.txt created
"
`);
"Application test
Environment development
Branch test-branch
------------------------
Preview https://test--development.gadget.app
Editor https://test.gadget.app/edit/development
Playground https://test.gadget.app/api/playground/javascript?environment=development
Docs https://docs.gadget.dev/api/test
⠙ Calculating file changes.
✔ Calculated file changes. 12:00:00 AM
Your local files have changed.
+ local-file.txt created
Your environment's files have also changed.
+ gadget-file.txt created
"
`);
});
});
4 changes: 2 additions & 2 deletions spec/services/filesync/sync-json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ describe("sprintSyncJson", () => {
Environment development
Branch test-branch
Preview (​https://test--development.gadget.app​) Editor (​https://test.gadget.app/edit/development​) Playground (​https://test.gadget.app/api/playground/graphql?environment=development​) Docs (​https://docs.gadget.dev/api/test​)
Preview (​https://test--development.gadget.app​) Editor (​https://test.gadget.app/edit/development​) Playground (​https://test.gadget.app/api/playground/javascript?environment=development​) Docs (​https://docs.gadget.dev/api/test​)
"
`);
});
Expand All @@ -309,7 +309,7 @@ describe("sprintSyncJson", () => {
------------------------
Preview https://test--development.gadget.app
Editor https://test.gadget.app/edit/development
Playground https://test.gadget.app/api/playground/graphql?environment=development
Playground https://test.gadget.app/api/playground/javascript?environment=development
Docs https://docs.gadget.dev/api/test
"
`);
Expand Down
2 changes: 1 addition & 1 deletion src/__generated__/edit.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/__generated__/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const usage: Usage = (_ctx) => {
--allow-different-app Syncs with a different app using the --app command, instead of the one specified in the .gadget/sync.json file
--log-level <level> Sets the log level for incoming application logs (default: info)
--no-logs Disables outputting application logs to the console
--my-logs Only outputs user sourced logs
{gray Ignoring files}
ggt dev uses a .ignore file, similar to .gitignore, to exclude specific files and
Expand Down
2 changes: 1 addition & 1 deletion src/services/app/edit/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export type GraphQLSubscription<

export const ENVIRONMENT_LOGS_SUBSCRIPTION = sprint(/* GraphQL */ `
subscription EnvironmentLogs($query: String!, $start: DateTime, $limit: Int) {
logsSearch(query: $query, start: $start, limit: $limit) {
logsSearchV2(query: $query, start: $start, limit: $limit) {
status
data
}
Expand Down
6 changes: 3 additions & 3 deletions src/services/filesync/filesync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,12 @@ export class FileSync {
return this.syncJson.edit.subscribe({
subscription: ENVIRONMENT_LOGS_SUBSCRIPTION,
variables: () => ({
query: `{environment_id="${this.syncJson.environment.id}"} | json | level=~"${includedLevels}"`,
query: `{environment_id="${this.syncJson.environment.id}"} | json | level=~"${includedLevels}"${args["--my-logs"] ? ' | source="user"' : ""}`,
start: new Date(),
}),
onError,
onData: ({ logsSearch }) => {
for (const log of logsSearch.data["messages"] as [string, string][]) {
onData: ({ logsSearchV2 }) => {
for (const log of logsSearchV2.data["messages"] as [string, string][]) {
const message: unknown = JSON.parse(log[1]);
const { msg, name, level, ...fields } = message as Record<string, unknown>;

Expand Down
5 changes: 3 additions & 2 deletions src/services/filesync/sync-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ArgError, type ArgsDefinition, type ArgsDefinitionResult } from "../com
import type { Command } from "../command/command.js";
import type { Context } from "../command/context.js";
import { config, homePath } from "../config/config.js";
import { blueLight } from "../output/log/format/pretty.js";
import { println } from "../output/print.js";
import { select } from "../output/select.js";
import { setSentryTags } from "../output/sentry.js";
Expand Down Expand Up @@ -306,14 +307,14 @@ export class SyncJson {
if (terminalLink.isSupported) {
content += sprintln({
ensureEmptyLineAbove: true,
content: `${terminalLink("Preview", `https://${this.environment.application.slug}--${this.environment.name}.gadget.app`)} ${terminalLink("Editor", `https://${this.environment.application.primaryDomain}/edit/${this.environment.name}`)} ${terminalLink("Playground", `https://${this.environment.application.primaryDomain}/api/playground/graphql?environment=${this.environment.name}`)} ${terminalLink("Docs", `https://docs.gadget.dev/api/${this.environment.application.slug}`)}`,
content: `${terminalLink(blueLight("Preview"), `https://${this.environment.application.slug}--${this.environment.name}.gadget.app`)} ${terminalLink(blueLight("Editor"), `https://${this.environment.application.primaryDomain}/edit/${this.environment.name}`)} ${terminalLink(blueLight("Playground"), `https://${this.environment.application.primaryDomain}/api/playground/javascript?environment=${this.environment.name}`)} ${terminalLink(blueLight("Docs"), `https://docs.gadget.dev/api/${this.environment.application.slug}`)}`,
});
} else {
content += sprintln`
------------------------
Preview https://${this.environment.application.slug}--${this.environment.name}.gadget.app
Editor https://${this.environment.application.primaryDomain}/edit/${this.environment.name}
Playground https://${this.environment.application.primaryDomain}/api/playground/graphql?environment=${this.environment.name}
Playground https://${this.environment.application.primaryDomain}/api/playground/javascript?environment=${this.environment.name}
Docs https://docs.gadget.dev/api/${this.environment.application.slug}
`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/output/log/format/pretty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const color = new Chalk({
});

const blue = color.hex("#86B5F7");
const blueLight = color.hex("#B2D0FA");
export const blueLight = color.hex("#B2D0FA");
const gray = color.hex("#D6D6D6");
const grayDark = color.hex("#C2C2C2");
const green = color.hex("#9DE6A4");
Expand Down
3 changes: 2 additions & 1 deletion src/services/output/log/structured.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { formatters } from "./format/format.js";
import { Level, parseLevel } from "./level.js";

export const LoggingArgs = {
"--log-level": { type: (value) => parseLevel(value, Level.INFO), alias: ["-l"], default: Level.INFO },
"--log-level": { type: (value) => parseLevel(value, Level.INFO), alias: ["-ll"], default: Level.INFO },
"--my-logs": { type: Boolean },
} satisfies ArgsDefinition;

export type LoggingArgs = typeof LoggingArgs;
Expand Down

0 comments on commit 44e1c6a

Please sign in to comment.