Code Monkey home page Code Monkey logo

logger's People

Contributors

benjie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

codetheweb

logger's Issues

Best strategy for existing logger?

Summary

We are considering using Graphile and we have deployed multiple tests. So far, so good (and thank you!).
However we have issues with logging inside the Tasks.
I read the section on logging and it looks like the Tasks must use their own logging from the helpers logger facility.
Unfortunately that does not look like a great option for us because we share a lot of the code in the Tasks with our web app and there are many places in this web app where we call logger.info(...) (logger is a winston logger). It is current imported in all the files where there is logging using import logger from '....'

We would really love to avoid passing down/around the "logger" object as it could be different based on whether it is the "web app logger" (winston) or the Graphile logger.

Any trick on how to make things work without rewriting all of our files? (i.e we would love to keep our import logger from '...'?

LogLevel doesn't work when using isolatedModules

Summary

Because LogLevel is a const enum, TypeScript when running with isolatedModules doesn't know the values to inline.

Steps to reproduce

Create a new TS project that has isolatedModules: true in its tsconfig and try to import LogLevel, you'll get a compile error.

And if you try to ts-ignore the error, then LogLevel.ERROR ends up being undefined.ERROR at runtime, b/c the import doesn't work (because the LogLevel symbol doesn't actually exist at runtime), and undefined.ERROR will cause an exception.

Possible Solution

For now we're just hard-coding the LogLevel values, i.e.:

    // Use pino for JSON logging
    // https://github.com/graphile/logger#creating-a-custom-logger
    logger: new GraphileLogger((scope) => {
      const scopedLogger = logger.child(scope);
      return (level, message, meta = {}) => {
        switch (level) {
          case "error":
            return scopedLogger.error(meta, message);
          case "warning":
            return scopedLogger.warn(meta, message);
          case "debug":
            return scopedLogger.debug(meta, message);
          case "info":
          default:
            return scopedLogger.info(meta, message);
        }
      };

De-const-izing LogLevel would fix the issue.

Enum isn't exported correctly for use in another TypeScript project.

Summary

export const enum LogLevel means that the enum will not work as expected with TypeScript. This needs to be export enum LogLevel instead.

Steps to reproduce

Create a new TypeScript project, add & import @graphile/logger. Try to use it like myVal === LogLevel.WARNING and you should get an error about can't read property of undefined. We have a wrapper that is using the log level as a condition for how it maps to our internal logger.

This occurs only at run time.

Expected results

enum should not be const, values are able to be used and match their expected string values from the @graphile/logger package.

Actual results

It throws an error that it can’t read the property

Additional context

https://ncjamieson.com/dont-export-const-enums/

Possible Solution

use export enum LogLevel instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.