Java中OpenLog集成指导:severity level设置及代码示例请求
Hey there! Let's sort out how to correctly pass the severity level parameter for your OpenLog integration.
First, most logging libraries (including OpenLog) use an enumerated type (enum) to define severity levels—common values are ERROR, WARNING, INFO, DEBUG, etc. The logError method you're calling expects this enum as the fourth parameter.
Looking at your original code snippet:
if (db.isOpen()){ //perform action }else{ OpenLogUtil.logError(session, null, Utils.getSession().getEffectiveUserName() + " has unsufficient access for database: " + sourceDB.getFileName(), ?? , null); }
Since you're logging a permission failure that blocks database access (a clear error scenario), you'll want to use the ERROR severity level. Assuming OpenLog defines an enum like OpenLogSeverity (check your library's docs or imports for the exact name), here's the updated working code:
if (db.isOpen()){ //perform action }else{ // Replace OpenLogSeverity.ERROR with the actual enum constant from your OpenLog implementation OpenLogUtil.logError(session, null, Utils.getSession().getEffectiveUserName() + " has insufficient access for database: " + sourceDB.getFileName(), OpenLogSeverity.ERROR, null); }
Quick Tips:
- Double-check the enum name: It might be called
SeverityLevel,LogLevel, or something else—look for the enum class that defines severity values in your OpenLog setup. - Match severity to the scenario: If this was a non-blocking issue (like a missing optional config), you could use
WARNING, but since this is a critical access failure,ERRORis the right choice. - Don't forget to import the enum class at the top of your file (e.g.,
import com.yourpackage.openlog.OpenLogSeverity;) to avoid compilation errors.
内容的提问来源于stack exchange,提问作者Malin

