Improve Response verbose/debug logging
This commit is contained in:
parent
10b3e1ecc3
commit
6f66126d38
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@extollo/lib",
|
||||
"version": "0.9.12",
|
||||
"version": "0.9.13",
|
||||
"description": "The framework library that lifts up your code.",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
@ -100,6 +100,7 @@ export class Response {
|
||||
|
||||
/** Set the value of the response header. */
|
||||
public setHeader(name: string, value: string | string[]): this {
|
||||
this.logging.verbose(`Will set header on response: ${name}`)
|
||||
if ( this.sentHeaders ) {
|
||||
throw new HeadersAlreadySentError(this, name)
|
||||
}
|
||||
@ -113,6 +114,7 @@ export class Response {
|
||||
* @param data
|
||||
*/
|
||||
public setHeaders(data: {[name: string]: string | string[]}): this {
|
||||
this.logging.verbose(`Will set headers on response: ${Object.keys(data).join(', ')}`)
|
||||
if ( this.sentHeaders ) {
|
||||
throw new HeadersAlreadySentError(this)
|
||||
}
|
||||
@ -128,12 +130,16 @@ export class Response {
|
||||
* @param value
|
||||
*/
|
||||
public appendHeader(name: string, value: string | string[]): this {
|
||||
this.logging.verbose(`Will append header: ${name}`)
|
||||
|
||||
if ( this.sentHeaders ) {
|
||||
throw new HeadersAlreadySentError(this, name)
|
||||
}
|
||||
|
||||
if ( !Array.isArray(value) ) {
|
||||
value = [value]
|
||||
}
|
||||
|
||||
let existing = this.headers[name] ?? []
|
||||
if ( !Array.isArray(existing) ) {
|
||||
existing = [existing]
|
||||
@ -152,6 +158,7 @@ export class Response {
|
||||
* Write the headers to the client.
|
||||
*/
|
||||
public sendHeaders(): this {
|
||||
this.logging.verbose(`Sending headers...`)
|
||||
const headers = {} as any
|
||||
|
||||
const setCookieHeaders = this.cookies.getSetCookieHeaders()
|
||||
@ -199,6 +206,7 @@ export class Response {
|
||||
* @param data
|
||||
*/
|
||||
public async write(data: string | Buffer | Uint8Array | Readable): Promise<void> {
|
||||
this.logging.verbose(`Writing headers & data to response... (destroyed? ${this.serverResponse.destroyed})`)
|
||||
return new Promise<void>((res, rej) => {
|
||||
if ( this.responseEnded || this.serverResponse.destroyed ) {
|
||||
throw new ErrorWithContext('Tried to write to Response after lifecycle ended.')
|
||||
|
@ -1,15 +1,17 @@
|
||||
import {Container} from '../di'
|
||||
import {
|
||||
ErrorWithContext,
|
||||
FileLogger,
|
||||
globalRegistry,
|
||||
ifDebugging,
|
||||
infer,
|
||||
isLoggingLevel, logIfDebugging,
|
||||
isLoggingLevel,
|
||||
LoggingLevel,
|
||||
logIfDebugging,
|
||||
PathLike,
|
||||
StandardLogger,
|
||||
universalPath,
|
||||
UniversalPath,
|
||||
FileLogger,
|
||||
ifDebugging,
|
||||
} from '../util'
|
||||
import {Logging} from '../service/Logging'
|
||||
import {RunLevelErrorHandler} from './RunLevelErrorHandler'
|
||||
@ -221,6 +223,7 @@ export class Application extends Container {
|
||||
logging.registerLogger(file)
|
||||
}
|
||||
|
||||
logging.level = LoggingLevel.Verbose
|
||||
logging.verbose('Attempting to load logging level from the environment...')
|
||||
|
||||
const envLevel = this.env('EXTOLLO_LOGGING_LEVEL')
|
||||
|
@ -26,6 +26,7 @@ const isLoggingLevel = (something: unknown): something is LoggingLevel => {
|
||||
LoggingLevel.Info,
|
||||
LoggingLevel.Debug,
|
||||
LoggingLevel.Verbose,
|
||||
LoggingLevel.Trace,
|
||||
].includes(something as any)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user