Skip to content

Commit

Permalink
small log enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
hazelnutcloud committed Apr 12, 2023
1 parent b9efb44 commit a899e5a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 36 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.4.2 (unreleased)

- fix: fixed a bug with the indexing logic
- chore: slight adustment to the console logger
- feat: added a log to indicate when the arkiver starts indexing live

# v0.4.1

- feat: change `arkiver remove` command to use the arkive name specified in the
Expand Down
16 changes: 11 additions & 5 deletions cli/start/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,17 @@ export const action = async (

log.setup({
handlers: {
console: new ArkiveConsoleLogHandler(options.logLevel as log.LevelName, {
arkiveName: manifest.name ?? 'my-arkive',
arkiveId: 0,
arkiveVersion: 1,
}),
console: new ArkiveConsoleLogHandler(
options.logLevel.toUpperCase() as log.LevelName,
{
arkive: {
name: manifest.name ?? 'my-arkive',
id: 0,
majorVersion: 1,
minorVersion: 0,
},
},
),
},
loggers: {
arkiver: {
Expand Down
10 changes: 6 additions & 4 deletions src/arkiver/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ export class DataSource {
this.liveBlockHeight,
)

if (toBlock === this.liveBlockHeight && !this.isLive) this.isLive = true
if (toBlock === this.liveBlockHeight && !this.isLive) {
this.isLive = true
logger().info(
`Start live arkiving for ${this.chain} at ${this.liveBlockHeight}`,
)
}

if (fromBlock > toBlock) {
await delay(this.liveDelay)
Expand Down Expand Up @@ -359,9 +364,6 @@ export class DataSource {
(source.startBlockHeight === 'live' && this.isLive)
)
if (blockSources.length === 0) {
logger().debug(
`No filtered block sources found for ${this.chain} at ${this.fetchedBlockHeight}`,
)
this.blocksQueue.set(
fromBlock,
{
Expand Down
55 changes: 28 additions & 27 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
import { colors, ConsoleHandler, log } from "./deps.ts";
import { colors, ConsoleHandler, log } from './deps.ts'

type Arkive = {
name: string
majorVersion: number
minorVersion: number
id: number
}

export class ArkiveConsoleLogHandler extends ConsoleHandler {
private arkiveName: string;
private arkiveId: number;
private arkiveVersion: number;
private arkive: Arkive

constructor(
levelName: log.LevelName,
options: log.HandlerOptions & {
arkiveName: string;
arkiveId: number;
arkiveVersion: number;
},
) {
super(levelName, options);
this.arkiveName = options.arkiveName;
this.arkiveId = options.arkiveId;
this.arkiveVersion = options.arkiveVersion;
}
constructor(
levelName: log.LevelName,
options: log.HandlerOptions & {
arkive: Arkive
},
) {
super(levelName, options)
this.arkive = options.arkive
}

override format(logRecord: log.LogRecord): string {
let msg = super.format(logRecord);
override format(logRecord: log.LogRecord): string {
let msg = super.format(logRecord)

msg = `${
colors.blue(
`[${this.arkiveId}-${this.arkiveName}@v${this.arkiveVersion}]`,
)
} ${msg}`;
msg = `${
colors.blue(
`[${this.arkive.id}:${this.arkive.name}@v${this.arkive.majorVersion}.${this.arkive.minorVersion}]`,
)
} ${msg}`

return msg;
}
return msg
}
}

export const logger = () => log.getLogger("arkiver");
export const logger = () => log.getLogger('arkiver')

1 comment on commit a899e5a

@vercel
Copy link

@vercel vercel bot commented on a899e5a Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.