We consider a portfolio optimization problem in a defaultable market. The investor can dynamically choose a consumption rate and allocate his/her wealth among three financial securities: a defaultable perpetual bond, a default-free risky asset, and a money market account. Both the default risk premium and the default intensity of the defaultable bond are assumed to rely on some stochastic factor which is described by a diffusion process. The goal is to maximize the infinite-horizon expected discounted log utility of consumption. We apply the dynamic programming principle to deduce a Hamilton-Jacobi-Bellman equation. Then an optimal Markov control policy and the optimal value function is explicitly presented in a verification theorem. Finally, a numerical analysis is presented for illustration.