{"id":16306766,"url":"https://github.com/oalders/lwp-consolelogger","last_synced_at":"2025-09-20T02:33:50.256Z","repository":{"id":16539381,"uuid":"19292853","full_name":"oalders/lwp-consolelogger","owner":"oalders","description":"Easy LWP tracing and debugging","archived":false,"fork":false,"pushed_at":"2024-11-19T02:01:30.000Z","size":338,"stargazers_count":6,"open_issues_count":0,"forks_count":8,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-01T23:30:53.282Z","etag":null,"topics":["debugging","hacktoberfest","lwp","perl","perl5","useragent"],"latest_commit_sha":null,"homepage":"https://metacpan.org/pod/LWP::ConsoleLogger::Easy","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oalders.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-04-29T21:59:21.000Z","updated_at":"2024-12-06T17:42:47.000Z","dependencies_parsed_at":"2024-06-18T20:06:11.566Z","dependency_job_id":"3ceae004-8eb4-467e-aa7e-7ff0feae5662","html_url":"https://github.com/oalders/lwp-consolelogger","commit_stats":{"total_commits":257,"total_committers":10,"mean_commits":25.7,"dds":0.0778210116731517,"last_synced_commit":"e0d7033b22dc7569418f6ef89e74fba714adcfcf"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oalders%2Flwp-consolelogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oalders%2Flwp-consolelogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oalders%2Flwp-consolelogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oalders%2Flwp-consolelogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oalders","download_url":"https://codeload.github.com/oalders/lwp-consolelogger/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233619155,"owners_count":18703688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debugging","hacktoberfest","lwp","perl","perl5","useragent"],"created_at":"2024-10-10T21:11:34.801Z","updated_at":"2025-09-20T02:33:44.852Z","avatar_url":"https://github.com/oalders.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nLWP::ConsoleLogger - LWP tracing and debugging\n\n# VERSION\n\nversion 1.000001\n\n# SYNOPSIS\n\nThe simplest way to get started is by adding [LWP::ConsoleLogger::Everywhere](https://metacpan.org/pod/LWP%3A%3AConsoleLogger%3A%3AEverywhere)\nto your code and then just watching your output.\n\n    use LWP::ConsoleLogger::Everywhere ();\n\nIf you need more control, look at [LWP::ConsoleLogger::Easy](https://metacpan.org/pod/LWP%3A%3AConsoleLogger%3A%3AEasy).\n\n    use LWP::ConsoleLogger::Easy qw( debug_ua );\n    use WWW::Mechanize;\n\n    my $mech           = WWW::Mechanize-\u003enew;   # or LWP::UserAgent-\u003enew() etc\n    my $console_logger = debug_ua( $mech );\n    $mech-\u003eget( 'https://metacpan.org' );\n\n    # now watch the console for debugging output\n    # turn off header dumps\n    $console_logger-\u003edump_headers( 0 );\n\n    $mech-\u003eget( $some_other_url );\n\nTo get down to the lowest level, use LWP::ConsoleLogger directly.\n\n    my $ua = LWP::UserAgent-\u003enew( cookie_jar =\u003e {} );\n    my $console_logger = LWP::ConsoleLogger-\u003enew(\n        dump_content       =\u003e 1,\n        dump_text          =\u003e 1,\n        content_pre_filter =\u003e sub {\n            my $content      = shift;\n            my $content_type = shift;\n\n            # mangle content here\n            # ...\n\n            return $content;\n        },\n    );\n\n    $ua-\u003edefault_header(\n        'Accept-Encoding' =\u003e scalar HTTP::Message::decodable() );\n\n    $ua-\u003eadd_handler( 'response_done',\n        sub { $console_logger-\u003eresponse_callback( @_ ) } );\n    $ua-\u003eadd_handler( 'request_send',\n        sub { $console_logger-\u003erequest_callback( @_ ) } );\n\n    # now watch debugging output to your screen\n    $ua-\u003eget( 'http://nytimes.com/' );\n\nSample output might look like this.\n\n    GET http://www.nytimes.com/2014/04/24/technology/fcc-new-net-neutrality-rules.html\n\n    GET params:\n    .-----+-------.\n    | Key | Value |\n    +-----+-------+\n    | _r  | 1     |\n    | hp  |       |\n    '-----+-------'\n\n    .-----------------+--------------------------------.\n    | Request Header  | Value                          |\n    +-----------------+--------------------------------+\n    | Accept-Encoding | gzip                           |\n    | Cookie2         | $Version=\"1\"                   |\n    | Referer         | http://www.nytimes.com?foo=bar |\n    | User-Agent      | WWW-Mechanize/1.73             |\n    '-----------------+--------------------------------'\n\n    ==\u003e 200 OK\n\n    Title: The New York Times - Breaking News, World News \u0026 Multimedia\n\n    .--------------------------+-------------------------------.\n    | Response Header          | Value                         |\n    +--------------------------+-------------------------------+\n    | Accept-Ranges            | bytes                         |\n    | Age                      | 176                           |\n    | Cache-Control            | no-cache                      |\n    | Channels                 | NytNow                        |\n    | Client-Date              | Fri, 30 May 2014 22:37:42 GMT |\n    | Client-Peer              | 170.149.172.130:80            |\n    | Client-Response-Num      | 1                             |\n    | Client-Transfer-Encoding | chunked                       |\n    | Connection               | keep-alive                    |\n    | Content-Encoding         | gzip                          |\n    | Content-Type             | text/html; charset=utf-8      |\n    | Date                     | Fri, 30 May 2014 22:37:41 GMT |\n    | NtCoent-Length           | 65951                         |\n    | Server                   | Apache                        |\n    | Via                      | 1.1 varnish                   |\n    | X-Cache                  | HIT                           |\n    | X-Varnish                | 1142859770 1142854917         |\n    '--------------------------+-------------------------------'\n\n    .--------------------------+-------------------------------.\n    | Text                                                     |\n    +--------------------------+-------------------------------+\n    | F.C.C., in a Shift, Backs Fast Lanes for Web Traffic...  |\n    '--------------------------+-------------------------------'\n\n# DESCRIPTION\n\nIt can be hard (or at least tedious) to debug mechanize scripts.  LWP::Debug is\ndeprecated.  It suggests you write your own debugging handlers, set up a proxy\nor install Wireshark.  Those are all workable solutions, but this module exists\nto save you some of that work.  The guts of this module are stolen from\n[Plack::Middleware::DebugLogging](https://metacpan.org/pod/Plack%3A%3AMiddleware%3A%3ADebugLogging), which in turn stole most of its internals\nfrom [Catalyst](https://metacpan.org/pod/Catalyst).  If you're new to LWP::ConsoleLogger, I suggest getting\nstarted with the [LWP::ConsoleLogger::Easy](https://metacpan.org/pod/LWP%3A%3AConsoleLogger%3A%3AEasy) wrapper.  This will get you up and\nrunning in minutes.  If you need to tweak the settings that\n[LWP::ConsoleLogger::Easy](https://metacpan.org/pod/LWP%3A%3AConsoleLogger%3A%3AEasy) chooses for you (or if you just want to be fancy),\nplease read on.\n\nSince this is a debugging library, I've left as much mutable state as possible,\nso that you can easily toggle output on and off and otherwise adjust how you\ndeal with the output.\n\n# CONSTRUCTOR\n\n## new()\n\nThe following arguments can be passed to new(), although none are required.\nThey can also be called as methods on an instantiated object.  I'll list them\nhere and discuss them in detail below.\n\n- `dump_content =\u003e 0|1`\n- `dump_cookies =\u003e 0|1`\n- `dump_headers =\u003e 0|1`\n- `dump_params =\u003e 0|1`\n- `dump_status =\u003e 0|1`\n- `dump_text =\u003e 0|1`\n- `dump_title =\u003e 0|1`\n- `dump_text =\u003e 0|1`\n- `dump_uri =\u003e 0|1`\n- `content_pre_filter =\u003e sub { ... }`\n- `headers_to_redact =\u003e ['Authentication', 'Foo']`\n- `params_to_redact =\u003e ['token', 'password']`\n- `text_pre_filter =\u003e sub { ... }`\n- `html_restrict =\u003e HTML::Restrict-\u003enew( ... )`\n- `logger =\u003e Log::Dispatch-\u003enew( ... )`\n- `pretty =\u003e 0|1`\n- `term_width =\u003e $integer`\n\n# SUBROUTINES/METHODS\n\n## dump\\_content( 0|1 )\n\nBoolean value. If true, the actual content of your response (HTML, JSON, etc)\nwill be dumped to your screen.  Defaults to false.\n\n## dump\\_cookies( 0|1 )\n\nBoolean value. If true, the content of your cookies will be dumped to your\nscreen.  Defaults to false.\n\n## dump\\_headers( 0|1 )\n\nBoolean value. If true, both request and response headers will be dumped to\nyour screen.  Defaults to true.\n\nHeaders are dumped in alphabetical order.\n\n## dump\\_params( 0|1 )\n\nBoolean value. If true, both GET and POST params will be dumped to your screen.\nDefaults to true.\n\nParams are dumped in alphabetical order.\n\n## dump\\_status( 0|1 )\n\nBoolean value. If true, dumps the HTTP response code for each page being\nvisited.  Defaults to true.\n\n## dump\\_text( 0|1 )\n\nBoolean value. If true, dumps the text of your page after both the\ncontent\\_pre\\_filter and text\\_pre\\_filters have been applied.  Defaults to true.\n\n## dump\\_title( 0|1 )\n\nBoolean value. If true, dumps the titles of HTML pages if your UserAgent has\na `title` method and if it returns something useful. Defaults to true.\n\n## dump\\_uri( 0|1 )\n\nBoolean value. If true, dumps the URI of each page being visited. Defaults to\ntrue.\n\n## pretty ( 0|1 )\n\nBoolean value. If disabled, request headers, response headers, content and text\nsections will be dumped without using tables. Handy for copy/pasting JSON etc\nfor faking responses later. Defaults to true.\n\n## content\\_pre\\_filter( sub { ... } )\n\nSubroutine reference.  This allows you to manipulate content before it is\ndumped.  A common use case might be stripping headers and footers away from\nHTML content to make it easier to detect changes in the body of the page.\n\n    $easy_logger-\u003econtent_pre_filter(\n    sub {\n        my $content      = shift;\n        my $content_type = shift; # the value of the Content-Type header\n        if (   $content_type =~ m{html}i\n            \u0026\u0026 $content =~ m{\u003c!--\\scontent\\s--\u003e(.*)\u003c!--\\sfooter}msx ) {\n            return $1;\n        }\n        return $content;\n    }\n    );\n\nTry to make sure that your content mangling doesn't return broken HTML as that\nmay not play well with [HTML::Restrict](https://metacpan.org/pod/HTML%3A%3ARestrict).\n\n## request\\_callback\n\nUse this handler to set up console logging on your requests.\n\n    my $ua = LWP::UserAgent-\u003enew;\n    $ua-\u003eadd_handler(\n        'request_send',\n        sub { $console_logger-\u003erequest_callback(@_) }\n    );\n\nThis is done for you by default if you set up your logging via\n[LWP::ConsoleLogger::Easy](https://metacpan.org/pod/LWP%3A%3AConsoleLogger%3A%3AEasy).\n\n## response\\_callback\n\nUse this handler to set up console logging on your responses.\n\n    my $ua = LWP::UserAgent-\u003enew;\n    $ua-\u003eadd_handler(\n        'response_done',\n        sub { $console_logger-\u003eresponse_callback(@_) }\n    );\n\nThis is done for you by default if you set up your logging via\n[LWP::ConsoleLogger::Easy](https://metacpan.org/pod/LWP%3A%3AConsoleLogger%3A%3AEasy).\n\n## text\\_pre\\_filter( sub { ... } )\n\nSubroutine reference.  This allows you to manipulate text before it is dumped.\nA common use case might be stripping away duplicate whitespace and/or newlines\nin order to improve formatting.  Keep in mind that the `content_pre_filter`\nwill have been applied to the content which is passed to the text\\_pre\\_filter.\nThe idea is that you can strip away an HTML you don't care about in the\ncontent\\_pre\\_filter phase and then process the remainder of the content in the\ntext\\_pre\\_filter.\n\n    $easy_logger-\u003etext_pre_filter(\n    sub {\n        my $content      = shift;\n        my $content_type = shift; # the value of the Content-Type header\n        my $base_url     = shift;\n\n        # do something with the content\n        # ...\n\n        return ( $content, $new_content_type );\n    }\n    );\n\nIf your `text_pre_filter()` converts from HTML to plain text, be sure to\nreturn the new content type (text/plain) when you exit the sub.  If you do not\ndo this, HTML formatting will then be applied to your plain text as is\nexplained below.\n\nIf this is HTML content, [HTML::Restrict](https://metacpan.org/pod/HTML%3A%3ARestrict) will be applied after the\ntext\\_pre\\_filter has been run.  LWP::ConsoleLogger will then strip away some\nwhitespace and newlines from processed HTML in its own opinionated way, in\norder to present you with more readable text.\n\n## html\\_restrict( HTML::Restrict-\u003enew( ... ) )\n\nIf the content\\_type indicates HTML then HTML::Restrict will be used to strip\ntags from your content in the text rendering process.  You may pass your own\nHTML::Restrict object, if you like.  This would be helpful in situations where\nyou still do want to have some tags in your text.\n\n## logger( Log::Dispatch-\u003enew( ... ) )\n\nBy default all data will be dumped to your console (as the name of this module\nimplies) using Log::Dispatch.  However, you may use your own Log::Dispatch\nmodule in order to facilitate logging to files or any other output which\nLog::Dispatch supports.\n\n## term\\_width( $integer )\n\nBy default this module will try to find the maximum width of your terminal and\nuse all available space when displaying tabular data.  You may use this\nparameter to constrain the tables to an arbitrary width.\n\n# CAVEATS\n\nI've written this to suit my needs and there are a lot of things I haven't\nconsidered.  For example, I'm mostly assuming that the content will be text,\nHTML, JSON or XML.\n\nThe test suite is not very robust either.  If you'd like to contribute to this\nmodule and you can't find an appropriate test, do add something to the example\nfolder (either a new script or alter an existing one), so that I can see what\nyour patch does.\n\n# AUTHOR\n\nOlaf Alders \u003colaf@wundercounter.com\u003e\n\n# COPYRIGHT AND LICENSE\n\nThis software is Copyright (c) 2014 by MaxMind, Inc.\n\nThis is free software, licensed under:\n\n    The Artistic License 2.0 (GPL Compatible)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foalders%2Flwp-consolelogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foalders%2Flwp-consolelogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foalders%2Flwp-consolelogger/lists"}