Comments (2)
Also, my implementation is below.
"""Main logging class to make logging easier."""
import os
import sys
from logzero import setup_logger, LogFormatter, logging, colors
class LogIt(object):
"""LogIt makes logging easier by creating easy loggers."""
def __init__(self):
"""Initialize the logger format based on system platform."""
# Set the different formats based on user's platform
if sys.platform == 'win32':
self._archive_format = '%m-%d-%Y_%I-%M-%p'
elif sys.platform == 'linux':
self._archive_format = '%m-%d-%Y@%I:%M:%S-%p'
self._date_format = '%b-%d-%Y at %I:%M:%S %p' # Used to add date
self._log_format = ("%(color)s[%(levelname)s | %(name)s] [%(asctime)s | "
"%(module)s - line %(lineno)d]:%(end_color)s %(message)s")
self._formatter = LogFormatter(fmt=self._log_format,
datefmt=self._date_format)
# Add a color for the critical level
self._formatter.DEFAULT_COLORS[50] = colors.Fore.LIGHTRED_EX
# Changed color for the debug level
self._formatter.DEFAULT_COLORS[10] = colors.Fore.LIGHTBLUE_EX
self.logging = logging
def default(self, logname, logfile):
"""Create a log handler using default formatting.
:param logname: Name of the log.
:param logfile: Path to the logfile. Can be `None`.
:return: A default_log object is returned.
"""
default_log = setup_logger(name=logname.upper(), logfile=logfile,
level=logging.DEBUG,
formatter=self._formatter)
assert isinstance(default_log, object)
return default_log
from logzero.
Fixed in #339
from logzero.
Related Issues (20)
- [RFE] - Create directory structure, if it doesn't exist
- Date Format Missing HOT 1
- Use logzero as root_logger. HOT 3
- Usage with multiprocessing and single rotated logfile HOT 4
- log content when subprocess.Popen another Python code file HOT 1
- How to show output logzero's log in pytest
- Is there a way to use use "logging.setLoggerClass" HOT 1
- setup_logger() with level set cannot be changed HOT 1
- Inconsistent output in console and logfile.
- To do & Feature ideas 💡 HOT 3
- [Feature Request] Handling multiple arguments and non-string arguments HOT 2
- Logfile JSON encode HOT 2
- logzero in multiple files using import
- setup_default_logger of para maxBytes, backupCount not used HOT 2
- [Suggestion/Discussion] Support for `logging.getLogger(__name__)` HOT 2
- Json Formatter overridden by _get_json_formatter HOT 1
- color in filelog is in a mess HOT 2
- Function 'logfile' assumes that filename is a string
- VS Code intellisense stops working from Pylance 2022.2.4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from logzero.