My logger library.
Project description
mylog
A simple logging library for Python.
Example/Getting started
First, install it with pip install git+https://github.com/koviubi56/mylog.git
. Need more help?
For demonstration purposes only! Output may not be the same as shown here!
import mylog
logger = mylog.root.get_child()
logger.info("Hello, world!")
# Returns: 0
# Output: <nothing>
# Why? Because the threshold is set to WARNING.
# Try this:
logger.warning("Hello, world!")
# Returns: 70
# Output: [WARNING Sun Mar 27 18:56:57 2022 line: 00001] Hello, world!
# Or
logger.threshold = mylog.Level.debug
logger.info("Hello, world!")
# Returns: 67
# Output: [INFO Sun Mar 27 18:58:40 2022 line: 00001] Hello, world!
API reference
Warning! This is only the public API!
WARNING! If you see a -
(minus/dash/hyphen) in an argument name, it is a _
(underscore)!
variable __version__
The version string of the library.
constant DEFAULT_FORMAT
The default format used by MyLog.
By default it is "[{lvl} {time} line: {line}] {indent}{msg}"
.
IntEnum class Level
Different levels of logging. (Note that logging levels aren't required to be one of these.)
Name | Value |
---|---|
debug |
10 |
info |
20 |
warning |
30 |
error |
40 |
critical |
50 |
Aliases:
warn
==warning
fatal
==critical
constant DEFAULT_THRESHOLD
The default threshold used by MyLog.
By default it is Level.warning
.
protocol Stringable
A class that has a __str__
method, that returns a string.
type alias Levelable
Union[Level, Stringable, int]
function to_level
(lvl: Levelable, int-ok: bool = False) -> Level
Converts an int/str/something to a Level. If lvl
cannot be converted, and int_ok
is True, the int will be returned.
type alias NoneType
type(None)
context manager SetAttr
(obj: object, name: str, new-value: Any)
A context manager for setting and then resetting an attribute.
class LogEvent
(msg: str, level: Level, time: float, indent: int, frame-depth: int, tb: bool)
A log event. Time is in UNIX seconds.
protocol StreamProtocol
A class that has a write
and a flush
method.
ABC Handler
An abstract base class for that has a method handle
.
class NoHandler
A handler that does nothing.
class StreamWriterHandler
(stream: StreamProtocol, *, flush: bool = True, use-colors: bool = True, format-msg: bool = True)
A handler that writes to a stream.
class Logger
(higher: Optional[Logger])
The logger class.
Class variables
bool colors
Should level_to_str use colors? Defaults to True
.
Static methods
_color
(rv: str) -> str
Colorizes a string.
Methods
_inherit
() -> None
Inherit from self.higher
("parent").
get_default_handlers
() -> List[Handler]
Get the default handlers.
level_to_str
(lvl: Levelable) -> str
Convert a level to a string.
format_msg
(event: LogEvent) -> str
Format the message.
_log
(lvl: Levelable, msg: Stringable, tb: bool, frame-depth: int) -> Optional[LogEvent]
Log a message.
debug
/info
/warning
/error
/critical
(msg: Stringable, traceback: bool = False) -> int
Log a message.
get_child
() -> Logger
Get a child logger.
is_enabled_for
(lvl: Levelable) -> bool
Check if the logger is enabled for the given level.
context manager IndentLogger
(logger: Logger)
Indent the logger by one when entered, then unindent by one when exited.
context manager ChangeThreshold
(logger: Logger, level: Levelable)
Change the threshold of the logger to level
when entered, then restore the threshold when exited.
variable root
The root logger.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for python_mylog-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cee8901cd14708aa8ef6bddb04748a85501aab184fb59e07285fe9a044a75bc |
|
MD5 | 06bfba108d52d121210ec22af3c88cba |
|
BLAKE2b-256 | 36c44cc15066c8f6c3944cbdd1517f4d405266a30d00cfffb3645f693fb9ca56 |