Skip to content

Commit

Permalink
feat(log): logging namespace, whoami split;
Browse files Browse the repository at this point in the history
- Use explicit `ckan.ckanapi` logging name for easier logging handlers.
- Added `split` for the `who am i` output.
- Changed logging level from `debug` to `info`.
  • Loading branch information
JVickery-TBS committed Mar 13, 2024
1 parent 55115ff commit 3363e04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
30 changes: 1 addition & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,35 +474,7 @@ ckanapi.log_local = True
The output of the log will look like:

```
DEBUG [ckanapi.cli.main] OS User <user> executed LocalCKAN: ckanapi <args>
```

Because the ckanapi namespace does not match ckan or ckanext namespaces, you may need to create a new logging handler. Example:

```
[loggers]
keys = ckanapi
[handlers]
keys = console
[formatters]
keys = generic
[logger_ckanapi]
level = DEBUG
handlers = console
qualname = ckanapi
propagate = 0
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s] %(message)s
DEBUG [ckan.ckanapi] OS User <user> executed LocalCKAN: ckanapi <args>
```

### TestAppCKAN
Expand Down
10 changes: 6 additions & 4 deletions ckanapi/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@

from logging import getLogger


log = getLogger(__name__)
# explicit logger namespace for easy logging handlers
log = getLogger('ckan.ckanapi')
PYTHON2 = str is bytes

def parse_arguments():
Expand Down Expand Up @@ -153,8 +153,10 @@ def main(running_with_paster=False):
else:
# remove line breaks from whoami's
out = out.replace('\n', '').replace('\r', '')
log.debug('OS User %s executed LocalCKAN: ckanapi %s',
out, u' '.join(sys.argv[1:]))
# split the `who am i`
out = out.split()[0]
log.info('OS User %s executed LocalCKAN: ckanapi %s',
out, u' '.join(sys.argv[1:]))

stdout = getattr(sys.stdout, 'buffer', sys.stdout)
if arguments['action']:
Expand Down

0 comments on commit 3363e04

Please sign in to comment.