-
Notifications
You must be signed in to change notification settings - Fork 6
Log fix #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
okhaimie-dev
wants to merge
5
commits into
develop
Choose a base branch
from
log-fix
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Log fix #109
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
16426cf
swapped logDNA w/ pino-loki
okhaimie-dev c570c7b
swapped logDNA w/ pino-loki
okhaimie-dev c60f215
merge conflit axios version fix
okhaimie-dev 554d7c3
qa action minor edit
okhaimie-dev 6808a49
merged dependency bot update
okhaimie-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,150 +1,106 @@ | ||
| import logdna, { Logger, LogOptions } from '@logdna/logger'; | ||
| import { pino } from 'pino'; | ||
| import apiKeys from '../service/constants/apiKeys'; | ||
| import { CommandContext } from 'slash-create'; | ||
| import * as Sentry from '@sentry/node'; | ||
|
|
||
| let logger: Logger; | ||
| const transport = pino.transport({ | ||
| target: 'pino-loki', | ||
| options: { | ||
| batching: true, | ||
| interval: 5, | ||
| basicAuth: { | ||
| username: apiKeys.lokiUserName, | ||
| password: apiKeys.lokiPassword, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| try { | ||
| logger = logdna.createLogger(apiKeys.logDNAToken, { | ||
| app: apiKeys.logDNAAppName, | ||
| level: apiKeys.logDNADefault, | ||
| }); | ||
| if (process.env.NODE_ENV != 'production' || !logger.info) { | ||
| // eslint-disable-next-line no-console | ||
| console.log('Logger initialized!'); | ||
| } else { | ||
| logger.log('Logger initialized!'); | ||
| } | ||
| } catch (e) { | ||
| // eslint-disable-next-line no-console | ||
| console.log('Please setup LogDNA token.'); | ||
| // eslint-disable-next-line no-console | ||
| console.log(e); | ||
| throw new Error(); | ||
| } | ||
| const logger = pino(transport); | ||
|
|
||
| const Log = { | ||
|
|
||
| info(statement: string | any, options?: Omit<LogOptions, 'level'>): void { | ||
| info(statement: string | any): void { | ||
| if (process.env.NODE_ENV != 'production' || !logger.info) { | ||
| // eslint-disable-next-line no-console | ||
| console.log(statement); | ||
| } else { | ||
| logger.info(statement, options); | ||
| logger.info(statement); | ||
| Sentry.addBreadcrumb({ | ||
| level: Sentry.Severity.Info, | ||
| message: statement, | ||
| }); | ||
| } | ||
| }, | ||
|
|
||
| warn(statement: string | any, options?: Omit<LogOptions, 'level'>): void { | ||
| warn(statement: string | any): void { | ||
| if (process.env.NODE_ENV != 'production' || !logger.warn) { | ||
| // eslint-disable-next-line no-console | ||
| console.log(statement); | ||
| } else { | ||
| logger.warn(statement, options); | ||
| logger.warn(statement); | ||
| Sentry.addBreadcrumb({ | ||
| level: Sentry.Severity.Warning, | ||
| message: statement, | ||
| }); | ||
| } | ||
| }, | ||
|
|
||
| debug(statement: string | any, options?: Omit<LogOptions, 'level'>): void { | ||
| debug(statement: string | any): void { | ||
| if (process.env.NODE_ENV != 'production' || !logger.debug) { | ||
| // eslint-disable-next-line no-console | ||
| console.debug(statement); | ||
| } else { | ||
| logger.debug(statement, options); | ||
| logger.debug(statement); | ||
| } | ||
| }, | ||
|
|
||
| error(statement: string | any, options?: Omit<LogOptions, 'level'>): void { | ||
| error(statement: string | any): void { | ||
| if (process.env.NODE_ENV != 'production' || !logger.error) { | ||
| // eslint-disable-next-line no-console | ||
| console.error(statement); | ||
| } else { | ||
| logger.error(statement, options); | ||
| logger.error(statement); | ||
| Sentry.addBreadcrumb({ | ||
| level: Sentry.Severity.Error, | ||
| message: statement, | ||
| }); | ||
| } | ||
| }, | ||
|
|
||
| fatal(statement: string | any, options?: Omit<LogOptions, 'level'>): void { | ||
| fatal(statement: string | any): void { | ||
| if (process.env.NODE_ENV != 'production' || !logger.fatal) { | ||
| // eslint-disable-next-line no-console | ||
| console.error(statement); | ||
| } else { | ||
| logger.fatal(statement, options); | ||
| logger.fatal(statement); | ||
| Sentry.addBreadcrumb({ | ||
| level: Sentry.Severity.Fatal, | ||
| message: statement, | ||
| }); | ||
| } | ||
| }, | ||
|
|
||
| trace(statement: string | any, options?: Omit<LogOptions, 'level'>): void { | ||
| trace(statement: string | any): void { | ||
| if (process.env.NODE_ENV != 'production' || !logger.trace) { | ||
| // eslint-disable-next-line no-console | ||
| console.log(statement); | ||
| } else { | ||
| logger.trace(statement, options); | ||
| logger.trace(statement); | ||
| } | ||
| }, | ||
|
|
||
| log(statement: string | any, options?: Omit<LogOptions, 'level'>): void { | ||
| if (process.env.NODE_ENV != 'production') { | ||
| // eslint-disable-next-line no-console | ||
| console.log(statement); | ||
| } | ||
| logger.log(statement, options); | ||
| Sentry.addBreadcrumb({ | ||
| level: Sentry.Severity.Log, | ||
| message: statement, | ||
| }); | ||
| }, | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
| addMetaProperty(key: string, value: any): void { | ||
| logger.addMetaProperty(key, value); | ||
| }, | ||
|
|
||
| removeMetaProperty(key: string): void { | ||
| logger.removeMetaProperty(key); | ||
| }, | ||
|
|
||
| flush(): void { | ||
| logger.flush(); | ||
| }, | ||
| }; | ||
|
|
||
| export const LogUtils = { | ||
| logCommandStart(ctx: CommandContext): void { | ||
| Log.info(`/${ctx.commandName} ran ${ctx.user.username}#${ctx.user.discriminator}`, { | ||
| indexMeta: true, | ||
| meta: { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above for RateLimit.ts and Checkout.ts. Since we're in the process of updating some of the log captures, might as well solve this now. |
||
| guildId: ctx.guildID, | ||
| userTag: `${ctx.user.username}#${ctx.user.discriminator}`, | ||
| userId: ctx.user.id, | ||
| params: ctx.options, | ||
| }, | ||
| }); | ||
| Log.info(`/${ctx.commandName} ran ${ctx.user.username}#${ctx.user.discriminator}`); | ||
| }, | ||
|
|
||
| logCommandEnd(ctx: CommandContext): void { | ||
| Log.info(`/${ctx.commandName} ended ${ctx.user.username}#${ctx.user.discriminator}`, { | ||
| indexMeta: true, | ||
| meta: { | ||
| guildId: ctx.guildID, | ||
| userTag: `${ctx.user.username}#${ctx.user.discriminator}`, | ||
| userId: ctx.user.id, | ||
| params: ctx.options, | ||
| }, | ||
| }); | ||
| Log.info(`/${ctx.commandName} ended ${ctx.user.username}#${ctx.user.discriminator}`); | ||
| }, | ||
|
|
||
| logError(message: string, error: Error | any, guildId?: string): void { | ||
|
|
@@ -154,15 +110,7 @@ export const LogUtils = { | |
| guildId: guildId, | ||
| }, | ||
| }); | ||
| Log.error(message, { | ||
| indexMeta: true, | ||
| meta: { | ||
| name: error?.name, | ||
| message: error?.message, | ||
| stack: error?.stack, | ||
| guildId: guildId, | ||
| }, | ||
| }); | ||
| Log.error(message); | ||
| } catch (e) { | ||
| Log.error(message); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.