Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
ปรับแต่ง iOS Logging
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
การบันทึก iOS ได้รับการจัดการโดย IOSLogHandler.java
ซึ่งจะลบล้าง java.util.logging.Handler คุณสามารถตั้งเป็นค่าเริ่มต้นได้โดยการเพิ่มทรัพยากร logging.properties ไปยัง
แอปของคุณ ตามที่แสดงใน LogManager
การเปลี่ยนเครื่องจัดการการบันทึกแบบเป็นโปรแกรม
หากต้องการเพิ่มเครื่องจัดการการบันทึกแบบเป็นโปรแกรม ให้ใช้โค้ดเดียวกับที่ใช้เปลี่ยนแปลงใน Java
LogManager.getLogger("").addHandler(myHandler);
หากคุณไม่ต้องการให้ตัวแฮนเดิลที่มีอยู่ทำงานด้วย ให้นำตัวแฮนเดิลเหล่านั้นออกก่อนโดยใช้คำสั่งต่อไปนี้
Logger logger = LogManager.getLogger("");
for (Handler h : logger.getHandlers()) {
logger.removeHandler(h);
}
การเปลี่ยนเครื่องจัดการการบันทึกด้วยไฟล์พร็อพเพอร์ตี้
หากต้องการเปลี่ยนเครื่องจัดการการบันทึกเริ่มต้นโดยใช้ไฟล์ Logging.properties คุณต้องระบุเครื่องจัดการนั้น
ดังนี้ (เช่นเดียวกับแอปพลิเคชัน Java):
handlers=mycompany.mylogger.MyIOSLogHandler
java.util.logging.ConsoleHandler.level=ALL
ไฟล์นี้มีชื่อใดก็ได้ตราบใดที่มีการใช้ชื่อนั้นระหว่างการโหลด
จากนั้นให้เพิ่มไฟล์ Logging.properties เป็นทรัพยากร iOS ลงในโปรเจ็กต์
แอปพลิเคชัน J2ObjC จะต้องโหลดไฟล์คุณสมบัติอย่างชัดเจน ซึ่งต่างจากแอปพลิเคชัน Java:
static {
// Fetch a logger in case the following leaves logging in a bad state, such
// as not adding the logging.properties resource or using a different name.
Logger log = Logger.getLogger("configLogger");
try {
InputStream loggingProperties = SomeClass.class.getResourceAsStream("logging.properties");
LogManager.getLogManager().readConfiguration(loggingProperties);
} catch (IOException exception) {
log.log(Level.SEVERE, "Error in loading configuration", exception);
}
}
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-25 UTC"],[],["iOS logging uses `IOSLogHandler.java`, which can be set as the default via a `logging.properties` resource. Programmatically, handlers are added using `LogManager.getLogger(\"\").addHandler(myHandler)`. Existing handlers can be removed with `logger.removeHandler(h)`. With a property file, specify the handler (e.g., `handlers=mycompany.mylogger.MyIOSLogHandler`) and add it as an iOS resource. The property file must be explicitly loaded in a J2ObjC app using `LogManager.getLogManager().readConfiguration(loggingProperties)`.\n"]]