@@ -164,36 +164,38 @@ export default class LambdaLog extends EventEmitter {
164164 * Logs a message at the `trace` log level.
165165 * @template T The type of the message to log.
166166 * @param {T } msg Message to log. Can be any type, but string or `Error` is reccommended.
167- * @param {GenericRecord } [meta] Optional meta data to attach to the log.
167+ * @param {Metadata } [meta] Optional meta data to attach to the log.
168168 * @param {Tag[] } [tags] Additional tags to append to this log.
169- * @returns {LogMessage|false } Returns instance of LogMessage or `false` if the level of the log exceeds to the maximum set log level .
169+ * @returns {LogMessage } Returns instance of LogMessage.
170170 */
171- trace < T extends Message > ( msg : T , meta ?: GenericRecord , tags ?: Tag [ ] ) {
172- return this . log ( 'trace' , msg , meta , tags ) ;
171+ trace < T extends Message = Message > ( msg : T , meta ?: Metadata , tags ?: Tag [ ] ) : LogMessage {
172+ return this . _log < T > ( 'trace' , msg , meta , tags ) ;
173173 }
174174
175175 /**
176176 * Logs a message at the `debug` log level.
177177 * @template T The type of the message to log.
178178 * @param {T } msg Message to log. Can be any type, but string or `Error` is reccommended.
179- * @param {GenericRecord } [meta] Optional meta data to attach to the log.
179+ * @param {Metadata } [meta] Optional meta data to attach to the log.
180180 * @param {Tag[] } [tags] Additional tags to append to this log.
181- * @returns {LogMessage|false } Returns instance of LogMessage or `false` if the level of the log exceeds to the maximum set log level .
181+ * @returns {LogMessage } Returns instance of LogMessage.
182182 */
183- debug < T extends Message > ( msg : T , meta ?: GenericRecord , tags ?: Tag [ ] ) {
184- return this . log ( 'debug' , msg , meta , tags ) ;
183+ debug < T extends Message = Message > ( msg : T , meta ?: Metadata , tags ?: Tag [ ] ) : LogMessage {
184+ return this . _log < T > ( 'debug' , msg , meta , tags ) ;
185185 }
186186
187187 /**
188188 * Logs a message at the `info` log level.
189189 * @template T The type of the message to log.
190190 * @param {T } msg Message to log. Can be any type, but string or `Error` is reccommended.
191- * @param {GenericRecord } [meta] Optional meta data to attach to the log.
191+ * @param {Metadata } [meta] Optional meta data to attach to the log.
192192 * @param {Tag[] } [tags] Additional tags to append to this log.
193- * @returns {LogMessage|false } Returns instance of LogMessage or `false` if the level of the log exceeds to the maximum set log level .
193+ * @returns {LogMessage } Returns instance of LogMessage.
194194 */
195- info < T extends Message > ( msg : T , meta ?: GenericRecord , tags ?: Tag [ ] ) {
196- return this . log ( 'info' , msg , meta , tags ) ;
195+ info < T extends Message = Message > ( msg : T , meta ?: Metadata , tags ?: Tag [ ] ) : LogMessage {
196+ return this . _log < T > ( 'info' , msg , meta , tags ) ;
197+ }
198+
197199 /**
198200 * Alias for `info`.
199201 * @template T The type of the message to log.
@@ -210,70 +212,68 @@ export default class LambdaLog extends EventEmitter {
210212 * Logs a message at the `warn` log level.
211213 * @template T The type of the message to log.
212214 * @param {T } msg Message to log. Can be any type, but string or `Error` is reccommended.
213- * @param {GenericRecord } [meta] Optional meta data to attach to the log.
215+ * @param {Metadata } [meta] Optional meta data to attach to the log.
214216 * @param {Tag[] } [tags] Additional tags to append to this log.
215- * @returns {LogMessage|false } Returns instance of LogMessage or `false` if the level of the log exceeds to the maximum set log level .
217+ * @returns {LogMessage } Returns instance of LogMessage.
216218 */
217- warn < T extends Message > ( msg : T , meta ?: GenericRecord , tags ?: Tag [ ] ) {
218- return this . log ( 'warn' , msg , meta , tags ) ;
219+ warn < T extends Message = Message > ( msg : T , meta ?: Metadata , tags ?: Tag [ ] ) : LogMessage {
220+ return this . _log < T > ( 'warn' , msg , meta , tags ) ;
219221 }
220222
221223 /**
222224 * Logs a message at the `error` log level.
223225 * @template T The type of the message to log.
224226 * @param {T } msg Message to log. Can be any type, but string or `Error` is reccommended.
225- * @param {GenericRecord } [meta] Optional meta data to attach to the log.
227+ * @param {Metadata } [meta] Optional meta data to attach to the log.
226228 * @param {Tag[] } [tags] Additional tags to append to this log.
227- * @returns {LogMessage|false } Returns instance of LogMessage or `false` if the level of the log exceeds to the maximum set log level .
229+ * @returns {LogMessage } Returns instance of LogMessage.
228230 */
229- error < T extends Message > ( msg : T , meta ?: GenericRecord , tags ?: Tag [ ] ) {
230- return this . log ( 'error' , msg , meta , tags ) ;
231+ error < T extends Message = Message > ( msg : T , meta ?: Metadata , tags ?: Tag [ ] ) : LogMessage {
232+ return this . _log < T > ( 'error' , msg , meta , tags ) ;
231233 }
232234
233235 /**
234236 * Logs a message at the `error` log level.
235237 * @template T The type of the message to log.
236238 * @param {T } msg Message to log. Can be any type, but string or `Error` is reccommended.
237- * @param {GenericRecord } [meta] Optional meta data to attach to the log.
239+ * @param {Metadata } [meta] Optional meta data to attach to the log.
238240 * @param {Tag[] } [tags] Additional tags to append to this log.
239- * @returns {LogMessage|false } Returns instance of LogMessage or `false` if the level of the log exceeds to the maximum set log level .
241+ * @returns {LogMessage } Returns instance of LogMessage.
240242 */
241- fatal < T extends Message > ( msg : T , meta ?: GenericRecord , tags ?: Tag [ ] ) {
242- return this . log ( 'fatal' , msg , meta , tags ) ;
243+ fatal < T extends Message = Message > ( msg : T , meta ?: Metadata , tags ?: Tag [ ] ) : LogMessage {
244+ return this . _log < T > ( 'fatal' , msg , meta , tags ) ;
243245 }
244246
245247 /**
246248 * Generates a log message if `test` is a falsy value. If `test` is truthy, the log message is skipped and returns `false`. Allows creating log messages without the need to
247249 * wrap them in an if statement. The log level will be `error`.
248- * @since 1.4.0
249250 * @template T The type of the message to log.
250251 * @param {* } test Value to test for a falsy value.
251252 * @param {T } msg Message to log. Can be any type, but string or `Error` is reccommended.
252253 * @param {object } [meta={}] Optional meta data to attach to the log.
253254 * @param {string[] } [tags=[]] Additional tags to append to this log.
254255 * @returns {LogMessage|false } The generated log message or `false` if assertion passed.
255256 */
256- assert < T extends Message > ( test : unknown , msg : T , meta ?: GenericRecord , tags ?: Tag [ ] ) {
257+ assert < T extends Message = Message > ( test : unknown , msg : T , meta ?: Metadata , tags ?: Tag [ ] ) : LogMessage | false {
257258 if ( test ) return false ;
258- return this. log ( 'error' , msg , meta , tags ) ;
259+ return this . _log < T > ( 'error' , msg , meta , tags ) ;
259260 }
260261
261262 /**
262263 * Generates a log message with the result or error provided by a promise. Useful for debugging and testing.
263- * @since 2.3.0
264264 * @param {Promise<*> } promise Promise to log the results of.
265265 * @param {object } [meta={}] Optional meta data to attach to the log.
266266 * @param {string[] } [tags=[]] Additional tags to append to this log.
267- * @returns {Promise<LogMessage | false > } A Promise that resolves with the log message.
267+ * @returns {Promise<LogMessage> } A Promise that resolves with the log message.
268268 */
269- async result ( promise : Promise < unknown > , meta ?: GenericRecord , tags ?: Tag [ ] ) {
270- const wrapper = new Promise < LogMessage | false > ( resolve => {
269+ async result ( promise : Promise < unknown > , meta ?: Metadata , tags ?: Tag [ ] ) : Promise < LogMessage > {
270+ const wrapper = new Promise < LogMessage > ( resolve => {
271271 promise
272272 . then ( value => {
273- resolve ( this . log ( 'info' , value as string , meta , tags ) ) ;
273+ resolve ( this . _log < any > ( 'info' , value , meta , tags ) ) ;
274274 } )
275275 . catch ( err => {
276- resolve ( this . log ( 'error' , err as Error , meta , tags ) ) ;
276+ resolve ( this . _log ( 'error' , err as Error , meta , tags ) ) ;
277277 } ) ;
278278 } ) ;
279279
0 commit comments