Skip to content

Commit aac2266

Browse files
authored
Rename basilisp.logging to basilisp.logging_config (#246)
* Rename basilisp.logging to basilisp.logging_config * Move logging to main * Add service name * Pass Travis CI environment variables
1 parent 869bc51 commit aac2266

File tree

5 files changed

+30
-34
lines changed

5 files changed

+30
-34
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ release:
1313

1414
.PHONY: repl
1515
repl:
16-
@BASILISP_USE_DEV_LOGGER=true
17-
@pipenv run basilisp repl
16+
@BASILISP_USE_DEV_LOGGER=true pipenv run basilisp repl
1817

1918

2019
.PHONY: test

src/basilisp/cli.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import basilisp.main as basilisp
1515
import basilisp.reader as reader
1616

17-
importlib.import_module('basilisp.logging')
18-
1917

2018
@click.group()
2119
def cli():

src/basilisp/logging.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/basilisp/main.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
11
import importlib
2+
import logging
3+
import os
24

35
import basilisp.importer as importer
46
import basilisp.lang.runtime as runtime
57

6-
importlib.import_module('basilisp.logging')
8+
9+
def _get_default_level() -> str:
10+
"""Get the default logging level for Basilisp."""
11+
return os.getenv('BASILISP_LOGGING_LEVEL', 'WARNING')
12+
13+
14+
def _get_default_handler(level: str, formatter: logging.Formatter) -> logging.Handler:
15+
"""Get the default logging handler for Basilisp."""
16+
handler: logging.Handler = logging.NullHandler()
17+
if os.getenv('BASILISP_USE_DEV_LOGGER') == 'true':
18+
handler = logging.StreamHandler()
19+
20+
handler.setFormatter(formatter)
21+
handler.setLevel(level)
22+
return handler
23+
24+
25+
_DEFAULT_FORMAT = '%(asctime)s %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] - %(message)s'
26+
_DEFAULT_FORMATTER = logging.Formatter(_DEFAULT_FORMAT)
27+
_DEFAULT_LEVEL = _get_default_level()
28+
_DEFAULT_HANDLER = _get_default_handler(_DEFAULT_LEVEL, _DEFAULT_FORMATTER)
29+
30+
logger = logging.getLogger('basilisp')
31+
logger.setLevel(_DEFAULT_LEVEL)
32+
logger.addHandler(_DEFAULT_HANDLER)
733

834

935
def init():

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ python =
66
3.6: py36, coverage, lint
77

88
[testenv]
9+
passenv = TRAVIS TRAVIS_*
910
deps =
1011
six==1.10.0
1112
commands =
@@ -16,7 +17,7 @@ deps =
1617
coveralls
1718
coverage
1819
six==1.10.0
19-
setenv =
20+
setenv =
2021
COVERALLS_REPO_TOKEN = {env:COVERALLS_REPO_TOKEN}
2122
usedevelop = true
2223
commands =

0 commit comments

Comments
 (0)