forked from CoreyMSchafer/code_snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
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
937a90a
commit df2e19b
Showing
5 changed files
with
181 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,34 @@ | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.INFO) | ||
|
||
formatter = logging.Formatter('%(levelname)s:%(name)s:%(message)s') | ||
|
||
file_handler = logging.FileHandler('employee.log') | ||
file_handler.setFormatter(formatter) | ||
|
||
logger.addHandler(file_handler) | ||
|
||
|
||
class Employee: | ||
"""A sample Employee class""" | ||
|
||
def __init__(self, first, last): | ||
self.first = first | ||
self.last = last | ||
|
||
logger.info('Created Employee: {} - {}'.format(self.fullname, self.email)) | ||
|
||
@property | ||
def email(self): | ||
return '{}.{}@email.com'.format(self.first, self.last) | ||
|
||
@property | ||
def fullname(self): | ||
return '{} {}'.format(self.first, self.last) | ||
|
||
|
||
emp_1 = Employee('John', 'Smith') | ||
emp_2 = Employee('Corey', 'Schafer') | ||
emp_3 = Employee('Jane', 'Doe') |
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,58 @@ | ||
import logging | ||
import employee | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
formatter = logging.Formatter('%(asctime)s:%(name)s:%(message)s') | ||
|
||
file_handler = logging.FileHandler('sample.log') | ||
file_handler.setLevel(logging.ERROR) | ||
file_handler.setFormatter(formatter) | ||
|
||
stream_handler = logging.StreamHandler() | ||
stream_handler.setFormatter(formatter) | ||
|
||
logger.addHandler(file_handler) | ||
logger.addHandler(stream_handler) | ||
|
||
|
||
def add(x, y): | ||
"""Add Function""" | ||
return x + y | ||
|
||
|
||
def subtract(x, y): | ||
"""Subtract Function""" | ||
return x - y | ||
|
||
|
||
def multiply(x, y): | ||
"""Multiply Function""" | ||
return x * y | ||
|
||
|
||
def divide(x, y): | ||
"""Divide Function""" | ||
try: | ||
result = x / y | ||
except ZeroDivisionError: | ||
logger.exception('Tried to divide by zero') | ||
else: | ||
return result | ||
|
||
|
||
num_1 = 10 | ||
num_2 = 0 | ||
|
||
add_result = add(num_1, num_2) | ||
logger.debug('Add: {} + {} = {}'.format(num_1, num_2, add_result)) | ||
|
||
sub_result = subtract(num_1, num_2) | ||
logger.debug('Sub: {} - {} = {}'.format(num_1, num_2, sub_result)) | ||
|
||
mul_result = multiply(num_1, num_2) | ||
logger.debug('Mul: {} * {} = {}'.format(num_1, num_2, mul_result)) | ||
|
||
div_result = divide(num_1, num_2) | ||
logger.debug('Div: {} / {} = {}'.format(num_1, num_2, div_result)) |
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,28 @@ | ||
|
||
import logging | ||
|
||
logging.basicConfig(filename='employee.log', level=logging.INFO, | ||
format='%(levelname)s:%(message)s') | ||
|
||
|
||
class Employee: | ||
"""A sample Employee class""" | ||
|
||
def __init__(self, first, last): | ||
self.first = first | ||
self.last = last | ||
|
||
logging.info('Created Employee: {} - {}'.format(self.fullname, self.email)) | ||
|
||
@property | ||
def email(self): | ||
return '{}.{}@email.com'.format(self.first, self.last) | ||
|
||
@property | ||
def fullname(self): | ||
return '{} {}'.format(self.first, self.last) | ||
|
||
|
||
emp_1 = Employee('John', 'Smith') | ||
emp_2 = Employee('Corey', 'Schafer') | ||
emp_3 = Employee('Jane', 'Doe') |
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,51 @@ | ||
|
||
import logging | ||
|
||
# DEBUG: Detailed information, typically of interest only when diagnosing problems. | ||
|
||
# INFO: Confirmation that things are working as expected. | ||
|
||
# WARNING: An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’). The software is still working as expected. | ||
|
||
# ERROR: Due to a more serious problem, the software has not been able to perform some function. | ||
|
||
# CRITICAL: A serious error, indicating that the program itself may be unable to continue running. | ||
|
||
logging.basicConfig(filename='test.log', level=logging.DEBUG, | ||
format='%(asctime)s:%(levelname)s:%(message)s') | ||
|
||
|
||
def add(x, y): | ||
"""Add Function""" | ||
return x + y | ||
|
||
|
||
def subtract(x, y): | ||
"""Subtract Function""" | ||
return x - y | ||
|
||
|
||
def multiply(x, y): | ||
"""Multiply Function""" | ||
return x * y | ||
|
||
|
||
def divide(x, y): | ||
"""Divide Function""" | ||
return x / y | ||
|
||
|
||
num_1 = 20 | ||
num_2 = 10 | ||
|
||
add_result = add(num_1, num_2) | ||
logging.debug('Add: {} + {} = {}'.format(num_1, num_2, add_result)) | ||
|
||
sub_result = subtract(num_1, num_2) | ||
logging.debug('Sub: {} - {} = {}'.format(num_1, num_2, sub_result)) | ||
|
||
mul_result = multiply(num_1, num_2) | ||
logging.debug('Mul: {} * {} = {}'.format(num_1, num_2, mul_result)) | ||
|
||
div_result = divide(num_1, num_2) | ||
logging.debug('Div: {} / {} = {}'.format(num_1, num_2, div_result)) |
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,10 @@ | ||
|
||
# DEBUG: Detailed information, typically of interest only when diagnosing problems. | ||
|
||
# INFO: Confirmation that things are working as expected. | ||
|
||
# WARNING: An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’). The software is still working as expected. | ||
|
||
# ERROR: Due to a more serious problem, the software has not been able to perform some function. | ||
|
||
# CRITICAL: A serious error, indicating that the program itself may be unable to continue running. |