Skip to content

Using store() is not working as expected #80

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

Closed
nilseckert opened this issue Oct 26, 2016 · 1 comment
Closed

Using store() is not working as expected #80

nilseckert opened this issue Oct 26, 2016 · 1 comment
Labels

Comments

@nilseckert
Copy link

I tried to use store() to persist the dynamically changed logger settings.

My test was

logger.level = logger.Level.DEBUG;
logger.store();

The value is stored in localStorage as 4.

Before refreshing the browser isInfoEnabled() and isDebugEnabled() are working as expected. But after refreshing the browser internal statelevel is now a string value: DEBUG.

I created a fork and removed the cast to string in the following line (logger.ts):

private _loadLevel = (): Level => Level[localStorage.getItem( this._storeAs ) as string];

This solved the issue for me. I will provide a pull request for that.

@langley-agm
Copy link
Contributor

langley-agm commented Nov 9, 2016

Hi @nilseckert nice finding.

However I don't think as string is the issue, casting is a compile time/typescript only feature, it shouldn't affect the runtime/js functionality.

The issue is caused by the Level[] notation. Typescript brings back either the key if you look for the value, or the value if you look for the key (at least in 2.0). That's because they translate the enum to an array similar to this:

0: "OFF"
1: "ERROR"
...
DEBUG: 4
ERROR: 1
...

I tried the solution in your pull request and it didn't fix it for me. Do you mind double checking? else if you apply the changes in the comments I added, I'll apply your pull request, thanks for your contribution =)

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

No branches or pull requests

2 participants