Sha256: 89093887433a08195cae2e579bdb663f8a04af92956a8f292fc81cd9215c6a51

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 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"></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('<p class="text-info">' + data.server_uuid + '</p>')
              .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)) %>
      <a href="?file=<%= relative_file %>"><%= file %></a>
    <% end %>
  <% end %>

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tailog-0.2.3 app/views/logs/index.erb