Skip to content
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

Create a logger manager #2

Open
wizardlink opened this issue Jun 24, 2021 · 2 comments
Open

Create a logger manager #2

wizardlink opened this issue Jun 24, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@wizardlink
Copy link
Member

wizardlink commented Jun 24, 2021

A logger manager is to be created following the specifications below, keep in mind that this should be instanced right after the ConfigManager since practically everything depends on it.

Configuration

interface IConfig
{
  ...,
  logger: {
    disabled?: boolean          // Whether logging should be disabled entirely.
    all?: boolean               // Whether to log everything or not, if disabled, non-important logs will be omitted.
    bootup?: boolean            // Whether to log client startup, shutdown, etc. or not. Will include sharding, when implemented.
    loading?: boolean           // ... log loading 'events' or not, such as commands and events loading.
    sentry?: ConstructorOptions // Configuration for sentry.io using raven, if omitted, a file will be generated instead.
  }
}

Note about <IConfig>.logger.all
This is a configuration that will enable all the other options below of it, however, this also will enable debug logs across the board, including typeorm's and discord.js's debug logs.

Colors

chalk can be used for this and is encouraged.

This enumerator should be followed for colors:

enum LogColor
{
  ERROR = '\x1b[31m',    // If using chalk: 225,0,45 | #e1002d
  DEBUG = '\x1b[32m',    // ... chalk: 64,255,0 | #40ff00
  INFO = '\x1b[34m',     // ... chalk: 72,143,246 | #488ff6
  WARNING = '\x1b[33m',  // ... chalk: 255,255,51 | #ffff33
  EMPHASIS = '\x1b[35m', // ... chalk: 191,0,255 | #bf00ff
}

If chalk isn't being used, a bg<Name> property needs to be added to each one, otherwise, use the same color. Text should generally always be white, but, when emphasis is needed you can use the <LogColor>.EMPHASIS color.

NOTE - If there are readability issues with any of these colors, please comment over them and we'll arrange a new color.

Features

  1. Access colors
    • Colors should be accessed via their names, like <LoggerManager>.info(message: string, isBackground?: boolean).
  2. Logging (obviously)
    • This should be either accessed via <LoggerManager>.log(message: string, options: ILogOptions).
    • An example of a log message is: <LoggerManager>.log(<LoggerManager>.info('[' + <LoggerManager>.emphasis('READY') + ']', true) + ' Client is ready!')
  3. Decorator
    • A decorator should be made that in it's nature, will catch any errors created by the method and log it as well register it (file or sentry.io).

Logging options (ILogOptions)

// These are basically template references for more easily log messages
enum ILogType
{
  ERROR = 'error',      // [ERROR] → <Message>
  DEBUG = 'debug',      // [DEBUG] → <Message>
  INFO = 'info',        // [INFO] → <Message>
  WARNING = 'warning',  // [WARNING] → <Message>
}

interface ILogOptions
{
  type?: ILogType    // The logging template, optional
  register?: boolean // Whether to report to sentry or on a file
  silent?: boolean // Only report, don't log to console
}

Errors

When an error is caught with the decorator, it should send to sentry.io if it's configured, or, create a directory (if it doesn't exists) inside <ConfigManager>.rootDirectory called .log and then a file akita_neru.error_<time>.log. An example name for the file is: akita_neru.error_2021-06-24.log.

@wizardlink wizardlink added the enhancement New feature or request label Jun 24, 2021
@wizardlink wizardlink added this to the v1 milestone Jun 24, 2021
@wizardlink
Copy link
Member Author

Assigned you to this @SpaceEEC since you already coded most of it. If there are specifications missing, please do let me know below or in our development channel @ Discord.

@wizardlink wizardlink assigned wizardlink and unassigned SpaceEEC Jun 27, 2021
@wizardlink
Copy link
Member Author

Self assigning the issue, got some interesting ideas in mind so you can leave this with me. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants