winstonjs / winston-syslog

A syslog transport for winston
http://github.com/winstonjs/winston-syslog
MIT License
138 stars 119 forks source link

cloudflare workers support #179

Open seguri opened 2 years ago

seguri commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

seguri commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.