-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a85ad1
commit 721ce6e
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
|
||
import logging | ||
|
||
logging.debug('This is a debug message') | ||
logging.info('This is an info message') | ||
logging.warning('This is a warning message') | ||
logging.error('This is an error message') | ||
logging.critical('This is a critical message') | ||
|
||
# | ||
|
||
import logging | ||
|
||
logging.basicConfig(filename='app.log', filemode='w', format='%(name)s - %(levelname)s - %(message)s') | ||
logging.warning('This will get logged to a file') | ||
|
||
# Create a custom logger | ||
logger = logging.getLogger("wrapper") | ||
|
||
# Create handlers | ||
c_handler = logging.StreamHandler() | ||
f_handler = logging.FileHandler('file.log') | ||
c_handler.setLevel(logging.WARNING) | ||
f_handler.setLevel(logging.ERROR) | ||
|
||
# Create formatters and add it to handlers | ||
c_format = logging.Formatter('%(name)s - %(levelname)s - %(message)s') | ||
f_format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | ||
c_handler.setFormatter(c_format) | ||
f_handler.setFormatter(f_format) | ||
|
||
# Add handlers to the logger | ||
logger.addHandler(c_handler) | ||
logger.addHandler(f_handler) | ||
|
||
logger.warning('This is a warning') | ||
logger.error('This is an error') |