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

console.log multiple lines to a single Cloudwatch Logs event #40

Closed
hayd opened this issue Jan 18, 2020 · 2 comments · Fixed by #43
Closed

console.log multiple lines to a single Cloudwatch Logs event #40

hayd opened this issue Jan 18, 2020 · 2 comments · Fixed by #43
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@hayd
Copy link
Contributor

hayd commented Jan 18, 2020

At the moment each line is a separate event for each line (this is handled by the callee of the custom runtime who is piping stdout to cloudwatch logs).

The objective is to be able to push a single event e.g. console.log(1, '\n', 2)

Screen Shot 2020-01-17 at 23 45 03

^This is the node output.

It is expandable and copy/pastable (where it wouldn't be if it was across multiple events).


Since console.log can be overloaded the naive solution is to push each console.log to CW however the problem is that this is rate-limited:

There is a quota of 5 requests per second per log stream. Additional requests are throttled. This quota can't be changed.

What you want to do is queue the log events up and PutLogEvents every second. The problem is that if you POST the queue after each event you may hit the rate-limit (since each event can be < 50ms) BUT if you don't then the process after each event they may never be POSTed (if the process is terminated) https://github.com/hayd/deno-lambda#warning


Ideally custom runtimes will have a local endpoint which manages such a CW logs batch queue... but nothing is documented as far as I can see.

OR it's even simpler and the newline can be encoded somehow (and still passed to stdout).

cc @brianleroux (perhaps you know / or know someone how has an answer for this)!

@hayd hayd added enhancement New feature or request help wanted Extra attention is needed labels Jan 18, 2020
@hayd
Copy link
Contributor Author

hayd commented Jan 25, 2020

Turns out this is trivial: use \r rather than \n!

Edit: Although I'm not sure how to do this! The objective is to replace all /n in the output of console.log with /r (except the last one). i.e.

console.log = (...args: unknown[]): void => {
    this.printFunc(
      stringifyArgs(args, {
        indentLevel: this.indentLevel
      }).replace('\n', '\r') + "\n",
      false
    );
  };

But unfortunately both printFunc and stringifyArgs are private.
https://github.com/denoland/deno/blob/514cdd941c7c0e8166e9a6f06ee23ef8f7ef30d7/cli/js/console.ts

@hayd
Copy link
Contributor Author

hayd commented Jan 25, 2020

fixed in #43.

@hayd hayd closed this as completed Jan 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant