acschaefer / duallog Goto Github PK
View Code? Open in Web Editor NEWPython package to enable simultaneous logging to console and logfile.
License: MIT License
Python package to enable simultaneous logging to console and logfile.
License: MIT License
So I have done something like
import logging
import duallog
_logger = logging.getLogger(__name__)
duallog.setup('/var/logs/logtest')
def parse_args(args):
parser = argparse.ArgumentParser(
description="Logs test")
....
parser.add_argument(
"-v",
"--verbose",
dest="loglevel",
help="set loglevel to INFO",
action="store_const",
const=logging.INFO)
parser.add_argument(
"-vv",
"--very-verbose",
dest="loglevel",
help="set loglevel to DEBUG",
action="store_const",
const=logging.DEBUG)
return parser.parse_args(args)
def setup_logging(loglevel):
logformat = "[%(asctime)s] %(levelname)s:%(name)s:%(message)s"
logging.basicConfig(level=loglevel, stream=sys.stdout,
format=logformat, datefmt="%Y-%m-%d %H:%M:%S")
def main(args):
args = parse_args(args)
setup_logging(args.loglevel)
_logger.debug("TEST 123...")
def run():
"""Entry point for console_scripts
"""
main(sys.argv[1:])
if __name__ == "__main__":
run()
that will produce empty console and file logs but when I will remove duallog it will show at least console logs.
Is there any way to get duallog
to work with getLogger()
method?
Hi there,
Very interested in using this module but I got an error on install.
Here is my output:
ran in my console $ sudo python setup.py install
running install
running bdist_egg
running egg_info
writing duallog.egg-info/PKG-INFO
writing top-level names to duallog.egg-info/top_level.txt
writing dependency_links to duallog.egg-info/dependency_links.txt
error: package directory 'duallog' does not exist
I'm on Linux Ubuntu 16.08.
Python 2.7.12
Tried running via python3 just to see what would happen but it failed instead for an ImportError:
Traceback (most recent call last):
File "setup.py", line 9, in <module>
import setuptools
ImportError: No module named 'setuptools'
Any help would be greatly appreciated!
Currently all logs are written to file, however some modules (like the requests module) have debug messages that clutter up the storage while giving little value for the user when debugging. An option for selecting the minimum logging level would mitigate this issue.
New to this thread.
After installing package, duallog.setup() fails. Please see trace beow.
duallog.setup('status.log')
File "/usr/lib/python2.6/site-packages/duallog-0.20-py2.6.egg/duallog/duallog.py", line 71, in setup
file_handler = logging.handlers.Rotatingfile_handler(
AttributeError: 'module' object has no attribute 'Rotatingfile_handler'
Seems like you changed a bit to much when converting from CamelCase.
Some "logging.Functions" were also renamed...
Quick patch to fix it:
--- duallog.py 2020-03-03 21:19:26.102004804 +0100
+++ /usr/local/lib/python3.7/dist-packages/duallog/duallog.py 2020-03-03 19:55:26.844999139 +0100
@@ -68,15 +68,15 @@
file_name = os.path.join(dir, file_name)
# Set up logging to the logfile.
- file_handler = logging.handlers.Rotatingfile_handler(
- file_name=file_name, max_bytes=max_bytes, backup_count=backup_count)
+ file_handler = logging.handlers.RotatingFileHandler(
+ filename=file_name, maxBytes=max_bytes, backupCount=backup_count)
file_handler.setLevel(logging.DEBUG)
file_formatter = logging.Formatter(file_msg_format)
file_handler.setFormatter(file_formatter)
logger.addHandler(file_handler)
# Set up logging to the console.
- stream_handler = logging.stream_handler()
+ stream_handler = logging.StreamHandler()
stream_handler.setLevel(minLevel)
stream_formatter = logging.Formatter(console_msg_format)
stream_handler.setFormatter(stream_formatter)
Hi,
Installation:
λ python setup.py install
running install
running bdist_egg
running egg_info
creating duallog.egg-info
writing duallog.egg-info\PKG-INFO
writing dependency_links to duallog.egg-info\dependency_links.txt
writing top-level names to duallog.egg-info\top_level.txt
writing manifest file 'duallog.egg-info\SOURCES.txt'
reading manifest file 'duallog.egg-info\SOURCES.txt'
writing manifest file 'duallog.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build
creating build\lib
creating build\lib\duallog
copying duallog\duallog.py -> build\lib\duallog
copying duallog_init_.py -> build\lib\duallog
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\duallog
copying build\lib\duallog\duallog.py -> build\bdist.win-amd64\egg\duallog
copying build\lib\duallog_init_.py -> build\bdist.win-amd64\egg\duallog
byte-compiling build\bdist.win-amd64\egg\duallog\duallog.py to duallog.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\duallog_init_.py to init.cpython-37.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying duallog.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying duallog.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying duallog.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying duallog.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist\duallog-0.2-py3.7.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing duallog-0.2-py3.7.egg
Removing c:\users\phcam\anaconda3\lib\site-packages\duallog-0.2-py3.7.egg
Copying duallog-0.2-py3.7.egg to c:\users\phcam\anaconda3\lib\site-packages
duallog 0.2 is already the active version in easy-install.pth
Installed c:\users\phcam\anaconda3\lib\site-packages\duallog-0.2-py3.7.egg
Processing dependencies for duallog==0.2
Finished processing dependencies for duallog==0.2
Ipython test: module 'duallog' has no attribute 'setup'
Config: Windows 10, Python 3.7.0, IPython 6.5.0
Seems like the version you get from pip3 is more than a year old, and missing features such as "mnLevel" etc.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.