1## This Source Code Form is subject to the terms of the Mozilla Public 2## License, v. 2.0. If a copy of the MPL was not distributed with this 3## file, You can obtain one at https://mozilla.org/MPL/2.0/. 4## 5## Copyright (c) 2019-2021 VMware, Inc. or its affiliates. All rights reserved. 6 7defmodule RabbitMQ.CLI.Diagnostics.Commands.LogTailCommand do 8 @moduledoc """ 9 Displays standard log file location on the target node 10 """ 11 @behaviour RabbitMQ.CLI.CommandBehaviour 12 13 alias RabbitMQ.CLI.Core.LogFiles 14 15 def switches, do: [number: :integer, timeout: :integer] 16 def aliases, do: ['N': :number, t: :timeout] 17 18 def merge_defaults(args, opts) do 19 {args, Map.merge(%{number: 50}, opts)} 20 end 21 use RabbitMQ.CLI.Core.AcceptsNoPositionalArguments 22 23 def run([], %{node: node_name, timeout: timeout, number: n}) do 24 case LogFiles.get_default_log_location(node_name, timeout) do 25 {:ok, file} -> 26 :rabbit_misc.rpc_call(node_name, 27 :rabbit_log_tail, :tail_n_lines, [file, n], 28 timeout) 29 error -> error 30 end 31 end 32 33 use RabbitMQ.CLI.DefaultOutput 34 35 def help_section(), do: :observability_and_health_checks 36 37 def description(), do: "Prints the last N lines of the log on the node" 38 39 def usage, do: "log_tail [--number|-N <number>]" 40 41 def usage_additional do 42 [ 43 ["<number>", "number of lines to print. Defaults to 50"] 44 ] 45 end 46 47 def banner([], %{node: node_name, number: n}) do 48 "Last #{n} log lines on node #{node_name} ..." 49 end 50end 51