i’m working on my discord bot.
i started running the bot from glitch, it works great other than i can’t view logs older than about an hour.
today i got the bot to log to a file on the project container.
i’m wondering how i could send that log file to a dropbox account via a dropbox file request url and then delete it from the container and start a new log file.
something like :
log the console logs
check file size of log.txt
if file is a certain size send file to url and delete file contents
any ideas or code snippets that could help me figure this one out, would be greatly appreciated!
i already have the log console logs part down, and i found a page on how to check file size, im just unsure on how to send the file from the container to the dropbox url
Hello! Here’s how I would break down the problem. There may be other solutions that work, too!
I’m keeping in mind these restrictions:
Projects sleep after 5 minutes if they are not used, and those running for more than 12 hours are stopped. They wake again when they receive another HTTP request.
Projects have a limit of 200MB of disk space on the container. Though things written to ‘/tmp’ don’t count towards that, nor do your Node.js modules. Plus, there’s an additional 512MB of assets storage space too.
Your bot writes logs to log.txt
Your server is periodically getting hit by a request from something like Uptime Robot, which keeps your bot alive. Maybe the handler for that request also checks the file size of log.txt, and uploads it to Dropbox/deletes the file contents if it’s over a certain size. Or, maybe you don’t want to do that on every request from Uptime Robot, so you set up another server endpoint to do that.
i have a 5 minute timer and an uptime robot ping, plus the bot is pretty active 24/7, even for a small server set it is used alot. and the reason im looking to upload to dropbox is the file size limits.
if i could get the file to upload and delete itself at say 100mb, id basically never have to mess with it again unless there is a error or some change i wanted to do.
im about to eat my dinner, when i finish i will look into those links you sent, thank you
I missed your most recent message while I was typing mine. I mentioned that example page from Dropbox; this link to the documentation should help you even more. It explains what you’ll need to use the Dropbox SDK (a fancy abbreviation that essentially means ‘code library’) to connect to Dropbox.
You’ll need an app key and an access token, and you’ll want those to be secret (so people who look at or remix your bot won’t be able to use your Dropbox connection.) You can keep those secret by putting the values in the .env file, and referencing them in your server like process.env.VARIABLE_NAME.
thank you for these links, i had no idea this sdk existed, this should work out perfect. now the only down side is i tore a tendon in my dominate shoulder, so its taking me 4 times as long to do anything, hunt and peck typing left handed and using my right hand built mouse with my left hand, gotta love getting hurt when sitting still… thats how you know you are getting old…
thank you for the very fast replies to, i posted this expecting to get a reply maybe by morning, not almost instantly
ReferenceError: fetch is not defined
at DropboxBase (/rbd/pnpm-volume/53ebba9e-3bf9-4875-8ea1-cbe3abd74b84/node_modules/.registry.npmjs.org/dropbox/4.0.15/node_modules/dropbox/lib/dropbox-base.js:155:35)
at new Dropbox (/rbd/pnpm-volume/53ebba9e-3bf9-4875-8ea1-cbe3abd74b84/node_modules/.registry.npmjs.org/dropbox/4.0.15/node_modules/dropbox/lib/dropbox.js:42:104)
at Object. (/app/modules/logger.js:6:11)
at Module._compile (module.js:653:30)
at Object.Module._extensions…js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
Looks like the constructor new Dropbox expects you to also pass in a variable called fetch.
You’ll probably need to add isomorphic-fetch or possibly node-fetch (I haven’t test this, though) to your package.json.
var fetch = require('isomorphic-fetch');
var Dropbox = require('dropbox').Dropbox;
var dbx = new Dropbox({ clientId: 'YOUR_CLIENT_KEY_HERE', fetch: fetch });
ok so i changed it over to isomorphic-fetch and now i have this error
Global fetch is deprecated and will be unsupported in a future version. Please pass fetch function as option when instantiating dropbox instance: new Dropbox({fetch})
i just wanted to finish this thread with a notice that i got the code to work perfectly. i have the logger system check file size every 50 logger events, if the file is 100 mbs it uploads it to my dropbox and wipes the files contents, and starts over again. thank you for all your help.