import {
logkitty,
makeTagsFilter,
formatEntry,
formatError,
Priority,
Entry,
} from 'logkitty';
const emitter = logkitty({
platform: 'android',
minPriority: Priority.VERBOSE,
filter: makeTagsFilter('ReactNative', 'ReactNativeJS'),
});
emitter.on('entry', (entry: Entry) => {
console.log(formatEntry(entry));
});
emitter.on('error', (error: Error) => {
console.log(formatError(error));
});
Spawns logkitty with given options:
platform: 'android' | 'ios'
- Platform to get the logs from: usesadb logcat
for Android andxcrun simctl
+log
for iOS simulator`.adbPath?: string
- Custom path to adb tool orundefined
(used only whenplatform
isandroid
).priority?: number
- Minimum priority of entries to show ofundefined
, which will include all entries with priority DEBUG (Android)/DEFAULT (iOS) or above.filter?: FilterCreator
- The returned value frommakeTagsFilter
/makeAppFilter
/makeMatchFilter
/makeCustomFilter
orundefined
, which will include all entries (similar toall
command in the CLI).
When spawning logkitty you will get a instance of EventEmitter
which emits the following events:
entry
(arguments:entry: Entry
) - Emitted when new log comes in, that matches thefilter
andpriority
options. It is your responsibility to print or use that entry, for example you can useformatEntry
to print it with the same styling as in the CLI.error
(arguments:error: Error
) - Emitted when the log can't be parsed into a entry or when the Logcat process emits an error. You can useformatError
to print it with the same styling as in the CLI.
Available for both Android and iOS.
Creates a filter from given tags (for example ReactNative
, ReactNativeJS
), so only entries matching any of the given tags will be emitted in entry
event. Pass the returned value to filter
property when running logkitty
.
Available only for Android.
Creates a filter for given application identifier (for example com.example.app
), so only entries from given app will be emitted in entry
event. Pass the returned value to filter
property when running logkitty
.
Available for both Android and iOS.
Creates a filter from given regexes (for example /ReactNative/gm
, /ReactNativeJS/gm
), so only entries matching any of the given regexes will be emitted in entry
event. Pass the returned value to filter
property when running logkitty
.
Available only for Android.
Creates a custom filter (for example *:S
, ReactNative:D
, Hello:E
), so only entries matching given patterns will be emitted in entry
event. Pass the returned value to filter
property when running logkitty
.
Takes an entry as formats it to a string with ANSI escape codes for coloring.
Takes an error and formats it to a string with ANSI escape codes for coloring.