-
-
Save anton-x-t/859a69d0426ed1e4040660f57229c76c to your computer and use it in GitHub Desktop.
Revisions
-
anton-x-t revised this gist
Aug 3, 2023 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -54,9 +54,7 @@ process.stdin.on('data', function(data) { const match = data.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z/g); if (match) { match.forEach(dateUtc => { const dateLocal = toIsoString(new Date(dateUtc)); data = data.replace(dateUtc, dateLocal); }); } -
anton-x-t revised this gist
Aug 2, 2023 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,6 +17,10 @@ * thank you Steven Moseley, * https://stackoverflow.com/a/17415677 * * ISO 8601 - Wikipedia, * thank you Wikipedia Contributors, * https://en.wikipedia.org/wiki/ISO_8601 * * docker-logs-localtime, * thank you popstas, * https://gist.github.com/popstas/ffcf282492fd78389d1df2ab7f31052a -
anton-x-t revised this gist
Aug 2, 2023 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,10 @@ * thank you anton-x-t, * https://gist.github.com/anton-x-t/859a69d0426ed1e4040660f57229c76c * * MDN Date, getMilliseconds(), * thank you MDN, * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_components_and_time_zones * * How to ISO 8601 format a Date with Timezone Offset in JavaScript?, * thank you Steven Moseley, * https://stackoverflow.com/a/17415677 -
anton-x-t revised this gist
Aug 2, 2023 . 1 changed file with 42 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,35 +1,56 @@ #!/usr/bin/env node /* * replace all UTC dates to local datetime with timezone offset through pipe * usage: docker logs -ft container_name | docker-logs-localtime * * Credits: * * docker-logs-localtime, * thank you anton-x-t, * https://gist.github.com/anton-x-t/859a69d0426ed1e4040660f57229c76c * * How to ISO 8601 format a Date with Timezone Offset in JavaScript?, * thank you Steven Moseley, * https://stackoverflow.com/a/17415677 * * docker-logs-localtime, * thank you popstas, * https://gist.github.com/popstas/ffcf282492fd78389d1df2ab7f31052a * * docker-logs-localtime, * thank you HuangYingNing, * https://github.com/HuangYingNing/docker-logs-localtime */ function toIsoString(date) { var tzo = -date.getTimezoneOffset(), dif = tzo >= 0 ? '+' : '-', pad = function(num) { return (num < 10 ? '0' : '') + num; }; return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) + 'T' + pad(date.getHours()) + ':' + pad(date.getMinutes()) + ':' + pad(date.getSeconds()) + '.' + pad(date.getMilliseconds()) + dif + pad(Math.floor(Math.abs(tzo) / 60)) + ':' + pad(Math.abs(tzo) % 60); } process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', function(data) { data = data.replace(/\d{2}:\d{2}:\d{2}\.\d{3} /g, ''); const match = data.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z/g); if (match) { match.forEach(dateUtc => { const d = new Date(dateUtc); const offset = new Date().getTimezoneOffset() * 60000; const dateLocal = toIsoString(new Date(d.getTime() - offset)); data = data.replace(dateUtc, dateLocal); }); } process.stdout.write(data); }); -
anton-x-t revised this gist
Jul 31, 2023 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,7 @@ // curl https://gist.github.com/popstas/ffcf282492fd78389d1df2ab7f31052a/raw/505cdf97c6a1edbb10c3b2b64e1836e0627b87a0/docker-logs-localtime > /usr/local/bin/docker-logs-localtime && chmod +x /usr/local/bin/docker-logs-localtime // alternative: https://github.com/HuangYingNing/docker-logs-localtime // Thank you popstas for the gist! https://gist.github.com/popstas/ffcf282492fd78389d1df2ab7f31052a const pad = d => (d > 9 ? d : '0' + d); -
anton-x-t revised this gist
Jul 31, 2023 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,9 +11,9 @@ const pad = d => (d > 9 ? d : '0' + d); Date.prototype.outDateTime = function() { return ( [this.getFullYear(), pad(this.getMonth() + 1), pad(this.getDate())].join('-')// + //' ' + //[pad(this.getHours()), pad(this.getMinutes()), pad(this.getSeconds())].join(':') ); }; -
popstas revised this gist
Mar 4, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,8 @@ // install: // curl https://gist.github.com/popstas/ffcf282492fd78389d1df2ab7f31052a/raw/505cdf97c6a1edbb10c3b2b64e1836e0627b87a0/docker-logs-localtime > /usr/local/bin/docker-logs-localtime && chmod +x /usr/local/bin/docker-logs-localtime // alternative: https://github.com/HuangYingNing/docker-logs-localtime const pad = d => (d > 9 ? d : '0' + d); Date.prototype.outDateTime = function() { -
popstas revised this gist
Jan 30, 2020 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,11 +2,14 @@ // replace all UTC dates to local dates in pipe // usage: docker logs -t container_name | docker-logs-localtime // install: // curl https://gist.github.com/popstas/ffcf282492fd78389d1df2ab7f31052a/raw/505cdf97c6a1edbb10c3b2b64e1836e0627b87a0/docker-logs-localtime > /usr/local/bin/docker-logs-localtime && chmod +x /usr/local/bin/docker-logs-localtime const pad = d => (d > 9 ? d : '0' + d); Date.prototype.outDateTime = function() { return ( [this.getFullYear(), pad(this.getMonth() + 1), pad(this.getDate())].join('-') + ' ' + [pad(this.getHours()), pad(this.getMinutes()), pad(this.getSeconds())].join(':') ); -
popstas revised this gist
Jan 30, 2020 . 1 changed file with 4 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,12 @@ #!/usr/bin/env node // replace all UTC dates to local dates in pipe // usage: docker logs -t container_name | docker-logs-localtime const pad = d => (d > 9 ? d : '0' + d); Date.prototype.outDateTime = function() { return ( [this.getFullYear(), pad(this.getDate()), pad(this.getMonth() + 1)].join('-') + ' ' + [pad(this.getHours()), pad(this.getMinutes()), pad(this.getSeconds())].join(':') ); @@ -23,7 +19,9 @@ process.stdin.on('data', function(data) { const match = data.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/g); if (match) { match.forEach(dateUtc => { const d = new Date(dateUtc); const offset = new Date().getTimezoneOffset() * 60000; const dateLocal = new Date(d.getTime() - offset).outDateTime(); data = data.replace(dateUtc, dateLocal); }); } -
popstas revised this gist
Feb 6, 2019 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,16 @@ #!/usr/bin/env node // replace all UTC dates to local dates in pipe // install: // curl https://gist.github.com/popstas/ffcf282492fd78389d1df2ab7f31052a/raw/505cdf97c6a1edbb10c3b2b64e1836e0627b87a0/docker-logs-localtime > /usr/local/bin/docker-logs-localtime && chmod +x /usr/local/bin/docker-logs-localtime // usage: docker logs -t container_name | docker-logs-localtime const pad = d => (d > 9 ? d : '0' + d); Date.prototype.outDateTime = function() { return ( [this.getFullYear(), pad(this.getMonth() + 1), pad(this.getDate())].join('-') + ' ' + [pad(this.getHours()), pad(this.getMinutes()), pad(this.getSeconds())].join(':') ); -
popstas created this gist
Jan 23, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ #!/usr/bin/env node // replace all UTC dates to local dates in pipe // usage: docker logs -t container_name | docker-logs-localtime const pad = d => (d > 9 ? d : '0' + d); Date.prototype.outDateTime = function() { return ( [this.getFullYear(), pad(this.getDate()), pad(this.getMonth() + 1)].join('-') + ' ' + [pad(this.getHours()), pad(this.getMinutes()), pad(this.getSeconds())].join(':') ); }; process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', function(data) { data = data.replace(/\.\d+Z /g, ' '); const match = data.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/g); if (match) { match.forEach(dateUtc => { const dateLocal = new Date(dateUtc).outDateTime(); data = data.replace(dateUtc, dateLocal); }); } process.stdout.write(data); });