Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
logging-ts
Advanced tools
Changelog
0.3.4
IO
withLogger
combinator, #21 (@waynevanson)Readme
Adapted from purescript-logging
fp-ts
and TypeScript compatibilitylogging-ts version | required fp-ts version | required TypeScript version |
---|---|---|
0.3.0 | 2.0.0+ | 3.5+ |
0.2.0 | 1.7.0+ | 2.8.0+ |
From purescript-logging
's README
A logger receives records and potentially performs some effects. You can create a logger from any function
(a: A) => HKT<M, void>
for anyA
andM
.Unlike most other logging libraries,
logging-ts
has no separate concepts "loggers" and "handlers". Instead, loggers can be composed into larger loggers using theSemigroup
instance. Loggers can also be transformed usingcontramap
(for transforming records) andfilter
(for filtering records). An example use case might be the following:
import * as C from 'fp-ts/lib/Console'
import * as D from 'fp-ts/lib/Date'
import { chain, IO } from 'fp-ts/lib/IO'
import { pipe } from 'fp-ts/lib/pipeable'
import * as L from '../src/IO'
type Level = 'Debug' | 'Info' | 'Warning' | 'Error'
interface Entry {
message: string
time: Date
level: Level
}
function showEntry(entry: Entry): string {
return `[${entry.level}] ${entry.time.toLocaleString()} ${entry.message}`
}
function getLoggerEntry(prefix: string): L.LoggerIO<Entry> {
return entry => C.log(`${prefix}: ${showEntry(entry)}`)
}
const debugLogger = L.filter(getLoggerEntry('debug.log'), e => e.level === 'Debug')
const productionLogger = L.filter(getLoggerEntry('production.log'), e => e.level !== 'Debug')
const logger = L.getMonoid<Entry>().concat(debugLogger, productionLogger)
const info = (message: string) => (time: Date): IO<void> => logger({ message, time, level: 'Info' })
const debug = (message: string) => (time: Date): IO<void> => logger({ message, time, level: 'Debug' })
const program = pipe(
D.create,
chain(info('boot')),
chain(() => D.create),
chain(debug('Hello!'))
)
program()
/*
production.log: [Info] 10/4/2019, 12:44:48 PM boot
debug.log: [Debug] 10/4/2019, 12:44:48 PM Hello!
*/
FAQs
Composable loggers for TypeScript
The npm package logging-ts receives a total of 1,936 weekly downloads. As such, logging-ts popularity was classified as popular.
We found that logging-ts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.