SlackLogger#
- class composer.loggers.SlackLogger(include_keys=(), formatter_func=None, log_interval='1ba', max_logs_per_message=50, slack_logging_api_key=None, channel_id=None)[source]#
Log metrics to slack, using Slackโs postMessage api - https://api.slack.com/methods/chat.postMessage.
First export 2 environment variable to use this logger. 1. SLACK_LOGGING_API_KEY: To get app credentials, follow tutorial here - https://api.slack.com/tutorials/tracks/posting-messages-with-curl?app_id_from_manifest=A053W1QCEF2. 2. SLACK_LOGGING_CHANNEL_ID: Channel id to send the message (Open slack channel in web browser to look this up).
Next write script to output metrics / hparams / traces to slack channel. See example below.
trainer = Trainer( model=mnist_model(num_classes=10), train_dataloader=train_dataloader, max_duration='2ep', algorithms=[ LabelSmoothing(smoothing=0.1), CutMix(alpha=1.0), ChannelsLast(), ], loggers=[ SlackLogger( formatter_func=(lambda data: [{ 'type': 'section', 'text': { 'type': 'mrkdwn', 'text': f'*{k}:* {v}' } } for k, v in data.items()]), include_keys=['loss/train/total'], interval_in_seconds=1 ), ], ) trainer.fit()
- Parameters
formatter_func ((...) -> Any | None) โ A formatter function that returns list of blocks to be sent to slack.
include_keys (Sequence[str]) โ A sequence of metric/logs/traces keys to include in the message.
log_interval โ (int | str | Time): How frequently to log. (default:
'1ba'
)max_logs_per_message (int) โ 50): Maximum number of logs to send in a single message. Note that no more than 50 items are allowed to send in a single message.
buffer (If more than 50 items are stored in) โ
interval. (the message flushed without waiting the full time) โ