Skip to content

Commit 334a5cb

Browse files
authored
Merge pull request #7 from formidablejs/release/0.1.1
Release/0.1.1
2 parents a0e8b37 + c8b0ab2 commit 334a5cb

File tree

9 files changed

+1323
-1184
lines changed

9 files changed

+1323
-1184
lines changed

.github/workflows/tests.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@ name: Tests
33
on: push
44

55
jobs:
6-
build:
7-
6+
linux:
87
runs-on: ubuntu-latest
98

109
steps:
11-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v4
11+
- name: Install modules
12+
run: npm install
13+
- name: Build lib
14+
run: npm run build
15+
- name: Run tests
16+
run: npm test
17+
18+
windows:
19+
runs-on: windows-latest
20+
21+
steps:
22+
- uses: actions/checkout@v4
1223
- name: Install modules
1324
run: npm install
1425
- name: Build lib

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/node_modules
22
/lib
3+
/storage
34
/test/e2e
45
.env
56
.env.backup

package-lock.json

Lines changed: 1253 additions & 1158 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@formidablejs/logger",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"main": "lib/index.js",
55
"description": "The Formidable Logger is a Monolog-inspired logging library",
66
"author": "Donald Pakkies",
@@ -23,20 +23,20 @@
2323
"@formidablejs/framework": "*"
2424
},
2525
"devDependencies": {
26-
"@formidablejs/framework": "0.13.11",
27-
"@types/jest": "^29.2.4",
26+
"@formidablejs/framework": "0.23.8",
27+
"@types/jest": "^29.5.5",
2828
"imba": "2.0.0-alpha.215",
29-
"jest": "^29.3.1",
30-
"ts-jest": "^29.0.3"
29+
"jest": "^29.7.0",
30+
"ts-jest": "^29.1.1"
3131
},
3232
"dependencies": {
3333
"@livy/console-formatter": "^1.0.3",
3434
"@livy/console-handler": "^1.0.3",
35-
"@livy/contracts": "^1.1.1",
36-
"@livy/file-handler": "^1.0.3",
37-
"@livy/group-handler": "^1.0.3",
38-
"@livy/line-formatter": "^1.0.3",
39-
"@livy/logger": "^1.0.5",
35+
"@livy/contracts": "^1.1.2",
36+
"@livy/file-handler": "^1.0.4",
37+
"@livy/group-handler": "^1.0.4",
38+
"@livy/line-formatter": "^1.0.4",
39+
"@livy/logger": "^1.0.6",
4040
"@livy/rotating-file-handler": "^1.0.4",
4141
"@livy/slack-webhook-handler": "^1.0.3",
4242
"got": "^12.5.3"

src/Drivers/SingleDriver.imba

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1+
import { existsSync, mkdirSync } from 'fs'
2+
import { dirname, join } from 'path'
13
import { FileHandler } from '@livy/file-handler'
24
import { LineFormatter } from '@livy/line-formatter'
35
import { Driver } from '../Driver'
46

57
export class SingleDriver < Driver
68

9+
get path
10+
let path\string = self.options.path ?? join(process.cwd!, 'storage', 'logs', 'formidable.log')
11+
12+
if (process.platform !== 'win32' && path.slice(0, 1) !== '/') || (process.platform === 'win32' && path.slice(1, 2) !== ':')
13+
path = join(process.cwd!, path)
14+
15+
if !existsSync dirname(path)
16+
try mkdirSync dirname(path), { recursive: true }
17+
18+
path
19+
720
def handler
8-
new FileHandler(self.options.path ?? 'storage/logs/formidable.log', {
21+
new FileHandler(path, {
922
formatter: new LineFormatter({
1023
include: {
1124
datetime: true,

tests/app/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export class Config extends ConfigRepository {
2121
driver: 'console',
2222
level: 'debug'
2323
},
24+
file: {
25+
driver: 'single',
26+
level: 'debug',
27+
}
2428
}
2529
}
2630
}

tests/log.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
12
import './app'
3+
import { existsSync, readFileSync, rmSync } from 'fs'
4+
import { join } from 'path'
25
import { Log } from '../lib'
36

47
describe('integration test', () => {
@@ -93,4 +96,20 @@ describe('integration test', () => {
9396
Log.channel('random-channel')
9497
}).toThrowError('Logging config is missing')
9598
})
99+
100+
it('Log to file', () => {
101+
const random = Math.random().toString(36)
102+
103+
Log.channel('file').info(random)
104+
105+
const file = join(process.cwd(), 'storage', 'logs', 'formidable.log')
106+
107+
expect(existsSync(file)).toBeTruthy()
108+
109+
expect(readFileSync(file, 'utf-8')).toContain(random)
110+
111+
if (process.platform !== 'win32') {
112+
rmSync(process.cwd() + '/storage', { recursive: true, force: true })
113+
}
114+
})
96115
})

types/Driver.d.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
// auto-generated
1+
import { HandlerInterface } from "@livy/contracts/lib/handler-interface";
22

3-
export class Driver {
4-
constructor(options?: {});
5-
_options: {};
6-
get options(): {};
7-
/**
8-
@returns { HandlerInterface }
9-
*/
3+
export class Driver<T = {}> {
4+
_options: T;
5+
constructor(options?: T);
6+
get options(): T;
107
handler(): HandlerInterface;
118
}
12-
import { HandlerInterface } from "@livy/contracts/lib/handler-interface";

types/Drivers/SingleDriver.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// auto-generated
1+
import { Driver } from "../Driver";
2+
import { FileHandler } from "@livy/file-handler";
23

34
export class SingleDriver extends Driver {
5+
get path(): string;
46
handler(): FileHandler;
57
}
6-
import { Driver } from "../Driver";
7-
import { FileHandler } from "@livy/file-handler";

0 commit comments

Comments
 (0)