Skip to content

Commit

Permalink
Merge pull request #5 from kumparan/feature/extra-log
Browse files Browse the repository at this point in the history
feature: add extra log
  • Loading branch information
aslamhadi authored Oct 4, 2023
2 parents 75f879e + 9db4cb4 commit 273a996
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 101 deletions.
42 changes: 0 additions & 42 deletions .chglog/CHANGELOG.tpl.md

This file was deleted.

31 changes: 0 additions & 31 deletions .chglog/config.yml

This file was deleted.

17 changes: 0 additions & 17 deletions CHANGELOG.md

This file was deleted.

8 changes: 0 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,3 @@ publish:
format-all-files:
poetry run black .
poetry run isort .

changelog_args=-o CHANGELOG.md -tag-filter-pattern '^v'

changelog:
ifdef version
$(eval changelog_args=--next-tag $(version) $(changelog_args))
endif
git-chglog $(changelog_args)
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
# unified python utils
# Unified Python Utils

Collection of python library utils

## Installation

```poetry add upils```

## How to use the logger

First, set up the logger. It accepts string like "INFO" or int 20

```logger = configure_logger(20)```

And then you can just use it like other logger

```
logger.info("info")
logger.warning("warning")
```

### Add extra information
How to use the extra logging:

```
logger.bind(user="ajung", desc="smart").error(
"Inline binding of extra attribute"
)
```

The output will be

```
{"level": "ERROR", "time": {"repr": "2023-10-04 12:03:53.043106+07:00", "timestamp": 1696395833.043106}, "message": "Inline binding of extra attribute", "file": {"name": "app.py", "path": "/Users/user/Documents/projects/de-projects/service/statistics-services/app.py"}, "line": 47, "exception": null, "extra": {"ajung": "smart"}}
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "upils"
version = "0.2.1"
version = "0.2.2"
description = "Unified Python Utils"
authors = ["Aslam Hadi Harsono <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion upils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def serialize(record):
"file": {"name": record["file"].name, "path": record["file"].path},
"line": record["line"],
"exception": exception,
"extra": record["extra"]
}
return json.dumps(subset, default=str, ensure_ascii=False) + "\n"

Expand All @@ -44,7 +45,6 @@ def configure_logger(level: Union[str, int]) -> logger:
# remove default option from loguru. if we don't remove this, it will result in duplicated logs
logger.remove(0)
loguru_logger = logger.patch(patching) # use custom serializer

loguru_logger.add(
sink=sys.stdout,
level=level,
Expand Down

0 comments on commit 273a996

Please sign in to comment.