#!/bin/sh
# Copyright (c) 2011, Couchbase, Inc.
# All rights reserved.

progname=`basename $0`

usage() {
cat 1>&2 <<EOF
Usage: ${progname} <node> [logname]

  Examples:

    To dump the logs for node 0, try running the following command

           ${0} n_0

    To dump the error log for node 0, try running the following command

           ${0} n_0 errors
EOF
  exit 1
}

if [ x"$1" = "x" -o "$1" = "-?" -o "$1" = "--help" ]
then
   usage
fi

cd `dirname $0`

if ! [ -d logs/"$1" ]
then
  echo "Failed to locate the log files for \"$1\"." 1>&2
  exit 1
fi

if [ x"$2" != "x" ]
then
    extra_args="-log $2"
fi

exec erl -pa ebin -noshell \
         -run ns_log_browser -report_dir logs/"$1" ${extra_args} \
         -run init stop -- "$@"
