doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
locale.T_FMT Get a string that can be used as a format string for time.strftime() to represent a time in a locale-specific way.
python.library.locale#locale.T_FMT
locale.T_FMT_AMPM Get a format string for time.strftime() to represent time in the am/pm format.
python.library.locale#locale.T_FMT_AMPM
locale.YESEXPR Get a regular expression that can be used with the regex function to recognize a positive response to a yes/no question. Note The expression is in the syntax suitable for the regex() function from the C library, which might differ from the syntax used in re.
python.library.locale#locale.YESEXPR
locals() Update and return a dictionary representing the current local symbol table. Free variables are returned by locals() when it is called in function blocks, but not in class blocks. Note that at the module level, locals() and globals() are the same dictionary. Note The contents of this dictionary should not be...
python.library.functions#locals
logging — Logging facility for Python Source code: Lib/logging/__init__.py Important This page contains the API reference information. For tutorial information and discussion of more advanced topics, see Basic Tutorial Advanced Tutorial Logging Cookbook This module defines functions and classes which implement a fl...
python.library.logging
logging.addLevelName(level, levelName) Associates level level with text levelName in an internal dictionary, which is used to map numeric levels to a textual representation, for example when a Formatter formats a message. This function can also be used to define your own levels. The only constraints are that all leve...
python.library.logging#logging.addLevelName
logging.basicConfig(**kwargs) Does basic configuration for the logging system by creating a StreamHandler with a default Formatter and adding it to the root logger. The functions debug(), info(), warning(), error() and critical() will call basicConfig() automatically if no handlers are defined for the root logger. Th...
python.library.logging#logging.basicConfig
logging.captureWarnings(capture) This function is used to turn the capture of warnings by logging on and off. If capture is True, warnings issued by the warnings module will be redirected to the logging system. Specifically, a warning will be formatted using warnings.formatwarning() and the resulting string logged to...
python.library.logging#logging.captureWarnings
logging.config — Logging configuration Source code: Lib/logging/config.py Important This page contains only reference information. For tutorials, please see Basic Tutorial Advanced Tutorial Logging Cookbook This section describes the API for configuring the logging module. Configuration functions The following func...
python.library.logging.config
logging.config.dictConfig(config) Takes the logging configuration from a dictionary. The contents of this dictionary are described in Configuration dictionary schema below. If an error is encountered during configuration, this function will raise a ValueError, TypeError, AttributeError or ImportError with a suitably ...
python.library.logging.config#logging.config.dictConfig
logging.config.fileConfig(fname, defaults=None, disable_existing_loggers=True) Reads the logging configuration from a configparser-format file. The format of the file should be as described in Configuration file format. This function can be called several times from an application, allowing an end user to select from...
python.library.logging.config#logging.config.fileConfig
logging.config.listen(port=DEFAULT_LOGGING_CONFIG_PORT, verify=None) Starts up a socket server on the specified port, and listens for new configurations. If no port is specified, the module’s default DEFAULT_LOGGING_CONFIG_PORT is used. Logging configurations will be sent as a file suitable for processing by dictConf...
python.library.logging.config#logging.config.listen
logging.config.stopListening() Stops the listening server which was created with a call to listen(). This is typically called before calling join() on the return value from listen().
python.library.logging.config#logging.config.stopListening
logging.critical(msg, *args, **kwargs) Logs a message with level CRITICAL on the root logger. The arguments are interpreted as for debug().
python.library.logging#logging.critical
logging.debug(msg, *args, **kwargs) Logs a message with level DEBUG on the root logger. The msg is the message format string, and the args are the arguments which are merged into msg using the string formatting operator. (Note that this means that you can use keywords in the format string, together with a single dict...
python.library.logging#logging.debug
logging.disable(level=CRITICAL) Provides an overriding level level for all loggers which takes precedence over the logger’s own level. When the need arises to temporarily throttle logging output down across the whole application, this function can be useful. Its effect is to disable all logging calls of severity leve...
python.library.logging#logging.disable
logging.error(msg, *args, **kwargs) Logs a message with level ERROR on the root logger. The arguments are interpreted as for debug().
python.library.logging#logging.error
logging.exception(msg, *args, **kwargs) Logs a message with level ERROR on the root logger. The arguments are interpreted as for debug(). Exception info is added to the logging message. This function should only be called from an exception handler.
python.library.logging#logging.exception
class logging.FileHandler(filename, mode='a', encoding=None, delay=False, errors=None) Returns a new instance of the FileHandler class. The specified file is opened and used as the stream for logging. If mode is not specified, 'a' is used. If encoding is not None, it is used to open the file with that encoding. If de...
python.library.logging.handlers#logging.FileHandler
close() Closes the file.
python.library.logging.handlers#logging.FileHandler.close
emit(record) Outputs the record to the file.
python.library.logging.handlers#logging.FileHandler.emit
class logging.Filter(name='') Returns an instance of the Filter class. If name is specified, it names a logger which, together with its children, will have its events allowed through the filter. If name is the empty string, allows every event. filter(record) Is the specified record to be logged? Returns zero for ...
python.library.logging#logging.Filter
filter(record) Is the specified record to be logged? Returns zero for no, nonzero for yes. If deemed appropriate, the record may be modified in-place by this method.
python.library.logging#logging.Filter.filter
class logging.Formatter(fmt=None, datefmt=None, style='%', validate=True) Returns a new instance of the Formatter class. The instance is initialized with a format string for the message as a whole, as well as a format string for the date/time portion of a message. If no fmt is specified, '%(message)s' is used. If no ...
python.library.logging#logging.Formatter
format(record) The record’s attribute dictionary is used as the operand to a string formatting operation. Returns the resulting string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using msg % args. If the formatting string contains '...
python.library.logging#logging.Formatter.format
formatException(exc_info) Formats the specified exception information (a standard exception tuple as returned by sys.exc_info()) as a string. This default implementation just uses traceback.print_exception(). The resulting string is returned.
python.library.logging#logging.Formatter.formatException
formatStack(stack_info) Formats the specified stack information (a string as returned by traceback.print_stack(), but with the last newline removed) as a string. This default implementation just returns the input value.
python.library.logging#logging.Formatter.formatStack
formatTime(record, datefmt=None) This method should be called from format() by a formatter which wants to make use of a formatted time. This method can be overridden in formatters to provide for any specific requirement, but the basic behavior is as follows: if datefmt (a string) is specified, it is used with time.st...
python.library.logging#logging.Formatter.formatTime
logging.getLevelName(level) Returns the textual or numeric representation of logging level level. If level is one of the predefined levels CRITICAL, ERROR, WARNING, INFO or DEBUG then you get the corresponding string. If you have associated levels with names using addLevelName() then the name you have associated with...
python.library.logging#logging.getLevelName
logging.getLogger(name=None) Return a logger with the specified name or, if name is None, return a logger which is the root logger of the hierarchy. If specified, the name is typically a dot-separated hierarchical name like ‘a’, ‘a.b’ or ‘a.b.c.d’. Choice of these names is entirely up to the developer who is using lo...
python.library.logging#logging.getLogger
logging.getLoggerClass() Return either the standard Logger class, or the last class passed to setLoggerClass(). This function may be called from within a new class definition, to ensure that installing a customized Logger class will not undo customizations already applied by other code. For example: class MyLogger(lo...
python.library.logging#logging.getLoggerClass
logging.getLogRecordFactory() Return a callable which is used to create a LogRecord. New in version 3.2: This function has been provided, along with setLogRecordFactory(), to allow developers more control over how the LogRecord representing a logging event is constructed. See setLogRecordFactory() for more informat...
python.library.logging#logging.getLogRecordFactory
class logging.Handler __init__(level=NOTSET) Initializes the Handler instance by setting its level, setting the list of filters to the empty list and creating a lock (using createLock()) for serializing access to an I/O mechanism. createLock() Initializes a thread lock which can be used to serialize access ...
python.library.logging#logging.Handler
acquire() Acquires the thread lock created with createLock().
python.library.logging#logging.Handler.acquire
addFilter(filter) Adds the specified filter filter to this handler.
python.library.logging#logging.Handler.addFilter
close() Tidy up any resources used by the handler. This version does no output but removes the handler from an internal list of handlers which is closed when shutdown() is called. Subclasses should ensure that this gets called from overridden close() methods.
python.library.logging#logging.Handler.close
createLock() Initializes a thread lock which can be used to serialize access to underlying I/O functionality which may not be threadsafe.
python.library.logging#logging.Handler.createLock
emit(record) Do whatever it takes to actually log the specified logging record. This version is intended to be implemented by subclasses and so raises a NotImplementedError.
python.library.logging#logging.Handler.emit
filter(record) Apply this handler’s filters to the record and return True if the record is to be processed. The filters are consulted in turn, until one of them returns a false value. If none of them return a false value, the record will be emitted. If one returns a false value, the handler will not emit the record.
python.library.logging#logging.Handler.filter
flush() Ensure all logging output has been flushed. This version does nothing and is intended to be implemented by subclasses.
python.library.logging#logging.Handler.flush
format(record) Do formatting for a record - if a formatter is set, use it. Otherwise, use the default formatter for the module.
python.library.logging#logging.Handler.format
handle(record) Conditionally emits the specified logging record, depending on filters which may have been added to the handler. Wraps the actual emission of the record with acquisition/release of the I/O thread lock.
python.library.logging#logging.Handler.handle
handleError(record) This method should be called from handlers when an exception is encountered during an emit() call. If the module-level attribute raiseExceptions is False, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging syst...
python.library.logging#logging.Handler.handleError
release() Releases the thread lock acquired with acquire().
python.library.logging#logging.Handler.release
removeFilter(filter) Removes the specified filter filter from this handler.
python.library.logging#logging.Handler.removeFilter
setFormatter(fmt) Sets the Formatter for this handler to fmt.
python.library.logging#logging.Handler.setFormatter
setLevel(level) Sets the threshold for this handler to level. Logging messages which are less severe than level will be ignored. When a handler is created, the level is set to NOTSET (which causes all messages to be processed). See Logging Levels for a list of levels. Changed in version 3.2: The level parameter now ...
python.library.logging#logging.Handler.setLevel
__init__(level=NOTSET) Initializes the Handler instance by setting its level, setting the list of filters to the empty list and creating a lock (using createLock()) for serializing access to an I/O mechanism.
python.library.logging#logging.Handler.__init__
logging.handlers — Logging handlers Source code: Lib/logging/handlers.py Important This page contains only reference information. For tutorials, please see Basic Tutorial Advanced Tutorial Logging Cookbook The following useful handlers are provided in the package. Note that three of the handlers (StreamHandler, Fil...
python.library.logging.handlers
class logging.handlers.BaseRotatingHandler(filename, mode, encoding=None, delay=False, errors=None) The parameters are as for FileHandler. The attributes are: namer If this attribute is set to a callable, the rotation_filename() method delegates to this callable. The parameters passed to the callable are those pa...
python.library.logging.handlers#logging.handlers.BaseRotatingHandler
namer If this attribute is set to a callable, the rotation_filename() method delegates to this callable. The parameters passed to the callable are those passed to rotation_filename(). Note The namer function is called quite a few times during rollover, so it should be as simple and as fast as possible. It should als...
python.library.logging.handlers#logging.handlers.BaseRotatingHandler.namer
rotate(source, dest) When rotating, rotate the current log. The default implementation calls the ‘rotator’ attribute of the handler, if it’s callable, passing the source and dest arguments to it. If the attribute isn’t callable (the default is None), the source is simply renamed to the destination. Parameters sou...
python.library.logging.handlers#logging.handlers.BaseRotatingHandler.rotate
rotation_filename(default_name) Modify the filename of a log file when rotating. This is provided so that a custom filename can be provided. The default implementation calls the ‘namer’ attribute of the handler, if it’s callable, passing the default name to it. If the attribute isn’t callable (the default is None), t...
python.library.logging.handlers#logging.handlers.BaseRotatingHandler.rotation_filename
rotator If this attribute is set to a callable, the rotate() method delegates to this callable. The parameters passed to the callable are those passed to rotate(). New in version 3.3.
python.library.logging.handlers#logging.handlers.BaseRotatingHandler.rotator
class logging.handlers.BufferingHandler(capacity) Initializes the handler with a buffer of the specified capacity. Here, capacity means the number of logging records buffered. emit(record) Append the record to the buffer. If shouldFlush() returns true, call flush() to process the buffer. flush() You can ove...
python.library.logging.handlers#logging.handlers.BufferingHandler
emit(record) Append the record to the buffer. If shouldFlush() returns true, call flush() to process the buffer.
python.library.logging.handlers#logging.handlers.BufferingHandler.emit
flush() You can override this to implement custom flushing behavior. This version just zaps the buffer to empty.
python.library.logging.handlers#logging.handlers.BufferingHandler.flush
shouldFlush(record) Return True if the buffer is up to capacity. This method can be overridden to implement custom flushing strategies.
python.library.logging.handlers#logging.handlers.BufferingHandler.shouldFlush
class logging.handlers.DatagramHandler(host, port) Returns a new instance of the DatagramHandler class intended to communicate with a remote machine whose address is given by host and port. Changed in version 3.4: If port is specified as None, a Unix domain socket is created using the value in host - otherwise, a UD...
python.library.logging.handlers#logging.handlers.DatagramHandler
emit() Pickles the record’s attribute dictionary and writes it to the socket in binary format. If there is an error with the socket, silently drops the packet. To unpickle the record at the receiving end into a LogRecord, use the makeLogRecord() function.
python.library.logging.handlers#logging.handlers.DatagramHandler.emit
makeSocket() The factory method of SocketHandler is here overridden to create a UDP socket (socket.SOCK_DGRAM).
python.library.logging.handlers#logging.handlers.DatagramHandler.makeSocket
send(s) Send a pickled byte-string to a socket. The format of the sent byte-string is as described in the documentation for SocketHandler.makePickle().
python.library.logging.handlers#logging.handlers.DatagramHandler.send
class logging.handlers.HTTPHandler(host, url, method='GET', secure=False, credentials=None, context=None) Returns a new instance of the HTTPHandler class. The host can be of the form host:port, should you need to use a specific port number. If no method is specified, GET is used. If secure is true, a HTTPS connection...
python.library.logging.handlers#logging.handlers.HTTPHandler
emit(record) Sends the record to the Web server as a URL-encoded dictionary. The mapLogRecord() method is used to convert the record to the dictionary to be sent.
python.library.logging.handlers#logging.handlers.HTTPHandler.emit
mapLogRecord(record) Provides a dictionary, based on record, which is to be URL-encoded and sent to the web server. The default implementation just returns record.__dict__. This method can be overridden if e.g. only a subset of LogRecord is to be sent to the web server, or if more specific customization of what’s sen...
python.library.logging.handlers#logging.handlers.HTTPHandler.mapLogRecord
class logging.handlers.MemoryHandler(capacity, flushLevel=ERROR, target=None, flushOnClose=True) Returns a new instance of the MemoryHandler class. The instance is initialized with a buffer size of capacity (number of records buffered). If flushLevel is not specified, ERROR is used. If no target is specified, the tar...
python.library.logging.handlers#logging.handlers.MemoryHandler
close() Calls flush(), sets the target to None and clears the buffer.
python.library.logging.handlers#logging.handlers.MemoryHandler.close
flush() For a MemoryHandler, flushing means just sending the buffered records to the target, if there is one. The buffer is also cleared when this happens. Override if you want different behavior.
python.library.logging.handlers#logging.handlers.MemoryHandler.flush
setTarget(target) Sets the target handler for this handler.
python.library.logging.handlers#logging.handlers.MemoryHandler.setTarget
shouldFlush(record) Checks for buffer full or a record at the flushLevel or higher.
python.library.logging.handlers#logging.handlers.MemoryHandler.shouldFlush
class logging.handlers.NTEventLogHandler(appname, dllname=None, logtype='Application') Returns a new instance of the NTEventLogHandler class. The appname is used to define the application name as it appears in the event log. An appropriate registry entry is created using this name. The dllname should give the fully q...
python.library.logging.handlers#logging.handlers.NTEventLogHandler
close() At this point, you can remove the application name from the registry as a source of event log entries. However, if you do this, you will not be able to see the events as you intended in the Event Log Viewer - it needs to be able to access the registry to get the .dll name. The current version does not do this...
python.library.logging.handlers#logging.handlers.NTEventLogHandler.close
emit(record) Determines the message ID, event category and event type, and then logs the message in the NT event log.
python.library.logging.handlers#logging.handlers.NTEventLogHandler.emit
getEventCategory(record) Returns the event category for the record. Override this if you want to specify your own categories. This version returns 0.
python.library.logging.handlers#logging.handlers.NTEventLogHandler.getEventCategory
getEventType(record) Returns the event type for the record. Override this if you want to specify your own types. This version does a mapping using the handler’s typemap attribute, which is set up in __init__() to a dictionary which contains mappings for DEBUG, INFO, WARNING, ERROR and CRITICAL. If you are using your ...
python.library.logging.handlers#logging.handlers.NTEventLogHandler.getEventType
getMessageID(record) Returns the message ID for the record. If you are using your own messages, you could do this by having the msg passed to the logger being an ID rather than a format string. Then, in here, you could use a dictionary lookup to get the message ID. This version returns 1, which is the base message ID...
python.library.logging.handlers#logging.handlers.NTEventLogHandler.getMessageID
class logging.handlers.QueueHandler(queue) Returns a new instance of the QueueHandler class. The instance is initialized with the queue to send messages to. The queue can be any queue-like object; it’s used as-is by the enqueue() method, which needs to know how to send messages to it. The queue is not required to hav...
python.library.logging.handlers#logging.handlers.QueueHandler
emit(record) Enqueues the result of preparing the LogRecord. Should an exception occur (e.g. because a bounded queue has filled up), the handleError() method is called to handle the error. This can result in the record silently being dropped (if logging.raiseExceptions is False) or a message printed to sys.stderr (if...
python.library.logging.handlers#logging.handlers.QueueHandler.emit
enqueue(record) Enqueues the record on the queue using put_nowait(); you may want to override this if you want to use blocking behaviour, or a timeout, or a customized queue implementation.
python.library.logging.handlers#logging.handlers.QueueHandler.enqueue
prepare(record) Prepares a record for queuing. The object returned by this method is enqueued. The base implementation formats the record to merge the message, arguments, and exception information, if present. It also removes unpickleable items from the record in-place. You might want to override this method if you w...
python.library.logging.handlers#logging.handlers.QueueHandler.prepare
class logging.handlers.QueueListener(queue, *handlers, respect_handler_level=False) Returns a new instance of the QueueListener class. The instance is initialized with the queue to send messages to and a list of handlers which will handle entries placed on the queue. The queue can be any queue-like object; it’s passe...
python.library.logging.handlers#logging.handlers.QueueListener
dequeue(block) Dequeues a record and return it, optionally blocking. The base implementation uses get(). You may want to override this method if you want to use timeouts or work with custom queue implementations.
python.library.logging.handlers#logging.handlers.QueueListener.dequeue
enqueue_sentinel() Writes a sentinel to the queue to tell the listener to quit. This implementation uses put_nowait(). You may want to override this method if you want to use timeouts or work with custom queue implementations. New in version 3.3.
python.library.logging.handlers#logging.handlers.QueueListener.enqueue_sentinel
handle(record) Handle a record. This just loops through the handlers offering them the record to handle. The actual object passed to the handlers is that which is returned from prepare().
python.library.logging.handlers#logging.handlers.QueueListener.handle
prepare(record) Prepare a record for handling. This implementation just returns the passed-in record. You may want to override this method if you need to do any custom marshalling or manipulation of the record before passing it to the handlers.
python.library.logging.handlers#logging.handlers.QueueListener.prepare
start() Starts the listener. This starts up a background thread to monitor the queue for LogRecords to process.
python.library.logging.handlers#logging.handlers.QueueListener.start
stop() Stops the listener. This asks the thread to terminate, and then waits for it to do so. Note that if you don’t call this before your application exits, there may be some records still left on the queue, which won’t be processed.
python.library.logging.handlers#logging.handlers.QueueListener.stop
class logging.handlers.RotatingFileHandler(filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=False, errors=None) Returns a new instance of the RotatingFileHandler class. The specified file is opened and used as the stream for logging. If mode is not specified, 'a' is used. If encoding is not None, i...
python.library.logging.handlers#logging.handlers.RotatingFileHandler
doRollover() Does a rollover, as described above.
python.library.logging.handlers#logging.handlers.RotatingFileHandler.doRollover
emit(record) Outputs the record to the file, catering for rollover as described previously.
python.library.logging.handlers#logging.handlers.RotatingFileHandler.emit
class logging.handlers.SMTPHandler(mailhost, fromaddr, toaddrs, subject, credentials=None, secure=None, timeout=1.0) Returns a new instance of the SMTPHandler class. The instance is initialized with the from and to addresses and subject line of the email. The toaddrs should be a list of strings. To specify a non-stan...
python.library.logging.handlers#logging.handlers.SMTPHandler
emit(record) Formats the record and sends it to the specified addressees.
python.library.logging.handlers#logging.handlers.SMTPHandler.emit
getSubject(record) If you want to specify a subject line which is record-dependent, override this method.
python.library.logging.handlers#logging.handlers.SMTPHandler.getSubject
class logging.handlers.SocketHandler(host, port) Returns a new instance of the SocketHandler class intended to communicate with a remote machine whose address is given by host and port. Changed in version 3.4: If port is specified as None, a Unix domain socket is created using the value in host - otherwise, a TCP so...
python.library.logging.handlers#logging.handlers.SocketHandler
close() Closes the socket.
python.library.logging.handlers#logging.handlers.SocketHandler.close
createSocket() Tries to create a socket; on failure, uses an exponential back-off algorithm. On initial failure, the handler will drop the message it was trying to send. When subsequent messages are handled by the same instance, it will not try connecting until some time has passed. The default parameters are such th...
python.library.logging.handlers#logging.handlers.SocketHandler.createSocket
emit() Pickles the record’s attribute dictionary and writes it to the socket in binary format. If there is an error with the socket, silently drops the packet. If the connection was previously lost, re-establishes the connection. To unpickle the record at the receiving end into a LogRecord, use the makeLogRecord() fu...
python.library.logging.handlers#logging.handlers.SocketHandler.emit
handleError() Handles an error which has occurred during emit(). The most likely cause is a lost connection. Closes the socket so that we can retry on the next event.
python.library.logging.handlers#logging.handlers.SocketHandler.handleError
makePickle(record) Pickles the record’s attribute dictionary in binary format with a length prefix, and returns it ready for transmission across the socket. The details of this operation are equivalent to: data = pickle.dumps(record_attr_dict, 1) datalen = struct.pack('>L', len(data)) return datalen + data Note that...
python.library.logging.handlers#logging.handlers.SocketHandler.makePickle
makeSocket() This is a factory method which allows subclasses to define the precise type of socket they want. The default implementation creates a TCP socket (socket.SOCK_STREAM).
python.library.logging.handlers#logging.handlers.SocketHandler.makeSocket