Skip to content

Commit

Permalink
(feat) upgrade tslog (#4154)
Browse files Browse the repository at this point in the history
* upgrade tslog

* Create big-turtles-tease.md

* pnpm lock

* fix build issue

* upgrade pnpm in the lock file to v8

* try again

* Update main.yml

* fix build

* fix

* again

* fix spacing
  • Loading branch information
siddhsuresh authored Jun 5, 2023
1 parent 2533caf commit 5166e5e
Show file tree
Hide file tree
Showing 15 changed files with 5,708 additions and 5,529 deletions.
9 changes: 9 additions & 0 deletions .changeset/big-turtles-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@blitzjs/auth": patch
"@blitzjs/next": patch
"@blitzjs/rpc": patch
"blitz": patch
"@blitzjs/generator": patch
---

(feat) upgrade tslog to v4.8.2
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
with:
version: 7.11.0
version: 8.6.0
- name: Setup node
uses: actions/setup-node@v2
with:
Expand All @@ -40,7 +40,7 @@ jobs:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
with:
version: 7.11.0
version: 8.6.0
- name: Setup node
uses: actions/setup-node@v2
with:
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Setup PNPM
uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
with:
version: 7.11.0
version: 8.6.0

- name: Setup node@16
uses: actions/setup-node@v2
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
- name: Setup PNPM
uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
with:
version: 7.11.0
version: 8.6.0

- name: Setup node@${{ matrix.NODE_VERSION }}
uses: actions/setup-node@v2
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/blitz-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const {gSSP, gSP, api} = setupBlitzServer({
}),
],
logger: BlitzLogger({
colorizePrettyLogs: true,
prefix: ["[blitz]>>>>>"],
}),
})
Expand Down
2 changes: 1 addition & 1 deletion packages/blitz-auth/src/server/auth-sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export async function useAuthenticatedBlitzContext({
redirectAuthenticatedTo?: string | RouteUrlObject | ((ctx: Ctx) => string | RouteUrlObject)
role?: string | string[]
}): Promise<void> {
const log = baseLogger().getChildLogger()
const log = baseLogger().getSubLogger({name: "useAuthenticatedBlitzContext"})
const customChalk = new chalk.Instance({
level: log.settings.type === "json" ? 0 : chalk.level,
})
Expand Down
5 changes: 3 additions & 2 deletions packages/blitz-next/src/error-boundary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ test("withErrorBoundary HOC", () => {
expect(cleanStack(onErrorComponentStack)).toMatchInlineSnapshot(`
{
"componentStack": "
at ErrorBoundaryRoot
at withRouter
at __vite_ssr_import_4__.withErrorBoundary.FallbackComponent
at ErrorBoundaryRoot
at WithRouterWrapper
at withErrorBoundary",
}
`)
Expand Down
5 changes: 4 additions & 1 deletion packages/blitz-next/src/error-boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {NextRouter, withRouter} from "next/router"
import * as React from "react"
import {RouterContext} from "./router-context"
import _debug from "debug"
import {ExcludeRouterProps} from "next/dist/client/with-router"

const debug = _debug("blitz:errorboundary")

Expand Down Expand Up @@ -72,7 +73,9 @@ type ErrorBoundaryState = {error: Error | null}

const initialState: ErrorBoundaryState = {error: null}

const ErrorBoundary = withRouter(
const ErrorBoundary: React.ComponentType<
ExcludeRouterProps<React.PropsWithChildren<ErrorBoundaryProps>>
> = withRouter(
class ErrorBoundaryRoot extends React.Component<
React.PropsWithRef<React.PropsWithChildren<ErrorBoundaryProps>>,
ErrorBoundaryState
Expand Down
2 changes: 1 addition & 1 deletion packages/blitz-rpc/src/index-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function rpcHandler(config: RpcConfig) {
const relativeRoutePath = (req.query.blitz as string[])?.join("/")
const routePath = "/" + relativeRoutePath

const log = baseLogger().getChildLogger({
const log = baseLogger().getSubLogger({
prefix: [routePath.replace(/(\/api\/rpc)?\//, "") + "()"],
})
const customChalk = new chalk.Instance({
Expand Down
2 changes: 1 addition & 1 deletion packages/blitz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"tar": "6.1.11",
"ts-node": "10.9.1",
"tsconfig-paths": "4.0.0",
"tslog": "3.3.4",
"tslog": "4.8.2",
"watchpack": "2.1.1"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/blitz/src/cli/commands/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const pipeline = promisify(Stream.pipeline)
const got = async (url: string) => {
return require("got")(url).catch((e: any) => {
if (e.response.statusCode === 403) {
baseLogger({displayDateTime: false}).error(e.response.body)
baseLogger().error(e.response.body)
} else {
return e
}
Expand Down Expand Up @@ -264,7 +264,7 @@ const install: CliCommand = async () => {

if (!(await isUrlValid(packageJsonPath))) {
debug("Url is invalid for ", packageJsonPath)
baseLogger({displayDateTime: false}).error(`Could not find recipe "${args._[1]}"\n`)
baseLogger().error(`Could not find recipe "${args._[1]}"\n`)
console.log(`${chalk.bold("Please provide one of the following:")}
1. The name of a recipe to install (e.g. "tailwind")
Expand Down
6 changes: 2 additions & 4 deletions packages/blitz/src/installer/recipe-executor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ export class RecipeExecutor<Options extends RecipeMeta> {
{exitOnCtrlC: false},
)
await waitUntilExit()
baseLogger({displayDateTime: false, displayLogLevel: false}).info(
`\n🎉 The ${this.options.name} recipe has been installed!\n`,
)
baseLogger().info(`\n🎉 The ${this.options.name} recipe has been installed!\n`)
} catch (e) {
baseLogger({displayDateTime: false}).error(e as any)
baseLogger().error(e as any)
return
}
}
Expand Down
36 changes: 12 additions & 24 deletions packages/blitz/src/logging.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {ISettingsParam, Logger, TLogLevelName} from "tslog"
import {ILogObj, ISettingsParam, Logger, IMeta} from "tslog"
import c from "chalk"
import {Table} from "console-table-printer"
import ora from "ora"
import readline from "readline"

export type BlitzLoggerSettings = ISettingsParam
export type BlitzLogLevel = TLogLevelName
export type BlitzLoggerSettings = ISettingsParam<ILogObj>
export type BlitzLogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal"

declare namespace globalThis {
let _blitz_baseLogger: Logger
let _blitz_baseLogger: Logger<ILogObj>
let _blitz_logLevel: BlitzLogLevel
}

export const baseLogger = (options: BlitzLoggerSettings = {}): Logger => {
export const baseLogger = (options: BlitzLoggerSettings = {}): Logger<ILogObj> => {
if (globalThis._blitz_baseLogger) return globalThis._blitz_baseLogger

globalThis._blitz_baseLogger = BlitzLogger(options)
Expand All @@ -22,34 +22,22 @@ export const baseLogger = (options: BlitzLoggerSettings = {}): Logger => {

export const BlitzLogger = (settings: BlitzLoggerSettings = {}) => {
const baseLogger = new Logger({
minLevel: "info",
minLevel: 3,
type: "pretty",
dateTimePattern:
prettyLogTemplate:
process.env.NODE_ENV === "production"
? "year-month-day hour:minute:second.millisecond"
: "hour:minute:second.millisecond",
displayFunctionName: false,
displayFilePath: "hidden",
displayRequestId: false,
dateTimeTimezone:
process.env.NODE_ENV === "production"
? "utc"
: Intl.DateTimeFormat().resolvedOptions().timeZone,
prettyInspectHighlightStyles: {
name: "yellow",
number: "blue",
bigint: "blue",
boolean: "blue",
},
? "{{yyyy}}-{{mm}}-{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}"
: "{{hh}}:{{MM}}:{{ss}}:{{ms}}",
prettyLogTimeZone: process.env.NODE_ENV === "production" ? "UTC" : "local",
maskValuesOfKeys: ["password", "passwordConfirmation", "currentPassword"],
exposeErrorCodeFrame: process.env.NODE_ENV !== "production",
// exposeErrorCodeFrame: process.env.NODE_ENV !== "production",
...settings,
})

return baseLogger
}

export const initializeLogger = (logger: Logger) => {
export const initializeLogger = (logger: Logger<ILogObj>) => {
globalThis._blitz_baseLogger = logger
}

Expand Down
2 changes: 1 addition & 1 deletion packages/generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"prettier": "^2.7.1",
"recast": "0.20.5",
"supports-color": "8.1.1",
"tslog": "3.3.4",
"tslog": "4.8.2",
"username": "5.1.0",
"vinyl": "2.2.1",
"zod": "3.20.2"
Expand Down
4 changes: 2 additions & 2 deletions packages/generator/src/generators/app-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ export class AppGenerator extends Generator<AppGeneratorOptions> {

gitInitSuccessful = initResult.status === 0
if (!gitInitSuccessful) {
baseLogger({displayDateTime: false}).warn("Failed to run git init.")
baseLogger({displayDateTime: false}).warn(
baseLogger().warn("Failed to run git init.")
baseLogger().warn(
"Find out more about how to install git here: https://git-scm.com/downloads.",
)
}
Expand Down
32 changes: 9 additions & 23 deletions packages/generator/src/utils/log.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ISettingsParam, Logger} from "tslog"
import {ILogObj, ISettingsParam, Logger} from "tslog"
import c from "chalk"
import {Table} from "console-table-printer"
import ora from "ora"
Expand All @@ -8,7 +8,7 @@ import {defaultConfig} from "./default-config"

// eslint-disable-next-line
declare module globalThis {
let _blitz_baseLogger: Logger
let _blitz_baseLogger: Logger<ILogObj>
let _blitz_logLevel: LogLevel
}

Expand Down Expand Up @@ -103,7 +103,7 @@ export const newline = () => {
}
}

export const baseLogger = (options?: ISettingsParam): Logger => {
export const baseLogger = (options?: ISettingsParam<ILogObj>): Logger<ILogObj> => {
if (globalThis._blitz_baseLogger) return globalThis._blitz_baseLogger

let config
Expand All @@ -114,28 +114,14 @@ export const baseLogger = (options?: ISettingsParam): Logger => {
}

globalThis._blitz_baseLogger = new Logger({
minLevel: config.log?.level || "info",
minLevel: config.log?.level || 3,
type: config.log?.type || "pretty",
dateTimePattern:
prettyLogTemplate:
process.env.NODE_ENV === "production"
? "year-month-day hour:minute:second.millisecond"
: "hour:minute:second.millisecond",
displayFunctionName: false,
displayFilePath: "hidden",
displayRequestId: false,
dateTimeTimezone:
process.env.NODE_ENV === "production"
? "utc"
: Intl.DateTimeFormat().resolvedOptions().timeZone,
prettyInspectHighlightStyles: {
name: "yellow",
number: "blue",
bigint: "blue",
boolean: "blue",
},
colorizePrettyLogs: process.env.FORCE_COLOR === "0" ? false : true,
maskValuesOfKeys: ["password", "passwordConfirmation"],
exposeErrorCodeFrame: process.env.NODE_ENV !== "production",
? "{{yyyy}}-{{mm}}-{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}"
: "{{hh}}:{{MM}}:{{ss}}:{{ms}}",
prettyLogTimeZone: process.env.NODE_ENV === "production" ? "UTC" : "local",
maskValuesOfKeys: ["password", "passwordConfirmation", "currentPassword"],
...options,
})

Expand Down
Loading

0 comments on commit 5166e5e

Please sign in to comment.