-
Notifications
You must be signed in to change notification settings - Fork 15
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
Showing
7 changed files
with
173 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import * as types from '@azure/functions'; | ||
import { ReadOnlyError } from '../errors'; | ||
import { nonNullProp } from '../utils/nonNull'; | ||
import { HookContext } from './HookContext'; | ||
|
||
export class LogHookContext extends HookContext implements types.LogHookContext { | ||
#init: types.LogHookContextInit; | ||
|
||
constructor(init?: types.LogHookContextInit) { | ||
super(init); | ||
this.#init = init ?? {}; | ||
this.#init.level ??= 'information'; | ||
this.#init.message ??= 'unknown'; | ||
this.#init.category ??= 'user'; | ||
} | ||
|
||
get level(): types.LogLevel { | ||
return nonNullProp(this.#init, 'level'); | ||
} | ||
|
||
set level(value: types.LogLevel) { | ||
this.#init.level = value; | ||
} | ||
|
||
get message(): string { | ||
return nonNullProp(this.#init, 'message'); | ||
} | ||
|
||
set message(value: string) { | ||
this.#init.message = value; | ||
} | ||
|
||
get category(): types.LogCategory { | ||
return nonNullProp(this.#init, 'category'); | ||
} | ||
|
||
set category(_value: types.LogCategory) { | ||
throw new ReadOnlyError('category'); | ||
} | ||
|
||
get invocationContext(): types.InvocationContext | undefined { | ||
return this.#init.invocationContext; | ||
} | ||
|
||
set invocationContext(_value: types.InvocationContext | undefined) { | ||
throw new ReadOnlyError('invocationContext'); | ||
} | ||
} |
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
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,58 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { LogLevel } from '../index'; | ||
import { InvocationContext } from '../InvocationContext'; | ||
import { HookContext, HookContextInit } from './HookContext'; | ||
|
||
/** | ||
* Handler for log hooks. | ||
*/ | ||
export type LogHookHandler = (context: LogHookContext) => void; | ||
|
||
/** | ||
* Context on a log | ||
*/ | ||
export declare class LogHookContext extends HookContext { | ||
/** | ||
* For testing purposes only. This will always be constructed for you when run in the context of the Azure Functions runtime | ||
*/ | ||
constructor(init?: LogHookContextInit); | ||
|
||
/** | ||
* If the log occurs during a function execution, the context object passed to the function handler. | ||
* Otherwise, undefined. | ||
*/ | ||
readonly invocationContext: InvocationContext | undefined; | ||
|
||
/** | ||
* 'system' if the log is generated by Azure Functions, 'user' if the log is generated by your own app. | ||
*/ | ||
readonly category: LogCategory; | ||
|
||
/** | ||
* Changes to this value _will_ affect the resulting log, but only for user-generated logs. | ||
*/ | ||
level: LogLevel; | ||
|
||
/** | ||
* Changes to this value _will_ affect the resulting log, but only for user-generated logs. | ||
*/ | ||
message: string; | ||
} | ||
|
||
/** | ||
* Object passed to LogHookContext constructors. | ||
* For testing purposes only | ||
*/ | ||
export interface LogHookContextInit extends HookContextInit { | ||
invocationContext?: InvocationContext; | ||
|
||
level?: LogLevel; | ||
|
||
category?: LogCategory; | ||
|
||
message?: string; | ||
} | ||
|
||
export type LogCategory = 'user' | 'system' | 'customMetric'; |
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