LogView.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <section class="log-view">
  3. <b-loading :active="loading" :is-full-page="false" />
  4. <div class="lines" ref="lines">
  5. <template v-for="(l, i) in lines">
  6. <span :set="line = splitLine(l)" :key="i" class="line">
  7. <span class="timestamp" :title="line.file">{{ line.timestamp }}</span>
  8. <span class="message">{{ line.message }}</span>
  9. </span>
  10. </template>
  11. </div>
  12. </section>
  13. </template>
  14. <script>
  15. // Regexp for splitting log lines in the following format to
  16. // [timestamp] [file] [message].
  17. // 2021/05/01 00:00:00 init.go:99: reading config: config.toml
  18. const reFormatLine = new RegExp(/^([0-9\s:/]+) (.+?\.go:[0-9]+):\s/g);
  19. export default {
  20. name: 'LogView',
  21. props: {
  22. loading: Boolean,
  23. lines: {
  24. type: Array,
  25. default: () => [],
  26. },
  27. },
  28. methods: {
  29. splitLine: (l) => {
  30. const parts = l.split(reFormatLine);
  31. return {
  32. timestamp: parts[1],
  33. file: parts[2],
  34. message: parts[3],
  35. };
  36. },
  37. formatLine: (l) => l.replace(reFormatLine, '<span class="stamp">$1</span> '),
  38. },
  39. watch: {
  40. lines() {
  41. this.$nextTick(() => {
  42. this.$refs.lines.scrollTop = this.$refs.lines.scrollHeight;
  43. });
  44. },
  45. },
  46. };
  47. </script>