Skip to content

Commit

Permalink
add log module declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaliy-art committed Feb 18, 2024
1 parent 9cff4ed commit 794492e
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/builtin/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
/** @todo jit https://www.tarantool.io/en/doc/latest/reference/reference_lua/jit/ */
/** @todo json https://www.tarantool.io/en/doc/latest/reference/reference_lua/json/ */
/** @todo key_def https://www.tarantool.io/en/doc/latest/reference/reference_lua/key_def/ */
/** @todo log https://www.tarantool.io/en/doc/latest/reference/reference_lua/log/ */
/** @todo merger https://www.tarantool.io/en/doc/latest/reference/reference_lua/merger/ */
/** @todo net.box https://www.tarantool.io/en/doc/latest/reference/reference_lua/net_box/ */
/** @todo os https://www.tarantool.io/en/doc/latest/reference/reference_lua/osmodule/ */
Expand All @@ -40,6 +39,7 @@

export * from './box';
export * from './buffer';
export * from './log';
export * from './msgpack';
export * from './package';
export * from './extra';
77 changes: 77 additions & 0 deletions src/builtin/log/Log.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/** @noSelfInFile */

import { LogConfig } from './LogConfig';
import { Log } from './LogType';

/**
* Configure logging options.
*
* Note that calling `log.cfg()` before `box.cfg()` takes into account logging options specified using environment variables,
* such as `TT_LOG` and `TT_LOG_LEVEL`.
* @param cfg Logging configuration table.
*/
export declare function cfg(cfg: LogConfig): void;

/**
* @param message A log message.
* - A message can be a string.
* - A message may contain C-style format specifiers `%d` or `%s`.
* - A message may be a scalar data type or a table.
* @param args Arguments to pass to message.
*/
export declare function error(message: unknown, ...args: unknown[]): void;

/**
* @param message A log message.
* - A message can be a string.
* - A message may contain C-style format specifiers `%d` or `%s`.
* - A message may be a scalar data type or a table.
* @param args Arguments to pass to message.
*/
export declare function warn(message: unknown, ...args: unknown[]): void;

/**
* @param message A log message.
* - A message can be a string.
* - A message may contain C-style format specifiers `%d` or `%s`.
* - A message may be a scalar data type or a table.
* @param args Arguments to pass to message.
*/
export declare function info(message: unknown, ...args: unknown[]): void;

/**
* @param message A log message.
* - A message can be a string.
* - A message may contain C-style format specifiers `%d` or `%s`.
* - A message may be a scalar data type or a table.
* @param args Arguments to pass to message.
*/
export declare function verbose(message: unknown, ...args: unknown[]): void;

/**
* @param message A log message.
* - A message can be a string.
* - A message may contain C-style format specifiers `%d` or `%s`.
* - A message may be a scalar data type or a table.
* @param args Arguments to pass to message.
*/
export declare function debug(message: unknown, ...args: unknown[]): void;

/**
* @returns A PID of a logger. You can use this PID to send a signal to a log rotation program, so it can rotate logs.
*/
export declare function pid(): number;

/**
* Rotate the log.
* For example, you need to call this function to continue logging after a log rotation program renames or moves a file with the latest logs.
*/
export declare function rotate(): void;

/**
* Create a new logger with the specified name. You can configure a specific log level for a new logger using the log_modules configuration property.
* @param name A logger name.
* @returns A logger instance.
* @customName new
*/
export declare function new_(name: string): typeof Log;
35 changes: 35 additions & 0 deletions src/builtin/log/LogConfig.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export interface LogConfig {
/**
* Specifies the level of detail the log has.
*/
level?: LogLevel;

/**
* Specifies where to send the log’s output, for example, to a file, pipe, or system logger.
*/
log?: string;

/**
* If true, Tarantool does not block during logging when the system is not ready for writing, and drops the message instead.
*/
nonblock?: boolean;

/**
* Specifies the log format: `plain` or `json`.
*/
format?: 'plain' | 'json';

/**
* Configures the specified log levels for different modules.
*/
modules?: { [key: string]: LogLevel };
}

export type LogLevel =
| 1 | 'syserror'
| 2 | 'error'
| 3 | 'crit'
| 4 | 'warn'
| 5 | 'info'
| 6 | 'verbose'
| 7 | 'debug';
1 change: 1 addition & 0 deletions src/builtin/log/LogType.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as Log from './Log';
1 change: 1 addition & 0 deletions src/builtin/log/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './LogConfig';
1 change: 1 addition & 0 deletions src/log.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './builtin/log/Log';

0 comments on commit 794492e

Please sign in to comment.