-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not export console-log-level publicly (#337)
* fix: do not export console-log-level publicly console-log-level types are an implementation detail. Exporting them meant that users needed to have @types/console-log-level installed to be able to use this module. This requires either that the users know that they need @types/console-log-level in their devDependencies or we need to decalare them in our main dependencies. Fixes: #336 * Update ts/src/logger.ts
- Loading branch information
1 parent
88f71a4
commit 4c61da5
Showing
3 changed files
with
46 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright 2017 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as consoleLogLevel from 'console-log-level'; | ||
import {defaultConfig} from './config'; | ||
|
||
const pjson = require('../../package.json'); | ||
|
||
const LEVEL_NAMES: consoleLogLevel.LogLevelNames[] = | ||
['fatal', 'error', 'warn', 'info', 'debug', 'trace']; | ||
|
||
function logLevelToName(level?: number): consoleLogLevel.LogLevelNames { | ||
if (level === undefined) { | ||
level = defaultConfig.logLevel; | ||
} else if (level < 0) { | ||
level = 0; | ||
} else if (level > 4) { | ||
level = 4; | ||
} | ||
return LEVEL_NAMES[level]; | ||
} | ||
|
||
export function createLogger(level?: number) { | ||
return consoleLogLevel( | ||
{stderr: true, prefix: pjson.name, level: logLevelToName(level)}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters