SGC
May 21, 2020, 3:47pm
5
@binary I just left the log in docker and then made this for exporting it, it might as noted take a little bit of performance, but i haven’t seen more than i could barely measure it…
and then one can use docker logs commands like --follow or --tail
haven’t setup any logrotate yet, but you could if you wanted deletion features and such, i just made a compressed folder for them and left it to pile up for future me to worry about lol
it might be a bit rough around the edges pretty new in linux so…
Cron command for live appending logs, with date stamp and without redirecting logs from the storagenode container.
Wanted to keep this simple, which i didn’t, but now it works kinda great…
This will keep a 1min delayed live log saved, without having to redirect your docker log files and thus you can run all scripts by default or run stuff like docker logs storagenode --follow
how to make it work is explained in detail, below and everything is basically copy paste ready.
Enjoy… and i hope some else finds this useful.
#
# Add this to your crontab, using crontab -e
# The command will run a one line command, which maybe could have been working from only cron, but this is the best i got thus far.
#
# * * * * * (tells cron to run the storagenode_append_log.sh script every minute
# >> appends the output of the script to the log file
# $(date +\%Y-\%m-\%d) adds the current date to the log filename
# 2>&1 combines the stdout stderr into a single file (not sure if this is required tho)
#
* * * * * /storagenodes/storj/scripts/storagenode_append_log.sh >> /storagenodes/storj/logs/storagenode_$(date +\%Y-\%m-\%d).log 2>&1
### Bash script because cron cannot do variables without this getting messy
#
# filename:
# storagenode_append_log.sh
# Location (basically where ever you want,
# Tho do keep in mind to change the location / folder in the crontab -e also
# but i set the location to a scripts folder inside to storj folder.
# seems mostly empty anyways... so... where was i
# Location:
# /storagenodes/storj/storagenode_append_log.sh
# Other related information
# use chmod +x /storagenodes/storj/scripts/storagenode_append_log.sh
# this makes the script below executable
## Bash scripts starts below this point
#!/bin/bash
# Bash script for appending to storagenode log
# If anyone know how to make this into a crontab -e commandline only, don't hold back...
docker logs --since "$(date -d "$date -2 minutes" +"%Y-%m-%dT%H:%M")" --until "$(date -d "$date -1 minutes" +"%Y-%m-%dT%H:%M")" storagenode