-1

If there is a problem in the source code, usually a programmer goes through the log manually and tries to identify the problem in the source code.

But is it possible to automate this process? Can we automate the process that would give the potential lines in the source code that was responsible for generating the fault.

So, for example:

If there is some problem in the log file. Then this automation tool should say that this problem has occurred due to line 30,31,32,35,38 in source code ABC

Thanks!!

2
  • mate, if your log doesn't show you where the program failed, you are not doing it right. If there where such a thing as an automatic source finding those lines, it would auto-correct itself.
    – Maviles
    Aug 5, 2016 at 17:10
  • I am talking about building a tool that would help in suggesting possible lines with bugs. By the way, it is obvious that you will need a correct set of working logs to make such tool.
    – John Rambo
    Aug 5, 2016 at 19:46

2 Answers 2

0

It depends on the language you are using.

In Java (and probably other JVM languages) this feature is built-in: Every exception that is thrown has a reference to the stack trace, including class, method and line number of every method involved. All you need to do is something like

exception.printStackTrace();

In C and C++, you can use preprocessor macros like __FUNCTION__ or __LINE__ when throwing an exception or writing a log message, for example:

throw "Error in " + __FUNCTION__ + ", line " + std::to_string(__LINE__);

The macros will be replaced by the current function and the current line.

If you are looking for a method that works with any language and any type of logging, there is no good solution. You could run a tool like grep over all source files, that will try to find matches. However this will only work if the log messages appear as string literals in source code at the position where the message is written. This is unlikely because the messages are likely to contain variable values or constants defined somewhere else.

0

Assuming we are not talking about (unit) testing, because this is what they do - show you where is the problem exactly.

Then this automation tool should say that this problem has occurred due to line 30,31,32,35,38 in source code ABC

In my team we had similar discussion and what we've come with is a Top5 most likely issues document (PlayBook). After reading logs every time on failure, we've noticed that in most of the times there is a requiring pattern. So 8 out of 10 cases the issues were following one of those patterns. So it is possible to trace the latest changes (with the help from Git). If your changes are small and frequent - this approach works quite well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.