Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stringify call seems to unformat logs on Windows #15

Open
edzillion opened this issue Jan 17, 2022 · 2 comments
Open

Stringify call seems to unformat logs on Windows #15

edzillion opened this issue Jan 17, 2022 · 2 comments

Comments

@edzillion
Copy link

  • apollo-server Version: [email protected]
  • Operating System (or Browser): windows 10, firefox latest
  • Node Version: v16.13.1
  • apollo-log Version: 1.1.0

How Do We Reproduce?

I suspect this is OS specific. To repro just use apollo-log as normal on a windows 10 machine. I am using conemu as my terminal but the same happens on windows default cmd

Expected Behavior

The logs are displayed with linebreaks etc so that they can be easily read.

apollo 44d6e2 {
  event: 'request',
  operationName: 'AddUser',
  query: 'mutation AddUser($addUserInput: AddUserInput!) {\n' +
    '  addUser(addUserInput: $addUserInput) {\n' +
    '    id\n' +
    '    device_id\n' +
    '    favourites\n' +
    '    __typename\n' +
    '  }\n' +
    '}',
  variables: [ 'addUserInput' ],
  context: {
    logger: Logger {
      name: 'apollo-server',
      levels: [Object],
      methodFactory: [Function: defaultMethodFactory],
      getLevel: [Function (anonymous)],
      setLevel: [Function (anonymous)],
      setDefaultLevel: [Function (anonymous)],
      resetLevel: [Function (anonymous)],
      enableAll: [Function (anonymous)],
      disableAll: [Function (anonymous)],
      trace: [Function: noop],
      debug: [Function: noop],
      info: [Function: bound info],
      warn: [Function: bound warn],
      error: [Function: bound error],
      log: [Function: noop]
    },
    schema: GraphQLSchema {
      __validationErrors: [],
      description: undefined,

Actual Behavior

Server is running on http://localhost:4000/graphql
apollo 21d17c {"event":"request","query":"    query IntrospectionQuery {      __schema {                queryType { name }        mutationType { name }        subscriptionType { name }        types {          ...FullType        }        directives {          name          description                    locations          args {            ...InputValue          }        }      }    }    fragment FullType on __Type {      kind      name      description            fields(includeDeprecated: true) {        name        description        args {          ...InputValue        }        type {          ...TypeRef        }        isDeprecated        deprecationReason      }      inputFields {        ...InputValue
  }      interfaces {        ...TypeRef      }      enumValues(includeDeprecated: true) {        name        description        isDeprecated        deprecationReason      }      possibleTypes {        ...TypeRef      }    }    fragment InputValue on __InputValue {      name      description      type { ...TypeRef }      defaultValue                }    fragment TypeRef on __Type {      kind      name      ofType {        kind        name        ofType {          kind
   name          ofType {            kind            name            ofType {              kind              name              ofType {                kind                name                ofType {                  kind
name                  ofType {

Observations

So the problem arises from the call to stringify() here:

log[(data as any).errors ? 'error' : 'info'](chalk`{dim ${id}}`, stringify(mutated));

when I removed stringify() and just returned the mutated variable the formatting was correct (as shown in expected behaviour above).
log[(data as any).errors ? 'error' : 'info'](chalk`{dim ${id}}`, mutated);

also I removed the line deleting newline chars in the query here

https://github.com/edzillion/apollo-log/blob/0b33bcd29f17ca8d321586b4770fe1c779ff96cb/src/index.ts#L69

@shellscape
Copy link
Owner

PRs are welcome

@shellscape
Copy link
Owner

@patrickblackjr please do not comment with "same, me too, +1, etc." that does nothing but spam the subscribers of this issue. basic github etiquette.

Repository owner deleted a comment from patrickblackjr Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants