mentum / lawgs

Logging to AWS CloudWatch Logs made easy
MIT License
116 stars 12 forks source link

Creating a logger causes the process to never exit #6

Open Dermah opened 8 years ago

Dermah commented 8 years ago

After I do

var logger = lawgs.getOrCreate('logGroup');

my script won't exit until I kill it manually. For example, example.js never exits. I'm guessing this is because of some asynchronous stuff happening using Q.

I could use the uploaded hook to exit the process after an upload, but what if don't have anything left to log and upload?

What do you think about something like

logger.flushAndClose()

which would upload all queued logs and sort of 'close the stream,' allowing things that use logger to exit naturally?

Dermah commented 8 years ago

Actually I can't use the upload hook because it hasn't been pushed to npm yet :(

zmpeg commented 8 years ago

I get the same issue. Happens for me on both node 0.12 latest and 4 latest. Going back through commits it looks like it has always been an issue. I'd be willing to look into submitting a PR if someone can point me in the right direction.

jkentjnr commented 7 years ago

I'm getting this issue too ... makes it impossible to use it on Lambda or similar. Always times out.

jschuur commented 6 years ago

Same problem. Wanted to log lambda activity :(

gcphost commented 6 years ago

I'm here for the same issue, none of these cloudwatch scripts seem to work on Lambda.

They all seem to wait for the process to exit before batching logs out to cloudwatch.

Novel idea for other types of applications.

Ankitsurparia commented 6 years ago

I have found the solution to this bug. just put this line into {subscription.dispose();} the putLogEvents method after else. it's like every time a new subscriber is subscribing but it's not disposing of. after disposing of it will work accordingly

thovden commented 5 years ago

The culprit seems to be var logsSource = new Rx.Subject() which uses a timer, and onCompleted is never called.

- Timers:
  - (5000 ~ 5 s) (anonymous) @ node_modules/rx/dist/rx.js:1431
bwobbones commented 5 years ago

Based on the comment from @thovden I've added

me.on("uploaded", () => {
  logsSource.onCompleted();
});

at around line 40, seems to work ok? There's a PR there, but seems like @mentum has dropped this one...

souuu commented 5 years ago

Hello, is there an update for this ?