-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin name disappeared from log messages #3353
Comments
To preface everything else, let me just say that getting logging right is hard. The default terminal is often only 80 characters wide, and a large site can generate thousands of lines of logging as it is; the volume can make it hard to find the details you need. For reference, the switch to logging with Moving to the new (i.e. current) logging system I found was better for displaying where it was coming from, as it added the calling file to the right margin. I don't think the old system displayed filenames unless it hit an error (and I think the new system still does that). As for the proposals, for No 1, I've implemented a variation of this with my own plugins, where I will prefix a shortname of the plugin to the log message is displays. The actual code is: from .constants import LOG_PREFIX # LOG_PREFIX = "[Microblog]"
logger = logging.getLogger(__name__)
def some_function():
# the rest of the function
logger.warning(
'%s micropost "%s" longer than expected (%s > %s).'
% (
LOG_PREFIX,
relative_filename,
post_len,
settings["MICROBLOG_MAX_LENGTH"],
) There may be a case for providing a Pelican hook for providing the logging prefix; I'm not sure what I think about trying to automatically determine one. In any case, I think logging from Pelican doesn't been to specifically be prefixed. As for No 2, I think this is too much to put on the right margin, because it would make the main logging message take up many more lines on narrow (and even "normal") terminals. |
Well, for starter, we wasted 12 columns just for the timestamp, so there is something to be said about precious real estate space. Do we even need timestamp??? Honestly, Pelican is inherently a sequential processor, nothing special about multiple sub-tasking nor sub-processes. A single line having a single date timestamp is more than sufficient, for all sense and purposes: datetime = <insert favorite time routine>
logger.info(datetime) Heck, put two: one for start, one for end of Pelican session. Also, doing EXISTING plugin development (oh let's say, upgrading to 4.0 plugin scheme), the filename is inherently useless for many. During plugin development, this class-nesting of 'name' seems a lot more practical (in terms of development) than anything else (but not wanting to diminish the filename/line-number scheme here). So, are we to be deigned in keeping it harder to do new (or old) plugin (re-)development? |
Notice the word "plugins"? It is already in place via The only reason why I looked into other column placement is because of excessive wraparounds, which we could fix perhaps by removing the timestamp column. Again, do we really, REALLY need a timestamp column? (asking for a co-worker). Nothing I suggested would require changes to the existing code base for all plugins, just leveraging the |
Don't get me wrong, I absolutely love the RichHandler stuff, just the timestamp, if made a configurable CLI option may make this easier to read longer output. Maybe picking up the terminal width and passing that as well, but I dunno as to its extensibility of RichFormat, what do you think, @MinchinWeb ? Something like in terminal_width = 80
try:
terminal_width = os.get_terminal_size()
if terminal_width < 80:
terminal_width = 80
except:
# Must be a virtual terminal like PyCharm console or VSCode console
terminal_width = 80 This working snippet of code actually works in both PyCharm/VSCode as well as xterm/terminal .... This snippet may obviate the need to pursue any further logging change except for:
|
Also the official Python
Use the specified format string for the handler. Defaults to attributes levelname, name and message separated by colons. Reference |
Perhaps we could support |
On trivial websites, per log line timestamps aren't that important. As the website grows, the timestamps become more helpful to show that Personally, I think they're worthwhile to keep.
If you've moved your plugin to a folder, and it's a single file named
I think
This seems reasonable. |
I will prototype that while keeping Do we need to be mindful of any other current but unresolved opinions that are ancillary to logging? |
Issue
the plugin name disappeared from its log message, albeit 3-years ago in this patch. And not only did
name
field disappear from the log format, thename
field got hard coded with'py.warning'
for all Pelican logs.Rationale
Having a path/filename column alone is quite the rather useless if many plugins share the same filename (of which THEY ARE ALLOW TO SO, such as
__init__
,__main__
,init
), so plug-in name would be very useful addition (that we used to have) to distinguish apart the same common filenames between Pelican and also between MANY plugins.name
field item of thislogging
module contains whatever it is declared inlogger = logging.getLogger('name'). Pelican starts it out with
pelican` as a logger name.Logger
name
:Our Pelican plugin makes use of the
logger = logging.getLogger(__name__)
so that plugin-specific names can appear with the log message as well.Is this something that we can quickly fix by introducing the
(name)
into thisLOG_FORMAT
?Perhaps, like:
so that we can get something like:
Alternative Output of Plugin Name
Alternatively, we could prepend the plugin name before the filename like in:
I've not determine how to implement this alternative, but I do believe @MinchinWeb can help us there, if this is the more desirable way to do this.
Alternative No. 2 - Shorter
name
We could shorten this 'name' even further to just the last two dotted names or anything starting with
plugin.
:pelican
pelican.plugins
.Examples are:
pelican
stays aspelican
pelican.generator
as-ispelican.writer
as-ispelican.plugins.m_htmlsanity
intom_htmlsanity
(that's a plugin bug, for right now it ispelican
)pelican.plugins.tableize.memoizer
becomestableize.memoizer
pelican.plugins.tableize.memoizer.jinja
becomestableize.memoizer.jinja
pelican.plugins
gets snipped out for deeper nesting.Comment made on its commit in question here.
HOOK'EM LOG-NAME
BUG:
py.warnings
is the currently assigned logname
(until I had my ownpelican.py
executable took over properly aspelican
name.)NOTE: Notice that
m.sanity
did not calllogger = logging.setLogger(__name__)
? It got thepelican
because it is a legacy (non-4.0) plugin.NOTE: Notice that using
__name__
inlogger = logging.setLogger(__name__)
will get you the full multi-dotted name likepelican.plugins.tableize.tableize
? but using your own string results likemy_fancy_tableize
results in a simple non-dottedmy_fancy_tableize
name? This multi-dotted nature can be disabled bylog.py
doinglogger = logging.setLogger('pelican')
.Declaring
logger
class variable as a global scope but within a plugin should be safe, scoping-wise:Platform Used
The text was updated successfully, but these errors were encountered: