Sha256: 4bb1971fdab681cb33064ff13c2d78ee483c30e89d53461a1b38c9ed8c906a07

Contents?: true

Size: 1.85 KB

Versions: 2

Compression:

Stored size: 1.85 KB

Contents

<% begin %>

  <% raise RuntimeError, "Tailog.log_path is not present!" unless Tailog.log_path %>

  <% if params[:file] %>
    <% file_path = File.join Tailog.log_path, params[:file] %>
    <h3 class="page-header"><%= file_path %></h3>

    <% File.open file_path do |file| %>
      <div id="content" class="content-hover"></div>
    <% end %>

    <script type="text/javascript">
      window.fileSize = {};
      window.fileSizeDone = {};
      var $window = $(window),
          $document = $(document),
          $content = $("#content");

      function loadMore() {
        $.post(window.location.href, { seek: window.fileSize }, function(json) {
          try {
            var data = JSON.parse(json);

            var fileSizeKey = data.server_uuid + '-' + data.file_size;
            if (window.fileSizeDone[fileSizeKey]) return;
            window.fileSizeDone[fileSizeKey] = true;
            window.fileSize[data.server_uuid] = data.file_size;

            if (!data.content) return;
            var shouldScrollToBottom = $window.scrollTop() + $window.height() == $document.height();
            $content
              .append('<span class="text-info">' + data.server_uuid + '</span>')
              .append(data.content);

            if (shouldScrollToBottom) {
              $window.scrollTop($document.height() - $window.height());
            }

          } catch (error) {
            console.log(error)
          }
        });
      }

      setInterval(loadMore, 3000);
      loadMore();
    </script>

  <% else %>
    <% Dir[File.join Tailog.log_path, '**/*.log'].each do |file| %>
      <% relative_file = Pathname.new(file).relative_path_from(Pathname.new(Tailog.log_path)) %>
      <p><a href="?file=<%= relative_file %>"><%= file %></a></p>
    <% end %>
  <% end %>

<% rescue => error %>
  <%= erb :error, locals: { error: error }, layout: false %>
<% end %>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tailog-0.3.1 app/views/logs/index.erb
tailog-0.3.0 app/views/logs/index.erb