code-chunks/angular2-logger

Can I use this for Production? Or when will this be ready for PROD?

Opened this issue ยท 20 comments

Based the Readme.md this is not for production.
Can I use this for Production somehow? Or when will this be ready for PROD?

Hi @batchu good question.

Well since Angular is already released its probable that they stop making breaking changes.

The syntaxis could probably change a little bit when future features come but I'll try my best to keep the old way working, worst case scenario is you'd have to point to a specific version of the library in your package.json but I dont believe this would happen soon if it does.

So I'd think its production ready now. Angular 2 is still too new so I'll give it a couple more weeks to see if anything arises then I'll remove the warning.

Hi @langley-agm, a related question here.
What is your recommendation for changing the log level between dev and production?
I'm trying to rely on ng's CLI environment.production config variable, which does enable prod mode for CLI purposes, but can't seem to be able to use it for log level config purposes.
Even though I do ng serve -prod or ng build -prod, enironment.production when read in the Logger service always returns false.
I know the question is not directly related to angular2-logger, and could stem from a bug with CLI itself, but I just wanted to hear the expert's opinion on how to avoid manual reconfiguration during/for production deployment.
Thank you!

@vkniazeu

Usually this is one of the aspects where DI starts to shine.
You can use one common setup file and two more specifics for dev / prod.
In dev you can Inject DEBUG_LOGGER_PROVIDERS or LOG_LOGGER_PROVIDERS.
And in prod you can Inject WARN_LOGGER_PROVIDERS or INFO_LOGGER_PROVIDERS.

This is mostly about project preferences, I usually leave it as info for both, and use the console to change it only when I need something more specific, then change it back to info after I'm done.

@langley-agm,
Thanks for the quick response! The DI flow is clear. My question is more specific to the CLI environment.production setup. I haven't yet had any luck getting an answer at the specific forums, and have a feeling that there might be a bug.
angular-cli is already setup to handle dev vs. prod flows.
The environments/environment.ts file is set up to get overridden if a -prod flag is sent to ng serve or ng build:

// The file for the current environment will overwrite this one during build.
// Different environments can be found in ./environment.{dev|prod}.ts, and
// you can create your own and use it with the --env flag.
// The build system defaults to the dev environment.

export const environment = {
  production: false
};

Doing ng serve -prod does correctly set this const to true for purposes of enabling angular internal prod mode in main.ts

if (environment.production) {
  enableProdMode();
}

I'm trying to use the same config variable to affect the LOGGER level, but whether I introduce environment.production into my app.module.ts or into the logger class's constructor itself (I extended it to add time prefixes), I always get a false no matter what flag I set.

Again, I know this doesn't quite relate to your module. I figured I'd just ask if you ran into a similar setup.

Thanks!

So the regular configuration in your app should be something like this:

@NgModule({
    ...
    providers:    [ LOG_LOGGER_PROVIDERS ]
})

What happens if you create a constant in an environment specific file and use that one instead?

environment.ts (the default)

export const LOGGER_PROVIDERS = [ WARN_LOGGER_PROVIDERS ]

environment.production.ts (prod specific)

export const LOGGER_PROVIDERS = [ OFF_LOGGER_PROVIDERS ]

app.module.ts

@NgModule({
    ...
    providers:  LOGGER_PROVIDERS
})

@langley-agm Thank you very much for all the time and help!
I've tried your suggestion and a slightly modified one, but unfortunately it didn't work.
It clearly is not about the logger. I don't want to waste another second of your time.
FWIW, environment.production.ts seems to only affect main.ts, but is not picked up in app.module.ts or other classes. I'll spend some more time investigating later and ask within appropriate channels or open a bug with the CLI team.

For me everything works perfect during development with ng serve but when I try to build project ng serve -prod, I got this error:
screen shot 2017-03-22 at 17 18 24

Version:

$ ng version
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / โ–ณ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.0.0-rc.4
node: 6.10.0
os: darwin x64
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/cli: 1.0.0-rc.4
@angular/compiler-cli: 2.4.10

This is how app it looks like:
screen shot 2017-03-22 at 17 21 27

@stepanic ng2-logger ? are you using two loggers?

@langley-agm this is okay, also without n2-logger reference angular2logger is not working and after 3 hours of trying to integrate angular2logger I chose n2-logger as alternative

@langley-agm this is application, you could add angular2logger to AppComponent and inject Logger in constructor and you will see the same error in the browser after ng serve -prod
Archive.zip

first, execute npm install --save angular2-logger because I removed it from the project after unsuccessful integration

$ npm -v
4.4.1
$ node -v
v6.10.0

@stepanic I've the same problem using angular2-logger in an application based on the last stable versions of angular and angular-cli:
@angular/...@4.0.0
@angular/cli@1.0.0

I tried to replace the angular2-logger dependencies including directly the 3 source files (level.ts, logger.ts and providers.ts) in my project and updating the imports: now I'm able do run the application in prod mode using ng serve -prod without the error from polyfills.

Maybe the problem is from how the library is compiled to be published in npm?

@stepanic

Maybe the problem is from how the library is compiled to be published in npm?

There's no correct way to compile a library, different frameworks require different ways. That's why the dist includes different compiles so you use the one you need. Even Angular 2 has been changing this several times.

The problem is in how its getting loaded. If you notice in Angular AOT's guide they have to make an specific configuration just for the rxjs library:

https://angular.io/docs/ts/latest/cookbook/aot-compiler.html

must likely its a similar issue.

I am working to find a way for people to not to have to go through this extra step for AoT, hopefully that'll help cli as well.

Hi @langley-agm ,

I am also getting the following error in production build:
Uncaught Error: No provider for t!

image

Is there a fix for this?

Thanks,
Hari

Hello @harikrishnan-u01 ,

That's an error of the minified code, I can't possibly guess what that t means. You have to add map files next to the min files in order for it to show you what's the exact error in the unminified code.

Hi @stepanic ,

Did you find a fix for this issue? Or is there any alternate solution I can use?

Thanks,
Hari

I am also facing the same issue when i run command ng serve-prod. I am unable to find solution for the same , as how to use library in production mode.
amazonissue

Hi @pankajsri03 ,

There was no resolution for this issue. So I ended up implementing my own logger framework.

But you can try using https://github.com/dbfannin/ngx-logger which was working fine in production build. There was an issue with IE11 because of which I didnt use this library. But this seem to be fixed in the latest release.

Hope this helps.

Thanks,
Hari

seems like it's not possible to use that library with angular-cli build optimizer
image

@ToGoBananas yea, no work has been done yet towards cli support, PRs are welcome =)