58 Commits

Author SHA1 Message Date
Mike Fährmann
1e7f4ee178 [output] add 'defer' option for logging files (#8523)
- defer file creation of error files by default
- implement custom FileHandler class
  to support deferred directory creation
2025-11-27 19:23:04 +01:00
Mike Fährmann
8c62be343e [output] add 'Logger.traceback()' helper 2025-10-14 18:44:29 +02:00
Mike Fährmann
fec37c50f0 fix accessing methods through 'path-metadata' pathfmt proxy (#6582)
https://github.com/mikf/gallery-dl/issues/6582#issuecomment-3193498152
2025-08-16 15:54:06 +02:00
Mike Fährmann
b47c9b6e91 [output] use f-strings for concatenations (#7671) 2025-08-03 09:50:13 +02:00
Mike Fährmann
f00157da40 [output] remove 'stream.reconfigure()' fallback (#7671) 2025-08-03 09:19:32 +02:00
Mike Fährmann
a097a373a9 simplify if statements by using walrus operators (#7671) 2025-07-22 20:57:54 +02:00
Mike Fährmann
9dbe33b6de replace old %-formatted and .format(…) strings with f-strings (#7671)
mostly using flynt
https://github.com/ikamensh/flynt
2025-06-29 17:50:19 +02:00
Mike Fährmann
e08ec7e083 update copyright notices 2025-06-13 00:03:41 +02:00
Mike Fährmann
811b665e33 remove @staticmethod decorators
There might have been a time when calling a static method was faster
than a regular method, but that is no longer the case. According to
micro-benchmarks, it is 70% slower in CPython 3.13 and it also makes
executing the code of a class definition slower.
2025-06-12 22:50:52 +02:00
Mike Fährmann
76f855d87b [output] use ANSI colors only when stream is a TTY 2024-10-28 19:36:42 +01:00
Mike Fährmann
ee61256054 [output] define and use global TTY_STD... values 2024-10-28 14:59:14 +01:00
Mike Fährmann
e93b8efe7b [output] make it easier to disable output to stdout
allow 'output.mode' to be set to any falsy value
instead of requiring it to be the string "null"
2024-10-28 14:49:52 +01:00
Mike Fährmann
f7a6401031 [actions] move LoggerAdapter from 'output' to 'actions' 2024-06-30 20:41:51 +02:00
Mike Fährmann
9671bd6d40 [actions] fix exception when 'msg' is not a string (#5683) 2024-06-18 16:49:45 +02:00
Mike Fährmann
dc9d83e64b [output] support 'NO_COLOR' environment variable 2024-05-03 12:25:41 +02:00
Mike Fährmann
20e2c0042b [output] enable colors by default 2024-04-20 20:51:20 +02:00
Mike Fährmann
14b38264e0 [output] extend 'output.colors' (#2566)
allow specifying ANSI colors for all loglevels
(debug, info, warning, error)
2024-04-20 20:50:58 +02:00
Mike Fährmann
d921d860f1 automatically create directory path for logging files (#5249) 2024-02-28 02:11:20 +01:00
Mike Fährmann
75697dfb26 implement -e/--error-file as a logging handler
similar to --write-unsupported
2023-12-10 00:06:39 +01:00
Mike Fährmann
e46efbd5b5 prevent crash when 'stdout.line_buffering' is not defined (#642) 2023-10-29 15:32:11 +01:00
Mike Fährmann
f7ce33c85c [output] set 'errors=replace' for output streams (#3765)
fixes regression from e480a933
2023-03-14 13:30:04 +01:00
Mike Fährmann
4235d412c4 implement 'actions'
continuation of d37e7f48
but more versatile and extendable

Example:

"actions": [
    # change debug messages to info
    ["debug", "level ~info"],

    # change exit status to a non-zero value
    ["info:^No results for", "status |= 1"],

    # exit with status 2 on 429
    ["warning:429", "exit 2"],

    # restart extractor when no cookies found
    ["warning:^[Nn]o .*cookies", "restart"]
]
2023-03-10 22:08:10 +01:00
Mike Fährmann
e480a93337 add 'output.stdout', '.stdin', and '.stderr' options
(#1621, #2152, #2529)

Allow setting custom input/output encodings and options
without having to rely on Python's defaults.
2023-02-26 14:56:19 +01:00
Mike Fährmann
d37e7f4898 add 'hooks' option
Very much a work in progress.

At the moment, it allows to
- wait and restart an extractor (#3338)
- change the exit code (#3630)
- change the log level of a logging message
based on the contents of a logging message
2023-02-13 13:33:42 +01:00
Mike Fährmann
7d1a95ada6 implement 'path-metadata' option (#2734) 2022-07-30 12:31:45 +02:00
Mike Fährmann
7990fe84f1 support user-defined 'output.mode' settings (#2529)
work in progress

the same output as produced by "mode": "color" can be achieved with

"output": {
    "mode": {
        "start"  : "{}",
        "success": "\r\u001b[1;32m{}\u001b[0m\n",
        "skip"   : "\u001b[2m{}\u001b[0m\n",
        "progress"      : "\r{0:>7}B {1:>7}B/s ",
        "progress-total": "\r{3:>3}% {0:>7}B {1:>7}B/s "
    }
}

to make 'output.shorten' work correctly, it is necessary to manually
specify the number of extra characters:

        "start"  : [12, "Downloading {}"]
2022-05-27 15:03:54 +02:00
Mike Fährmann
44ffc017ea remove useless 'tries' argument from out.success 2022-05-24 10:45:09 +02:00
Mike Fährmann
cf16f9a407 [output] introduce 'stdout_write()' etc (#2529) 2022-05-18 18:29:07 +02:00
Mike Fährmann
eeef9ccdc1 explicitly flush all writes to stdout (#2529) 2022-05-17 13:26:53 +02:00
Mike Fährmann
61887c895b implement 'output.colors' options (#2532) 2022-05-02 12:41:14 +02:00
Mike Fährmann
0054ad434e [output] write directly to sys.stdout 2021-11-29 04:41:29 +01:00
Mike Fährmann
da14b3fe9f [output] write download progress indicator to stderr 2021-11-29 04:41:17 +01:00
Mike Fährmann
28f1c36da2 simplify and adjust download progress indicator (#1519) 2021-09-29 18:40:36 +02:00
Mike Fährmann
c22ff97743 remove 'unit' argument from 'util.format_value()' 2021-09-28 23:07:55 +02:00
Mike Fährmann
d0761454b1 implement a download progress indicator (#1519) 2021-09-28 22:48:58 +02:00
Mike Fährmann
74145467dd move 'util.Formatter' into its own 'formatter' module 2021-09-27 02:37:04 +02:00
Mike Fährmann
bd845303ad implement a way to shorten filenames with east-asian characters
(#1377)

Setting 'output.shorten' to "eaw" (East-Asian Width) uses a slower
algorithm that also considers characters with a width > 1.
2021-09-13 21:38:33 +02:00
Mike Fährmann
e300da1424 add 'output.skip' option 2021-05-04 19:27:18 +02:00
Mike Fährmann
c8787647ed add global WINDOWS bool 2020-05-19 22:32:53 +02:00
Mike Fährmann
ece73b5b2a make 'path' and 'keywords' available in logging messages
Wrap all loggers used by job, extractor, downloader, and postprocessor
objects into a (custom) LoggerAdapter that provides access to the
underlying job, extractor, pathfmt, and kwdict objects and their
properties.

__init__() signatures for all downloader and postprocessor classes have
been changed to take the current Job object as their first argument,
instead of the current extractor or pathfmt.

(#574, #575)
2020-05-18 19:04:51 +02:00
Mike Fährmann
11d3247c85 use 'util.Formatter' when formatting logging output 2020-05-10 00:09:06 +02:00
Mike Fährmann
4bc161ca0f prevent crash when sys.stdout and co. are None (#653) 2020-03-23 23:38:55 +01:00
Mike Fährmann
5cdf1b1319 fix --verbose/--quiet
caused by 383795b
2020-02-17 22:29:51 +01:00
Mike Fährmann
383795b550 prevent superfluous calls to Logger.makeRecord()
… by setting an appropriate minimal logging level for the root Logger.
2020-01-30 15:19:06 +01:00
Mike Fährmann
f5604492c3 update interface of config functions 2019-11-24 00:42:28 +01:00
Mike Fährmann
15e4ddf46d implement custom logging formatter
supports custom log message formats for each loglevel and, by
extension, custom ANSI codes and colors for errors and warnings

(#304)
2019-06-21 20:17:58 +02:00
Mike Fährmann
ae353ed3b0 provide "extractor" and "job" keys for logging output
This allows for stuff like "{extractor.url}" and "{extractor.category}"
in logging format strings.
Accessing 'extractor' and 'job' in any way will return "None" if those
fields aren't defined, i.e. in general logging messages.
2019-02-14 11:09:58 +01:00
Mike Fährmann
4810d446bb remove the obsolete safeprint() and error() functions
- safeprint() was used to print values which might have caused a
  UnicodeEncodeError, but that is no longer necessary (0381ae5)
- errors are now handled via logging output (f94e370)
2018-04-05 13:10:33 +02:00
Mike Fährmann
79bcaa8726 improve downloader retry behavior
- only retry download on 5xx and 429 status codes
- immediately fail on 4xx status codes
2017-11-10 21:46:18 +01:00
Mike Fährmann
701c016b97 add '-q/--quiet' option 2017-04-26 11:33:19 +02:00