CodeAD: Synthesize Code of Rules for Log-based Anomaly Detection with LLMs