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

cloudflare workers support #179

Open
seguri opened this issue Mar 15, 2022 · 7 comments
Open

cloudflare workers support #179

seguri opened this issue Mar 15, 2022 · 7 comments

Comments

@seguri
Copy link

seguri commented Mar 15, 2022

Hello,

I'd like to kindly ask you if you could add a section in the README about how to setup winston-syslog for remote logging in cloudflare workers. I'm following this tutorial but the build fails:

$ wrangler publish
👀  ./node_modules/unix-dgram/lib/unix_dgram.js
Module not found: Error: Can't resolve 'dgram' in '/path/to/project/node_modules/unix-dgram/lib'
resolve 'dgram' in '/path/to/project/node_modules/unix-dgram/lib'
...

I'm now looking into webpack and its resolve.fallback configuration, but I'm new to these things and it might take a while.

Thanks

@wbt
Copy link
Contributor

wbt commented Mar 15, 2022

In short, be sure to run npm install before your publish line, and if you figure out more please feel free to post here and/or make a PR on the documentation. However, it looks like the issue is in the unix-dgram package, not in winston.

@seguri
Copy link
Author

seguri commented Mar 15, 2022

The Workers runtime uses the V8 engine and also implements many of the standard APIs available in most modern browsers. I'm not sure there's a way to make winston work. Do you see a way around dgram in one of the provided APIs?

@wbt
Copy link
Contributor

wbt commented Mar 15, 2022

I'm saying it looks like the problem is in the unix-dgram package rather than in Winston.

@seguri
Copy link
Author

seguri commented Mar 15, 2022

I got that thanks, you wrote it twice. Do you know or have an idea how to make winston-syslog compatible with cloudworkers or not?

@DABH
Copy link
Contributor

DABH commented Mar 15, 2022

I don’t think you want to use the winston-syslog transport. If you are trying to send logs to some remote destination, you should use something like the built-in HTTP transport in Winston. The syslog transport is meant for writing things to Linux system logs, and I don’t think that Cloudflare workers give you access to such logs since they are not designed as full-fledged Linux VMs. Hope that helps steer you in the right direction.

@seguri
Copy link
Author

seguri commented Mar 16, 2022

Just an update: the Papertrail tutorial I've linked also mentions winston.transports.Http; this throws fewer errors, but still fails, as there's a dependency on fs:

$ wrangler publish
👀  ./node_modules/winston/dist/winston/tail-file.js
Module not found: Error: Can't resolve 'fs' in '/path/to/project/node_modules/winston/dist/winston'

@DABH
Copy link
Contributor

DABH commented Mar 16, 2022

There should be some polyfill for the fs module out there you can use. Or even better, see if you can trick Node into using the browser version of Winston (https://github.com/winstonjs/winston/blob/master/package.json#L59), which is designed to not rely on serverside modules like fs.

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

3 participants