Git Product home page Git Product logo

class-logger's Introduction

Hi there 👋

ℹ️ My name is Andrey. Rockstar wannabe -> software engineer at Meta hypnotized by AI.

📌 London, UK. UK Global Talent alumni.

💼 Blockchain, web, and a bit of embedded at software consultancies (DSRDataArt) ➡️ Headed front-end at Hazelcast ➡️ Worked on web perf and WASM integration at Bricks ➡️ Enhancing DevX for mobile devs at Meta.

🎓 Voronezh State University -> Georgia Tech.

📝 Blog about life, career, and tech in English and in Russian.

🎤 Fighting my stage fright at conferences. Founded BeerJS in my home town - Voronezh. Program committee member at Geekle.

❤️ Philosophy, music (🥁 -> 🎹+🎙), Tolstoy and Dostoevsky, Yesenin, weightlifting, boxing, cycling, hiking, snowboarding.

📫 LinkedInInstagram, Twitter, Telegram.

class-logger's People

Contributors

aigoncharov avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

leekyunghee

class-logger's Issues

Unhandled promise rejection

Hi, great job for this repo that has saved me from many headaches.

Like the title says, I used @log() for a method that returns a promise, and when encountering a reject, I get the Unhandled promise rejection warning.
Now, I did not dive into your code, and I'm not an expert, but your examples do not cover this usecase so I thought I'd post an issue.

steps to reproduce: decorate a rejected promise
typescript: 3.1.6
class-logger: 1.1.0

Do you know about this problem / have any workaround / know if I'm looking the wrong way ?

Thanks in advance

[idea] IClassLoggerFormatter return non-string type

Hi, thanks for this useful project. Currently I'm using this in an electron app, and I want it woks like that:

render side (with full args)
image

node side (with args type only)
image

but because IClassLoggerFormatter spec to return string , I did some trick:

ClassLogger.setConfig({
    log: ()=> {},
    logError: ()=> {},
    formatter: {
        // @ts-ignore
        start: (data)=> {
            this.log(
                `${data.className}:${data.propertyName.toString()}`,
                ...data.args,
            )
        },
        // @ts-ignore
        end: (data)=> {
            if(!data.error) {
                this.log(
                    `${data.className}:${data.propertyName.toString()} success`,
                    data.result,
                )
            } else {
                this.error(`[ERROR]${data.className}:${data.propertyName.toString()} fail`, data.error)
            }
        }
    }
})

Maybe (data: IClassLoggerFormatterStartData) => any would be more flexable?

TypeScript 3.4 breaks the tests

The compiling and testing failed with TS 3.4.4.

 PASS  src/formatter.service.spec.ts
 PASS  src/log.decorator.spec.ts
 PASS  src/config.service.spec.ts
 FAIL  src/class-wrapper.service.spec.ts
  ● Test suite failed to run

    TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
    src/class-wrapper.service.spec.ts:283:14 - error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.

    283       expect(new TestWrapped()).toBeInstanceOf(Test)
                     ~~~~~~~~~~~~~~~~~
    src/class-wrapper.service.spec.ts:309:14 - error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.

    309       expect(new TestWrapped()).toBeInstanceOf(Test)
                     ~~~~~~~~~~~~~~~~~

 FAIL  src/log-class.decorator.spec.ts
  ● Test suite failed to run

    TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
    src/log-class.decorator.spec.ts:15:5 - error TS1238: Unable to resolve signature of class decorator when called as an expression.
      Property 'prototype' is missing in type '{}' but required in type 'typeof Test'.

    15     @LogClass(config)
           ~~~~~~~~~~~~~~~~~

 FAIL  ./index.spec.ts
  ● Test suite failed to run

    TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
    index.spec.ts:22:3 - error TS1238: Unable to resolve signature of class decorator when called as an expression.
      Type '{}' is missing the following properties from type 'typeof Test': prototype, staticSuccess, staticError

    22   @LogClass({
         ~~~~~~~~~~~
    23     log: (message) => console.info(message), // tslint:disable-line no-console
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    24   })
       ~~~~

----------------------|----------|----------|----------|----------|-------------------|
File                  |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------------------|----------|----------|----------|----------|-------------------|
All files             |    96.23 |      100 |    90.48 |    96.15 |                   |
 config.service.ts    |       75 |      100 |       60 |       75 |             26,27 |
 constants.ts         |      100 |      100 |      100 |      100 |                   |
 formatter.service.ts |      100 |      100 |      100 |      100 |                   |
 log.decorator.ts     |      100 |      100 |      100 |      100 |                   |
