anchor.diff:          {stop, _, State2} -> State2
       end.
   
  -terminate(Reason, #state{port = P} = _State) when not is_port(P) ->
  +terminate(Reason, #state{port = undefined} = _State) ->
       ?log_debug("doing nothing in terminate(~p) because port is not active", [Reason]),
       ok;
  -terminate(shutdown, #state{port = Port, name = Name} = State) ->
  +terminate(shutdown, #state{port = Port} = State) ->
       ShutdownCmd = misc:get_env_default(ns_babysitter, port_shutdown_command, "shutdown"),
  -    ?log_debug("Sending ~s to port ~p", [ShutdownCmd, Name]),
  +    ?log_debug("Sending ~s to port ~p", [ShutdownCmd, port_name(State)]),
       port_command(Port, [ShutdownCmd, 10]),
       State2 = wait_for_child_death(State),
  -    ?log_debug("~p has exited", [Name]),
  +    ?log_debug("~p has exited", [port_name(State)]),
       log(State2); % Log any remaining messages
   terminate(_Reason, State) ->
       log(State). % Log any remaining messages
  
positive.code:         [] ->
              ok;
          Buf ->
              ?log_info(format_lines(State#state.name, lists:reverse(Buf))),
              case State#state.dropped of
                  0 ->
                      ok;
                  Dropped ->
                      ?log_warning("Dropped ~p log lines from ~p",
                                   [Dropped, State#state.name])
              end
      end,
      State#state{log_tref=undefined, log_buffer=[], dropped=0};
  
negative.code:     State1 = log(State),
      {noreply, State1};
  handle_info({_Port, {exit_status, Status}}, State) ->
      ns_crash_log:record_crash({port_name(State),
                                 Status,
                                 string:join(ringbuffer:to_list(State#state.messages), "\n")}),
      {stop, {abnormal, Status}, State};
  