Search code examples
javaloggingcode-analysisapache-cloudstack

Why do they use different logging level here in CloudStack?


When doing logging code analysis, I found that there are some logging statements which have same log message but with different verbosity level, I'm wondering why do they do that? (Those logging statements are introduced many years ago, it's hard to get in touch with the developers who introduced them)

Such as the link Here:https://github.com/apache/cloudstack/blob/893a88d225276e45f12f9490e6af2c94a81c2965/server/src/main/java/com/cloud/network/element/VpcVirtualRouterElement.java

  if (vpcId == null) {
        s_logger.trace("Network " + network + " is not associated with any VPC");
        return false;
    }

and

 if (vpcId == null) {
        s_logger.error("Network " + network + " is not associated with any VPC");
        return routers;
    }

The log message and if condition are totally the same, then what's the purpose of using different level here?


Solution

  • When coding, conditions and messages are important but the context is even more important.

    Trace level logs expect a vpcId but if there isn't any it is not a bug because a lookup for a valid Vpc will be done later

    Error level logs expect a vpcId but if there isn't any it is a bug because no future lookup for a valid Vpc will be done later so the process will fail