Skip to content

Commit

Permalink
Merge pull request #3 from guiiai/fix/tty
Browse files Browse the repository at this point in the history
fix: bug: support cloudflare worker #2
  • Loading branch information
luoling8192 authored Aug 3, 2024
2 parents aab32cb + 0d5a48d commit 96216fd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
11 changes: 11 additions & 0 deletions examples/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Format, LogLevel, createLogg, setGlobalFormat, setGlobalLogLevel } from '../src'

setGlobalLogLevel(LogLevel.Debug)
setGlobalFormat(Format.Pretty) // Otherwise it will output JSON

// Create a logger instance with a specific context
const log = createLogg('http/request').useGlobalConfig()

log
.withField('url', 'https://github.com/guiiai/logg')
.log('Welcome to our repository')
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@guiiai/logg",
"type": "module",
"version": "1.0.1",
"version": "1.0.2",
"packageManager": "[email protected]",
"description": "Yet another simple, nearly zero dependency, structural log compliance logger implementation.",
"contributors": [
Expand Down
7 changes: 6 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { gray, green, magenta, yellow } from 'colorette'
import { gray, green, isColorSupported, magenta, yellow } from 'colorette'

import { logLevelStringToLogLevelMap, logLevelToChalkColorMap } from './constants'
import type { Log, LogLevelString } from './types'
Expand Down Expand Up @@ -67,6 +67,11 @@ export function newErrorLog(logLevel: LogLevelString, context: string, fields: R
}

export function toPrettyString(log: Log): string {
// Disable colors if not supported
if (!isColorSupported) {
return JSON.stringify(log)
}

const messagePartials: string[] = []

messagePartials.push(log['@timestamp'])
Expand Down

0 comments on commit 96216fd

Please sign in to comment.