@@ -589,6 +589,22 @@ decides to actually dispatch an event, the :meth:`emit` method is used to send
589589the message to its destination. Most user-defined subclasses of :class: `Handler `
590590will need to override this :meth: `emit `.
591591
592+ .. _custom-levels :
593+
594+ Custom Levels
595+ ^^^^^^^^^^^^^
596+
597+ Defining your own levels is possible, but should not be necessary, as the
598+ existing levels have been chosen on the basis of practical experience.
599+ However, if you are convinced that you need custom levels, great care should
600+ be exercised when doing this, and it is possibly *a very bad idea to define
601+ custom levels if you are developing a library *. That's because if multiple
602+ library authors all define their own custom levels, there is a chance that
603+ the logging output from such multiple libraries used together will be
604+ difficult for the using developer to control and/or interpret, because a
605+ given numeric value might mean different things for different libraries.
606+
607+
592608Useful Handlers
593609---------------
594610
@@ -790,12 +806,19 @@ functions.
790806 interpreted as for :func: `debug `. Exception info is added to the logging
791807 message. This function should only be called from an exception handler.
792808
793-
794809.. function :: log(level, msg, *args, **kwargs)
795810
796811 Logs a message with level *level * on the root logger. The other arguments are
797812 interpreted as for :func: `debug `.
798813
814+ PLEASE NOTE: The above module-level functions which delegate to the root
815+ logger should *not * be used in threads, in versions of Python earlier than
816+ 2.7.1 and 3.2, unless at least one handler has been added to the root
817+ logger *before * the threads are started. These convenience functions call
818+ :func: `basicConfig ` to ensure that at least one handler is available; in
819+ earlier versions of Python, this can (under rare circumstances) lead to
820+ handlers being added multiple times to the root logger, which can in turn
821+ lead to multiple messages for the same event.
799822
800823.. function :: disable(lvl)
801824
@@ -817,6 +840,8 @@ functions.
817840 registered using this function, levels should be positive integers and they
818841 should increase in increasing order of severity.
819842
843+ NOTE: If you are thinking of defining your own levels, please see the section
844+ on :ref: `custom-levels `.
820845
821846.. function :: getLevelName(lvl)
822847
@@ -848,6 +873,13 @@ functions.
848873 This function does nothing if the root logger already has handlers
849874 configured for it.
850875
876+ PLEASE NOTE: This function should be called from the main thread
877+ before other threads are started. In versions of Python prior to
878+ 2.7.1 and 3.2, if this function is called from multiple threads,
879+ it is possible (in rare circumstances) that a handler will be added
880+ to the root logger more than once, leading to unexpected results
881+ such as messages being duplicated in the log.
882+
851883 The following keyword arguments are supported.
852884
853885 +--------------+---------------------------------------------+
@@ -875,7 +907,6 @@ functions.
875907 | | present, 'stream' is ignored. |
876908 +--------------+---------------------------------------------+
877909
878-
879910.. function :: shutdown()
880911
881912 Informs the logging system to perform an orderly shutdown by flushing and
0 commit comments