The well log is the basis for understanding a geologic structure and evaluating petroleum reservoirs. It inevitably leads to missing logs due to borehole conditions and equipment failures. Existing machine-learning methods introduce convolutional neural networks (CNNs) in temporal networks to learn local morphological (spatial) features for improving prediction. However, they ignore the temporal background information of the logs and the differences in spatial features at different depth points. An adaptive spatiotemporal transformer (ASTT) is developed to effectively overcome these challenges, which consists of a temporal background encoder (TBE), a spatial encoder (SE), and a spatiotemporal decoder (STD). TBE introduces average pooling in the transformer encoder to learn the hidden geologic information in the extracted longitudinal temporal features. SE combines CNN and an attention mechanism to learn the spatial features of each depth point differentially. STD maps the extracted spatiotemporal features to the missing logs. Experimental results on real oilfield data indicate that our ASTT achieves excellent performance in terms of fitting degree and test error. The results in the cross-logs and crosswell cases demonstrate the generalization of ASTT.