NAME

Log::ger::Manual::Tutorial::100_WhatIsLogging - What is logging? Why logging? Logging vs ...

VERSION

version 0.040.000

DESCRIPTION

WHAT IS LOGGING?

Logging is recording information during run-time. You can log any kind of information for whatever purposes. Logging is most often used for debugging; you can dump internal data structures, record warn/die message along with their stack trace, or mark entering/leaving subroutines to trace the flow of program execution. Logging can also be used to show the progress of a long-running activity, to give users feedback so they know what's going on. Other uses of logging include: auditing, accounting, security monitoring, source code documentation, and so on.

To start logging with Log::ger, all you have to do is use Log::ger (or require and import) then start peppering logging statements. For example:

use Log::ger;

sub process_user {
    log_trace("Entering process_user(%s)", \@_);

    ...

    log_trace("Leaving process_user(), result=%s", $res);
    return $res;
}

log_trace("Starting program");
for my $user (@ARGV) {
    log_info("Processing user %s", $user);
    process_user($user);
}
log_trace("Ending program");

WHY LOGGING? LOGGING VS ...

Compared to using a debugger (with standard features like single-stepping, breakpoints, watchpoints, etc), logging can help diagnose problems while you run an application normally in production environment, as opposed to having to stop a program and run it under the debugger. Of course, a proper debugger has its strengths too.

Compared to peppering "print" statements all over your program, logging using a framework brings the flexibility of turning on/off the statements according to the notion of level/severity (or other criteria), and redirecting where the log messages should go. On the other hand, "print" statement is simpler and does not require extra module/framework.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2022, 2020, 2019, 2018, 2017 by perlancar <perlancar@cpan.org>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.