Skip to content

Commit 569be99

Browse files
committed
Add timestamps to all console logs
1 parent bf63f0d commit 569be99

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "github-contribution-api",
33
"description": "Scrape contribution data of a Github user",
4-
"version": "4.7.2",
4+
"version": "4.7.3",
55
"author": "Jonathan Gruber <gruberjonathan@gmail.com>",
66
"license": "MIT",
77
"private": true,
@@ -36,6 +36,7 @@
3636
"dependencies": {
3737
"cheerio": "^1.0.0",
3838
"compression": "^1.7.4",
39+
"console-stamp": "^3.1.2",
3940
"cors": "^2.8.4",
4041
"domhandler": "^5.0.3",
4142
"express": "^4.21.1",

pnpm-lock.yaml

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

src/index.ts renamed to src/app.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import compression from 'compression'
2+
import cors from 'cors'
13
import express, { ErrorRequestHandler } from 'express'
24
import cache from 'memory-cache'
3-
import cors from 'cors'
4-
import compression from 'compression'
5-
65
import {
76
NestedResponse as ApiNestedResponse,
87
Response as ApiResponse,
@@ -88,7 +87,7 @@ app.get('/v4/:username', async (req: Request, res, next) => {
8887

8988
next(
9089
new Error(
91-
`Error scraping contribution data of '${username}': ${
90+
`Failed scraping contribution data of '${username}': ${
9291
error instanceof Error ? error.message : 'Unknown error.'
9392
}`,
9493
),

src/scrape.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fromURL } from 'cheerio'
22

33
import { Element, isText } from 'domhandler'
4-
import { ParsedQuery } from '.'
4+
import { ParsedQuery } from './app'
55

66
type Level = 0 | 1 | 2 | 3 | 4
77
type Year = number | 'lastYear'

src/server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import app from './index'
1+
import consoleStamp from 'console-stamp'
2+
import app from './app'
3+
4+
// Globally wrap the console to add timestamps to every call.
5+
consoleStamp(console, { format: ':date(isoDateTime)' })
26

37
const server = app.listen(process.env.PORT ?? 8080, () =>
48
console.log(

tests/index.test.ts renamed to tests/app.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Server } from 'http'
22
import cache from 'memory-cache'
33
import request from 'supertest'
4-
import app from '../src'
4+
import app from '../src/app'
55
import * as fetchService from '../src/scrape'
66
import testDataMultipleYears from './fixtures/grubersjoe-2017-2018.json'
77
import testDataNested from './fixtures/grubersjoe-2018-nested.json'
@@ -114,7 +114,7 @@ describe('The :username endpoint', () => {
114114
.expect(500)
115115
.expect((res) =>
116116
expect(res.body).toStrictEqual({
117-
error: `Error scraping contribution data of '${username}': unexpected error`,
117+
error: `Failed scraping contribution data of '${username}': unexpected error`,
118118
}),
119119
)
120120
})

0 commit comments

Comments
 (0)