-2

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?

  • Hint: If you are going to analyse log files, you need to understand the code that generated them. Asking someone else to explain the code to you is ... outsourcing your job to someone else. – Stephen C Mar 18 '18 at 00:30

1 Answers1

1

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

Mumrah81
  • 2,034
  • 2
  • 16
  • 23