Skip to content

Commit d9b7f65

Browse files
committed
Merge branch 'feature/usage-instructions' into develop
2 parents b418a0b + 7faf27b commit d9b7f65

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

README.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,54 @@
1-
# simplelog
1+
# simplelog-decorator
22

33
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/devsheva/simplelog/qa.yml)
44
[![NPM Version](https://img.shields.io/npm/v/simplelog-decorator)](https://www.npmjs.com/package/simplelog-decorator)
55
[![Codecov](https://img.shields.io/codecov/c/github/devsheva/simplelog)](https://app.codecov.io/github/devsheva/simplelog)
66

7-
A simple logger decorator amplify like
7+
A simple logger built as class decorator, amplify like.
88

9-
## Important
9+
## Quick Start
1010

11-
**Experimental decorators** are used for this package implementation and since experimental it has some bugs like unsafe typing.
11+
### Usage
12+
13+
Due to the experimental decorators feature, there are some limitations.
14+
Starting from the preferred syntax `@Logger()`
15+
16+
In TypeScript you need to simply enable `experimentalDecorators: true` in your `tsconfig.json`, to be able to use the preferred syntax.
17+
18+
In JavaScript you need to use external libraries like [@babel/plugin-proposal-decorators](https://www.npmjs.com/package/@babel/plugin-proposal-decorators) to use the preferred syntax.
19+
20+
Anyway since a decorator is just a function, you can use it by importing the `loggerDecorator` method.
21+
22+
Arguments of logger are:
23+
24+
- `name`: optional, default value is name of class
25+
- `options`:
26+
- `level`: default to `info`
27+
28+
```ts
29+
import Logger, {loggerDecorator} from 'simplelog-decorator'
30+
31+
// @Logger('YourCustomClass')
32+
// @Logger('YourCustomClass', {level: 'warn'})
33+
// loggerDecorator()(YourClass)
34+
@Logger() // name will be YourClass, level info
35+
class YourClass {
36+
sample_method() {
37+
this.logger.verbose('hi from sample_method')
38+
this.logger.debug('hi from sample_method')
39+
this.logger.info('hi from sample_method')
40+
this.logger.warn('hi from sample_method')
41+
this.logger.error('hi from sample_method')
42+
43+
}
44+
}
45+
46+
47+
```
48+
49+
## Limitations
50+
51+
As previously said, **experimental decorators** are used for this package implementation and since experimental it has some bugs like `unsafe typing`.
1252
TypeScript compiler complains when it finds out a property used inside a class that calls a decorator cause it cannot infer it, so as a temporary workaround simply declare an interface
1353

1454
```ts
@@ -20,4 +60,10 @@ class Example {
2060
this.logger.debug() // THIS IS VALID
2161
}
2262
}
23-
```
63+
```
64+
65+
## Contributing
66+
67+
This has been developed as a personal project, in order to be able to have an amplify-like logger as a package, without needing to install the whole amplify lib for just logging features.
68+
69+
But feel free to contribute by forking this project and opening a PR once done.

0 commit comments

Comments
 (0)