| #!/bin/bash | |
| # Copyright 2018 The Fuchsia Authors. All rights reserved. | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| ### Listen for logs | |
| ## usage: fx syslog [--raw] [flags] | |
| ## | |
| ## Creates an SSH connection with a device and starts listening for logs. | |
| ## Pass -h to get help with log-listener flags. | |
| ## pass --raw as the first argument to get the raw, unsymbolized logs. | |
| set -o pipefail | |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/lib/vars.sh | |
| function listen { | |
| trap "exit 0" INT | |
| while true; do | |
| addr="$(get-fuchsia-device-addr --nowait --timeout=1000)" | |
| if [[ -n "${addr}" ]]; then | |
| echo "Connecting to device (${addr})..." | |
| (fx-command-exec ssh "${addr}" log_listener "$@" || true) | |
| if [[ $? -eq 0 ]]; then | |
| break | |
| fi | |
| fi | |
| done | |
| } | |
| echo "Looking for device" | |
| if [[ $# > 0 && "$1" = "--raw" ]]; then | |
| shift | |
| listen "$@" | |
| else | |
| listen "$@" | fx-symbolize | |
| fi |