----------------------|----------|----------|----------|----------|-------------------|
Jest: "global" coverage threshold for statements (100%) not met: 96.23%
Jest: "global" coverage threshold for lines (100%) not met: 96.15%
Jest: "global" coverage threshold for functions (100%) not met: 90.48%
Test Suites: 3 failed, 3 passed, 6 total
Tests:       34 passed, 34 total
Snapshots:   0 total
Time:        2.553s, estimated 3s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

Does class-logger option "args" works with Node 18?

Disabling the args with boolean or object does not affect the log output in my terminal. Is it only for me? It still does display the args:

  • MyClass._checkIndexes -> done. Args: ...
@LogClass({
    include: {
        args: false
    }
})
class MyClass { /*.. Code here.. */ }

However, the classInstance option is working doe.

Performance when disabled

This looks awesome! If I wanted this in place for development and test, turned off in production, and only flipped on and off via config, what's the impact to performance in production (while disabled)?

So, say the stuff is all there, it's just off, is there a performance hit? Is every method checking the config and choosing not to log at runtime, or is the injection just not performed in the first place? Or...?

Thanks!

@LogClass does not work with `type-graphql`

I am getting this error when using with type-graphql

(node:66568) UnhandledPromiseRejectionWarning: Error: Generating schema error
    at Function.generateFromMetadata (/Volumes/Projects/flutter/tw_foodies/server/node_modules/type-graphql/dist/schema/schema-generator.js:19:23)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Object.buildSchema (/Volumes/Projects/flutter/tw_foodies/server/node_modules/type-graphql/dist/utils/buildSchema.js:9:20)
    at /Volumes/Projects/flutter/tw_foodies/server/src/index.ts:162:15
(node:66568) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:66568) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This is how I am using.

@LogClass()
@Resolver(() => Rating)
export class RatingResolver {
  @Log()
  @Mutation(() => Boolean)
  public async addRating(
    @Arg("rating", () => Float) rating: number,
    @Arg("review", () => String, { nullable: true }) review: string | null
  ): Promise<Boolean> {
    try {
      await Rating.insert({ rating, review });
      return true;
    } catch (err) {
      throw err;
    }
  }
  @Log()
  @Mutation(() => Boolean)
  public async deleteRating(@Arg("id", () => ID) id: number): Promise<Boolean> {
    try {
      await Rating.delete({ id });
      return true;
    } catch (err) {
      throw err;
    }
  }
}

@LogClass is conflicting with other decorators

I just was trying out your logging decorators. They work nicely, but only if no other class decorators are used :/

Here is an example when using @LogClass in combination with @injectable from InversifyJS.

@LogClass()
@injectable()
class MyService {

   constructor(@inject(OtherService) private otherService: OtherService) { ... }

   @Log()
   methodThatShouldBeLogged() { ... }

}

This will produce an error with following message:

Error: Missing required @injectable annotation in: MyService.

Changing the order of the decorators does also produces an error:

Error: Missing required @inject or @multiInject annotation in: argument 0 in class MyService.

I think the problem is, that the @LogClass implementation replaces the class declaration with the provided constructor function and the other decorators are removed.

Is there a workaround for this or has anyone an idea how to fix this?

Thanks in advance 🤗

Error when adding decorator to class

Hi,
I'am having a error when executing my code after adding the decorator to a class.

! TypeError: Reflect.defineMetadata is not a function
at D:\Wiredkode\Projects\Covid19NeuroTracking\Functions\functions\node_modules\class-logger\dist\src\log-class.decorator.js:7:13
at __decorate (D:\Wiredkode\Projects\Covid19NeuroTracking\Functions\functions\lib\controlers\UsersController.js:5:95)
at Object. (D:\Wiredkode\Projects\Covid19NeuroTracking\Functions\functions\lib\controlers\UsersController.js:20:5)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object. (D:\Wiredkode\Projects\Covid19NeuroTracking\Functions\functions\lib\express\endpoints\post_sysadmins.js:5:27)
! We were unable to load your functions code. (see above)

  • It appears your code is written in Typescript, which must be compiled before emulation.
  • You may be able to run "npm run build" in your functions directory to resolve this.

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.