  Linear codes are widely studied due to their applications in communication,
cryptography, quantum codes, distributed storage and many other fields. In this
paper, we use the trace and norm functions over finite fields to construct a
family of linear codes. The weight distributions of the codes are determined in
three cases via Gaussian sums. The codes are shown to be self-orthogonal
divisible codes with only three, four or five nonzero weights in these cases.
In particular, we prove that this family of linear codes has locality 2.
Several optimal or almost optimal linear codes and locally recoverable codes
are derived. In particular, an infinite family of distance-optimal binary
linear codes with respect to the sphere-packing bound is obtained. The
self-orthogonal codes derived in this paper can be used to construct lattices
and have nice application in distributed storage.
