From 0cc57f1217157a45a2f40d7644722536e52ca6e1 Mon Sep 17 00:00:00 2001 From: Stephan Fuhrmann Date: Mon, 8 Jan 2024 16:26:24 +0100 Subject: [PATCH] Output line numbers in errors / warnings --- .../com/oneandone/snmpman/configuration/Walks.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/snmpman/src/main/java/com/oneandone/snmpman/configuration/Walks.java b/snmpman/src/main/java/com/oneandone/snmpman/configuration/Walks.java index 7c91938..2556d32 100644 --- a/snmpman/src/main/java/com/oneandone/snmpman/configuration/Walks.java +++ b/snmpman/src/main/java/com/oneandone/snmpman/configuration/Walks.java @@ -81,7 +81,9 @@ private static Map readVariableBindings(final File walk, final Bu OID lastOid = null; String lastType = null; String line; + int lineNumber = 0; while ((line = reader.readLine()) != null) { + lineNumber++; boolean match = false; Matcher matcher = VARIABLE_BINDING_PATTERN.matcher(line); if (matcher.matches()) { @@ -100,9 +102,9 @@ private static Map readVariableBindings(final File walk, final Bu } bindings.put(oid, variable); - log.trace("added binding with oid \"{}\" and variable \"{}\"", oid, variable); + log.trace("added binding from line {} with oid \"{}\" and variable \"{}\"", lineNumber, oid, variable); } catch (final Exception e) { - log.warn("could not parse line \"{}\" of walk file {} with exception: {}", line, walk.getCanonicalPath(), e.getMessage()); + log.warn("could not parse line {} with \"{}\" of walk file {} with exception: {}", lineNumber, line, walk.getCanonicalPath(), e.getMessage()); } } @@ -121,7 +123,8 @@ private static Map readVariableBindings(final File walk, final Bu String combined = oldString + "\n" + newString; bindings.put(lastOid, new OctetString(combined)); } else { - log.warn("Could not find the previous octet string of OID {} in walk file {}", lastOid); + log.warn("Could not find the previous octet string of OID {} in walk file {} at line {}", + lastOid, walk.getAbsolutePath(), lineNumber); } } @@ -139,13 +142,14 @@ private static Map readVariableBindings(final File walk, final Bu System.arraycopy(newBytes, 0, combined, oldBytes.length, newBytes.length); bindings.put(lastOid, new OctetString(combined)); } else { - log.warn("Could not find the previous octet string of OID {} in walk file {}", lastOid); + log.warn("Could not find the previous octet string of OID {} in walk file {} at line {}", + lastOid, walk.getAbsolutePath(), lineNumber); } } } if (!match) { - log.warn("could not parse line \"{}\" of walk file {}", line, walk.getAbsolutePath()); + log.warn("Could not parse line number {} with content \"{}\" of walk file {}", lineNumber, line, walk.getAbsolutePath()); } } return bindings;