-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a54a73
commit 442a8f7
Showing
13 changed files
with
495 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lib | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
extends: | ||
- "@socialgouv/eslint-config-typescript" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lib | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# | ||
# | ||
# | ||
|
||
Install logger: | ||
extends: .autodevops_install | ||
image: node:14.16.0-alpine3.11 | ||
cache: | ||
key: | ||
files: | ||
- yarn.lock | ||
prefix: ${CI_JOB_NAME} | ||
paths: | ||
- yarn | ||
script: | ||
- yarn config set cache-folder ${CI_PROJECT_DIR}/.cache/yarn | ||
- yarn global add @socialgouv/yarn-workspace-focus-install | ||
- yarn exec yarn-workspace-focus-install | ||
-- | ||
--cwd infra/logger | ||
-- | ||
--frozen-lockfile --prefer-offline | ||
artifacts: | ||
expire_in: 1 week | ||
paths: | ||
- infra/logger/node_modules | ||
- node_modules | ||
|
||
# | ||
# | ||
# | ||
|
||
Build logger: | ||
extends: .base_yarn_script | ||
image: node:14.16.0-alpine3.11 | ||
needs: | ||
- job: Install logger | ||
artifacts: true | ||
before_script: | ||
- cd infra/logger | ||
script: | ||
- yarn build | ||
artifacts: | ||
expire_in: 1 week | ||
paths: | ||
- infra/logger/lib | ||
|
||
# | ||
# | ||
# | ||
|
||
Lint logger: | ||
extends: .autodevops_lint | ||
dependencies: null | ||
image: node:14.16-alpine3.13 | ||
needs: | ||
- job: Install logger | ||
artifacts: true | ||
before_script: | ||
- cd infra/logger | ||
script: | ||
- yarn lint | ||
|
||
# | ||
# | ||
# | ||
|
||
Test logger: | ||
extends: .autodevops_test | ||
dependencies: null | ||
image: node:14.16-alpine3.13 | ||
needs: | ||
- job: Install logger | ||
artifacts: true | ||
before_script: | ||
- cd infra/logger | ||
script: | ||
- yarn test | ||
artifacts: | ||
expire_in: 1 week | ||
paths: | ||
- infra/logger/lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"name": "@socialgouv/cdtn-logger", | ||
"description": "SocialGouv - Code du travail numerique - Infrastructure - Logger", | ||
"version": "1.0.0-alpha.1", | ||
"babel": { | ||
"env": { | ||
"test": { | ||
"presets": [ | ||
"@babel/preset-typescript" | ||
], | ||
"plugins": [ | ||
"@babel/plugin-transform-modules-commonjs", | ||
"babel-plugin-dynamic-import-node" | ||
] | ||
} | ||
} | ||
}, | ||
"dependencies": { | ||
"winston": "^3.3.3" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.12.17", | ||
"@babel/plugin-transform-modules-commonjs": "^7.13.8", | ||
"@babel/preset-typescript": "^7.13.0", | ||
"@socialgouv/eslint-config-typescript": "^1.57.0", | ||
"@tsconfig/node14": "^1.0.0", | ||
"@types/jest": "^26.0.20", | ||
"@types/std-mocks": "^1.0.0", | ||
"babel-plugin-dynamic-import-node": "^2.3.3", | ||
"eslint": "^7.19.0", | ||
"jest": "^26.6.3", | ||
"lint-staged": "^10.5.4", | ||
"prettier": "^2.2.1", | ||
"std-mocks": "^1.0.1", | ||
"typescript": "^4.1.5" | ||
}, | ||
"license": "Apache-2.0", | ||
"main": "lib/index.js", | ||
"private": "true", | ||
"repository": { | ||
"directory": "infra/logger", | ||
"type": "git", | ||
"url": "https://github.com/SocialGouv/cdtn-admin.git" | ||
}, | ||
"scripts": { | ||
"build": "tsc -p tsconfig.build.json", | ||
"lint": "eslint src", | ||
"lint:fix": "yarn lint --fix", | ||
"prepush": "yarn lint && yarn test", | ||
"precommit": "lint-staged", | ||
"test": "jest", | ||
"watch": "yarn build --watch --preserveWatchOutput" | ||
}, | ||
"lint-staged": { | ||
"src/**": [ | ||
"yarn lint --fix", | ||
"yarn test --bail --findRelatedTests" | ||
] | ||
}, | ||
"sideEffects": false, | ||
"typings": "lib/index.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
|
||
import { flush, restore, use } from "std-mocks"; | ||
|
||
process.env.NODE_ENV = "production"; | ||
|
||
test("should log less than or equal to info level to stdout", async () => { | ||
// NOTE(douglasduteil): remove any LOG_LEVEL set in the env | ||
// Ensute that the external env does not interfer with the test. | ||
delete process.env.LOG_LEVEL; | ||
|
||
const { logger } = await import("./index"); | ||
|
||
use(); | ||
|
||
logger.error("an error"); | ||
logger.warn("an warn"); | ||
logger.info("an info"); | ||
logger.http("an http"); | ||
logger.verbose("an verbose"); | ||
logger.debug("an debug"); | ||
logger.silly("an debug"); | ||
|
||
restore(); | ||
|
||
const output = flush(); | ||
expect(output.stderr).toMatchInlineSnapshot(`Array []`); | ||
expect(output.stdout).toMatchInlineSnapshot(` | ||
Array [ | ||
"{\\"message\\":\\"an error\\",\\"level\\":\\"error\\"} | ||
", | ||
"{\\"message\\":\\"an warn\\",\\"level\\":\\"warn\\"} | ||
", | ||
"{\\"message\\":\\"an info\\",\\"level\\":\\"info\\"} | ||
", | ||
] | ||
`); | ||
}); | ||
|
||
test("should log all levels to stdout", async () => { | ||
jest.resetModules(); | ||
|
||
process.env.LOG_LEVEL = "silly"; | ||
const { logger } = await import("./index"); | ||
|
||
use(); | ||
|
||
logger.error("an error"); | ||
logger.warn("an warn"); | ||
logger.info("an info"); | ||
logger.http("an http"); | ||
logger.verbose("an verbose"); | ||
logger.debug("an debug"); | ||
logger.silly("an debug"); | ||
|
||
restore(); | ||
|
||
const output = flush(); | ||
expect(output.stderr).toMatchInlineSnapshot(`Array []`); | ||
expect(output.stdout).toMatchInlineSnapshot(` | ||
Array [ | ||
"{\\"message\\":\\"an error\\",\\"level\\":\\"error\\"} | ||
", | ||
"{\\"message\\":\\"an warn\\",\\"level\\":\\"warn\\"} | ||
", | ||
"{\\"message\\":\\"an info\\",\\"level\\":\\"info\\"} | ||
", | ||
"{\\"message\\":\\"an http\\",\\"level\\":\\"http\\"} | ||
", | ||
"{\\"message\\":\\"an verbose\\",\\"level\\":\\"verbose\\"} | ||
", | ||
"{\\"message\\":\\"an debug\\",\\"level\\":\\"debug\\"} | ||
", | ||
"{\\"message\\":\\"an debug\\",\\"level\\":\\"silly\\"} | ||
", | ||
] | ||
`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
|
||
import { createLogger, format, transports } from "winston"; | ||
|
||
const { Console } = transports; | ||
|
||
export const LOG_LEVEL = process.env.LOG_LEVEL ?? "info"; | ||
export const logger = createLogger({ | ||
level: LOG_LEVEL, | ||
transports: [], | ||
}); | ||
|
||
if (process.env.NODE_ENV !== "production") { | ||
logger.add( | ||
new Console({ | ||
format: format.combine(format.colorize(), format.simple()), | ||
}) | ||
); | ||
} else { | ||
logger.add( | ||
new Console({ | ||
format: format.json(), | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"extends": "./tsconfig.json", | ||
"files": ["./src/index.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"extends": "@tsconfig/node14/tsconfig.json", | ||
"compilerOptions": { | ||
"declaration": true, | ||
"outDir": "lib", | ||
"rootDir": "src" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
{ | ||
"packages": [ | ||
"shared/*", | ||
"targets/*" | ||
], | ||
"npmClient": "yarn", | ||
"useWorkspaces": true, | ||
"version": "1.0.0-alpha.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
"k8s": "yarn --silent --cwd .k8s" | ||
}, | ||
"workspaces": [ | ||
"infra/*", | ||
"shared/*", | ||
"targets/*" | ||
], | ||
|
Oops, something went wrong.