Skip to content

Commit

Permalink
feat(ts): add types for Logger class (rnmapbox#1316)
Browse files Browse the repository at this point in the history
* feat(ts): add types for Logger class

* update changelog

* refactor(ts): review comments

* docs(Logger): add Logger docs [by hand 😭]
  • Loading branch information
ferdicus authored Apr 20, 2021
1 parent 13bcdb4 commit ffa51af
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PR Title ([#123](link to my pr))

----
## NEXT
Add types for `Logger` class ([#1316](https://github.com/react-native-mapbox-gl/maps/pull/1316))
Enable linear easing on map camera ([#1281](https://github.com/react-native-mapbox-gl/maps/pull/1281))
Allow MapLibre as an option ([#1311](https://github.com/react-native-mapbox-gl/maps/pull/1311))
Fix native UserLocation on Android ([#1284](https://github.com/react-native-mapbox-gl/maps/pull/1284))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export default class App extends Component {

- [MapboxGL](/docs/MapboxGL.md)
- [CustomHttpHeaders](/docs/CustomHttpHeaders.md)
- [Logger](/docs/Logger.md)

## Expo Support

Expand Down
23 changes: 23 additions & 0 deletions docs/Logger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Logger
###

### methods
#### setLogLevel(LogLevel)

##### arguments
| Name | Type | Required | Description |
| ---- | :--: | :------: | :----------: |
| `LogLevel` | `String` | `Yes` | required level of logging, can be `"error" | "warning" | "info" | "debug" | "verbose"` |

##### Description
sets the amount of logging

#### setLogCallback(LogCallback)

##### arguments
| Name | Type | Required | Description |
| ---- | :--: | :------: | :----------: |
| `LogCallback` | `function` | `Yes` | callback taking a log object `{ message: String, level: LogLevel, tag: String }` as param. If callback return falsy value then default logging will take place. |

##### Description
overwrite logging - good to mute specific errors/ warnings
16 changes: 16 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,4 +902,20 @@ export interface SnapshotOptions {
writeToDisk?: boolean;
}

// Logger class
type LogLevel = "error" | "warning" | "info" | "debug" | "verbose";

interface LogObject {
level: LogLevel;
msg: string;
tag: string;
}

type LogCallback = (object: LogObject) => void;

export class Logger {
public static setLogCallback: (cb: LogCallback) => boolean;
public static setLogLevel: (level: LogLevel) => void;
}

export default MapboxGL;

0 comments on commit ffa51af

Please sign in to comment.