In the weighted logrank tests such as Fleming-Harrington test and the Tarone-Ware test, certain weight functions are used to put more weight on early, middle or late events. The purpose is to maximize the power of the test. The optimal weight under an alternative depends on the true hazard functions of the groups being compared, and thus cannot be applied directly. We propose replacing the true hazard functions with their estimates and then using the estimated weights in a weighted logrank test. However, the resulting test does not control type I error correctly because the weights converge to 0 under the null in large samples. We then adjust the estimated optimal weights for correct type I error control while the resulting test still achieves improved power compared to existing weighted logrank tests, and it is shown to be robust in various scenarios. Extensive simulation is carried out to assess the proposed method and it is applied in several clinical studies in lung cancer.