简体   繁体   中英

How to write to Heroku's log from Javascript in a Rails app?

I have a Rails app running on Heroku, and I am wondering if there is a way to write to the log from Javascript.

Heroku's documentation says anything written to standard out (stdout) or standard error (stderr) is captured into your logs.

I am not talking about console.log - which I am already making use of - I am talking about somehow being able to write to Logplex from (Rails-app based) Javascript.

Glancing at the documentation it looks like there's no built-in way to do logging from the client. If you want to use Heroku's logging functionality (instead of, say, using a third-party service designed specifically for this sort of thing), you'll probably have to have your JavaScript make Ajax requests to your server, and have your server write to the log.

You could, of course, roll your own solution, which would be as easy as adding a new route and a controller action that reads messages from POST params and writes them to the log, but it looks like there's at least one gem specifically for this: rails-client-logger .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM