Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
134c0b89
Unverified
Commit
134c0b89
authored
Dec 09, 2022
by
mergify[bot]
Committed by
GitHub
Dec 09, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4334 from ethereum-optimism/sc/cmn-log-level-option
feat(cmn): make logLevel a default option
parents
9a0778cc
ffcee101
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
3 deletions
+37
-3
sharp-colts-yawn.md
.changeset/sharp-colts-yawn.md
+5
-0
base-service-v2.ts
packages/common-ts/src/base-service/base-service-v2.ts
+12
-2
validators.ts
packages/common-ts/src/base-service/validators.ts
+11
-0
logger.ts
packages/common-ts/src/common/logger.ts
+9
-1
No files found.
.changeset/sharp-colts-yawn.md
0 → 100644
View file @
134c0b89
---
'
@eth-optimism/common-ts'
:
patch
---
Make logLevel a default option of BaseServiceV2
packages/common-ts/src/base-service/base-service-v2.ts
View file @
134c0b89
...
...
@@ -11,7 +11,7 @@ import promBundle from 'express-prom-bundle'
import
bodyParser
from
'
body-parser
'
import
morgan
from
'
morgan
'
import
{
Logger
}
from
'
../common/logger
'
import
{
Logger
,
LogLevel
}
from
'
../common/logger
'
import
{
Metric
,
Gauge
,
Counter
}
from
'
./metrics
'
import
{
validators
}
from
'
./validators
'
...
...
@@ -23,6 +23,7 @@ export type StandardOptions = {
loopIntervalMs
?:
number
port
?:
number
hostname
?:
string
logLevel
?:
LogLevel
}
export
type
OptionsSpec
<
TOptions
extends
Options
>
=
{
...
...
@@ -155,6 +156,7 @@ export abstract class BaseServiceV2<
loopIntervalMs
?:
number
port
?:
number
hostname
?:
string
logLevel
?:
LogLevel
}
)
{
this
.
loop
=
params
.
loop
!==
undefined
?
params
.
loop
:
true
...
...
@@ -176,6 +178,11 @@ export abstract class BaseServiceV2<
desc
:
'
Hostname for the app server
'
,
default
:
params
.
hostname
||
'
0.0.0.0
'
,
},
logLevel
:
{
validator
:
validators
.
logLevel
,
desc
:
'
Log level
'
,
default
:
params
.
logLevel
||
'
debug
'
,
},
}
// Add default options to options spec.
...
...
@@ -322,7 +329,10 @@ export abstract class BaseServiceV2<
// Set up everything else.
this
.
loopIntervalMs
=
this
.
options
.
loopIntervalMs
this
.
logger
=
new
Logger
({
name
:
params
.
name
})
this
.
logger
=
new
Logger
({
name
:
params
.
name
,
level
:
this
.
options
.
logLevel
,
})
this
.
healthy
=
true
// Gracefully handle stop signals.
...
...
packages/common-ts/src/base-service/validators.ts
View file @
134c0b89
...
...
@@ -13,6 +13,8 @@ import { Provider } from '@ethersproject/abstract-provider'
import
{
Signer
}
from
'
@ethersproject/abstract-signer
'
import
{
ethers
}
from
'
ethers
'
import
{
LogLevel
,
logLevels
}
from
'
../common
'
const
provider
=
makeValidator
<
Provider
>
((
input
)
=>
{
const
parsed
=
url
().
_parse
(
input
)
return
new
ethers
.
providers
.
JsonRpcProvider
(
parsed
)
...
...
@@ -39,6 +41,14 @@ const wallet = makeValidator<Signer>((input) => {
}
})
const
logLevel
=
makeValidator
<
LogLevel
>
((
input
)
=>
{
if
(
!
logLevels
.
includes
(
input
as
LogLevel
))
{
throw
new
Error
(
`expected log level to be one of
${
logLevels
.
join
(
'
,
'
)}
`
)
}
else
{
return
input
as
LogLevel
}
})
export
const
validators
=
{
str
,
bool
,
...
...
@@ -52,4 +62,5 @@ export const validators = {
provider
,
jsonRpcProvider
,
staticJsonRpcProvider
,
logLevel
,
}
packages/common-ts/src/common/logger.ts
View file @
134c0b89
...
...
@@ -3,7 +3,15 @@ import pinoms, { Streams } from 'pino-multi-stream'
import
{
createWriteStream
}
from
'
pino-sentry
'
import
{
NodeOptions
}
from
'
@sentry/node
'
export
type
LogLevel
=
'
trace
'
|
'
debug
'
|
'
info
'
|
'
warn
'
|
'
error
'
|
'
fatal
'
export
const
logLevels
=
[
'
trace
'
,
'
debug
'
,
'
info
'
,
'
warn
'
,
'
error
'
,
'
fatal
'
,
]
as
const
export
type
LogLevel
=
typeof
logLevels
[
number
]
export
interface
LoggerOptions
{
name
:
string
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment