Skip to content

Commit

Permalink
feat: migrate package to adonisjs provider
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Sep 6, 2019
1 parent 27680f6 commit aeca305
Show file tree
Hide file tree
Showing 29 changed files with 1,067 additions and 1,044 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ _Put an `x` in the boxes that apply_

_Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._

- [ ] I have read the [CONTRIBUTING](https://github.com/poppinss/logger/blob/master/CONTRIBUTING.md) doc
- [ ] I have read the [CONTRIBUTING](https://github.com/adonisjs/logger/blob/master/CONTRIBUTING.md) doc
- [ ] Lint and unit tests pass locally with my changes
- [ ] I have added tests that prove my fix is effective or that my feature works.
- [ ] I have added necessary documentation (if appropriate)
Expand Down
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1557762307/poppinss_iftxlt.jpg" width="600px">
<img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1564392111/adonis-banner_o9lunk.png" width="600px">
</div>

# Logger
Expand All @@ -12,6 +12,7 @@ Extremely fast JSON logger built on top of [pino](http://getpino.io). The module
## Table of contents

- [Usage](#usage)
- [Usage with AdonisJs](#usage-with-adonisjs)
- [What's changed from Pino?](#whats-changed-from-pino)
- [Making certain fields required](#making-certain-fields-required)
- [enabled](#enabled)
Expand All @@ -30,16 +31,16 @@ Extremely fast JSON logger built on top of [pino](http://getpino.io). The module
Install the package from npm as follows:

```sh
npm i @poppinss/logger
npm i @adonisjs/logger

# yarn
yarn add @poppinss/logger
yarn add @adonisjs/logger
```

and then use it as follows

```ts
import { Logger } from '@poppinss/logger'
import { Logger } from '@adonisjs/logger/build/standalone'
const logger = new Logger({
enabled: true,
name: 'adonis-logger',
Expand All @@ -49,6 +50,23 @@ const logger = new Logger({
logger.debug('received new request %s', request.url())
```

## Usage with AdonisJs
The `@adonisjs/core` module includes this module by default. However, here's how you can set it up manually.

```ts
const providers = [
'@adonisjs/logger/build/providers/LoggerProvider'
]
```

And then also register the typings file inside `tsconfig.json` file.

```json
{
"files": ["./node_modules/@adonisjs/logger/build/adonis-typings/logger.d.ts"]
}
```

## What's changed from Pino?
We have changed handful of config options to make things more explicit. The modifications are based on our own opinions.

Expand All @@ -73,7 +91,7 @@ Just like the `messageKey`, you can define the key for showing the level number
Instead of passing the stream as the 2nd argument, you can define the custom stream within the config.

```ts
import { Logger } from '@poppinss/logger'
import { Logger } from '@adonisjs/logger/build/standalone'

new Logger({
stream: process.stdout,
Expand All @@ -100,7 +118,7 @@ export class MyApp {
Inside your tests

```ts
import { FakeLogger } from '@poppinss/logger'
import { FakeLogger } from '@adonisjs/logger/build/standalone'
import { MyApp } from './MyApp'

const logger = new FakeLogger({
Expand All @@ -127,11 +145,11 @@ Following are the autogenerated files via Typedoc
## Maintainers
[Harminder virk](https://github.com/thetutlage)

[circleci-image]: https://img.shields.io/circleci/project/github/poppinss/logger/master.svg?style=for-the-badge&logo=circleci
[circleci-url]: https://circleci.com/gh/poppinss/logger "circleci"
[circleci-image]: https://img.shields.io/circleci/project/github/adonisjs/logger/master.svg?style=for-the-badge&logo=circleci
[circleci-url]: https://circleci.com/gh/adonisjs/logger "circleci"

[npm-image]: https://img.shields.io/npm/v/@poppinss/logger.svg?style=for-the-badge&logo=npm
[npm-url]: https://npmjs.org/package/@poppinss/logger "npm"
[npm-image]: https://img.shields.io/npm/v/@adonisjs/logger.svg?style=for-the-badge&logo=npm
[npm-url]: https://npmjs.org/package/@adonisjs/logger "npm"

[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript

Expand Down
91 changes: 91 additions & 0 deletions adonis-typings/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* @module @adonisjs/logger
*/

/*
* @adonisjs/logger
*
* (c) Harminder Virk <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare module '@ioc:Adonis/Core/Logger' {
import {
Level,
TimeFn,
redactOptions,
PrettyOptions,
SerializerFn,
LevelMapping,
DestinationStream,
} from 'pino'

/**
* Config shape
*/
export type LoggerConfigContract = {
name: string,
level: Level | 'silent' | string,
enabled: boolean,
messageKey?: string,
safe?: boolean,
crlf?: boolean,
useLevelLabels?: boolean,
levelKey?: string,
timestamp?: TimeFn | boolean,
customLevels?: {
[key: string]: number,
},
useOnlyCustomLevels?: boolean,
redact?: string[] | redactOptions,
prettyPrint?: boolean | PrettyOptions,
base?: { [key: string]: any } | null,
serializers?: { [key: string]: SerializerFn },
stream?: DestinationStream,
}

/**
* Logger interface that main and fake logger implements
*/
export interface LoggerContract {
level: string,
levelNumber: number,
levels: LevelMapping,
pinoVersion: string,
LOG_VERSION: number,

log (level: string, message: string, ...values: any[]): void
log (level: string, mergingObject: any, message: string, ...values: any[]): void

trace (message: string, ...values: any[]): void
trace (mergingObject: any, message: string, ...values: any[]): void

debug (message: string, ...values: any[]): void
debug (mergingObject: any, message: string, ...values: any[]): void

info (message: string, ...values: any[]): void
info (mergingObject: any, message: string, ...values: any[]): void

warn (message: string, ...values: any[]): void
warn (mergingObject: any, message: string, ...values: any[]): void

error (message: string, ...values: any[]): void
error (mergingObject: any, message: string, ...values: any[]): void

fatal (message: string, ...values: any[]): void
fatal (mergingObject: any, message: string, ...values: any[]): void

isLevelEnabled (level: string): boolean,
bindings (): { [key: string]: any },
child (bindings: {
level?: Level | string,
serializers: { [key: string]: SerializerFn },
[key: string]: any,
}): LoggerContract,
}

const Logger: LoggerContract
export default Logger
}
12 changes: 7 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
**[@poppinss/logger](README.md)**
**[@adonisjs/logger](README.md)**

[Globals](README.md)

## Index

### External modules

* ["FakeLogger"](modules/_fakelogger_.md)
* ["Logger"](modules/_logger_.md)
* ["contracts"](modules/_contracts_.md)
* ["getPino"](modules/_getpino_.md)
* ["adonis-typings/logger"](modules/_adonis_typings_logger_.md)
* ["providers/LoggerProvider"](modules/_providers_loggerprovider_.md)
* ["src/FakeLogger"](modules/_src_fakelogger_.md)
* ["src/Logger"](modules/_src_logger_.md)
* ["src/getPino"](modules/_src_getpino_.md)
* ["standalone"](modules/_standalone_.md)
Loading

0 comments on commit aeca305

Please sign in to comment.