Skip to content

Instantly share code, notes, and snippets.

View ashen007's full-sized avatar
🥸
Human Coder

Hewarathna A. I. ashen007

🥸
Human Coder
View GitHub Profile
@ashen007
ashen007 / main.py
Created February 27, 2023 06:09
modified main program
import json
import logging
from logging.config import dictConfig
from package.module_x import lib_x
from package.module_y import lib_y
# configure logging in user program
# lode json
@ashen007
ashen007 / lib_y.py
Created February 27, 2023 06:09
use of json
import json
import logging
import numpy as np
from logging.config import dictConfig
# configure logging module_y
# lode json
with open('package/logconfig.json', 'r') as file:
conf = json.load(file)
@ashen007
ashen007 / lib_x.py
Created February 27, 2023 06:08
use of json file
import json
import logging
import numpy as np
from logging.config import dictConfig
# configure logging in module_x
# lode json
with open('package/logconfig.json', 'r') as file:
conf = json.load(file)
@ashen007
ashen007 / logconfig.json
Last active February 27, 2023 06:07
basic log config json
{
"version": 1,
"disable_existing_loggers": false,
"handlers": {
"default": {
"class": "logging.FileHandler",
"filename": ".log",
"level": "DEBUG"
},
"stderror": {
@ashen007
ashen007 / lib_x-log-dict.py
Created February 27, 2023 04:28
use of dictConfig
import logging
from logging.config import dictConfig
# configure logging in module_x
# handlers
handlers = {'default': {'class': 'logging.FileHandler',
'filename': '.log'}}
# root
@ashen007
ashen007 / lib_x-file-handler.py
Created February 27, 2023 03:12
use file handler
# create file handler and config logging level
handler = logging.FileHandler(filename='.log', mode='a', encoding='utf-8')
handler.setLevel(logging.DEBUG)
@ashen007
ashen007 / main.py
Created February 27, 2023 03:01
main file for user progam
import logging
from package.module_x import lib_x
from package.module_y import lib_y
# configure logging in user program
# get the named logger object
logger = logging.getLogger(__name__)
# update logging level
@ashen007
ashen007 / lib_y.py
Created February 27, 2023 03:01
module y submodule
import logging
# configure logging module_y
# get the named logger object
logger = logging.getLogger(__name__)
# update logging level
logger.setLevel(logging.DEBUG)
@ashen007
ashen007 / lib_x.py
Created February 27, 2023 03:00
module x submodule
import logging
# configure logging in module_x
# get the named logger object
logger = logging.getLogger(__name__)
# update logging level
logger.setLevel(logging.DEBUG)
@ashen007
ashen007 / lib.py
Created February 26, 2023 17:31
example 1-1 other module
import logging
def do_something():
print("call this to do somthing")
logging.debug("do somthing executed in module-lib.")