Skip to content

Commit

Permalink
Merge pull request #35 from ba-st/june_improvements
Browse files Browse the repository at this point in the history
Log levels and healthcheck improvements
  • Loading branch information
gcotelli authored Jun 9, 2022
2 parents ba7f1c2 + bc6db06 commit fb27e25
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ RUN set -eu; \
ln -s /opt/pharo/launchpad-list /usr/local/bin/launchpad-list; \
ln -s /opt/pharo/launchpad-explain /usr/local/bin/launchpad-explain; \
ln -s /opt/pharo/launchpad-start /usr/local/bin/launchpad-start; \
ln -s /opt/pharo/launchpad-healthcheck /usr/local/bin/launchpad-healthcheck; \
chmod a+x /usr/local/bin/launchpad*; \
true

USER pharo

HEALTHCHECK CMD [ "launchpad-healthcheck"]
7 changes: 7 additions & 0 deletions docker/launchpad-healthcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

if [[ -z $LAUNCHPAD__COMMAND_SERVER_PORT ]]; then
LAUNCHPAD__COMMAND_SERVER_PORT=22222
fi

echo "HEALTHCHECK" | nc localhost $LAUNCHPAD__COMMAND_SERVER_PORT
1 change: 1 addition & 0 deletions docs/reference/Docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ adding some useful scripts for Launchpad-based applications:
- `launchpad-list` starts the CLI with the `list` command
- `launchpad-start` starts the CLI with the `start` command and setup
a `SIGTERM` handler for gracefully stopping the application.
- `launchpad-healthcheck` is run as the default docker `HEALTHCHECK`

## How to use as base docker image

Expand Down
2 changes: 2 additions & 0 deletions docs/reference/Logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ including a log level that can be `INFO`, `WARNING`, or `ERROR`.
To emit your logs, you can reuse `LaunchpadLogRecord` by sending one of the
`emit` messages:

- `emitTraceInfo:` will produce informational signals with trace information.
- `emitDebuggingInfo:` will produce informational signals with debugging information.
- `emitInfo:` and `emitInfo:during:` will produce informational signals.
- `emitWarning:` will produce warning signals.
- `emitError:` will produce error signals.
Expand Down
20 changes: 20 additions & 0 deletions source/Launchpad-Logging-Tests/LaunchpadLogRecordTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ LaunchpadLogRecordTest >> testEmitCombinedEvents [
assert: ( logger recordings last printString endsWith: '[ERROR] Starting app... [FAILED]' )
]

{ #category : #tests }
LaunchpadLogRecordTest >> testEmitDebug [

logger runDuring: [ LaunchpadLogRecord emitDebuggingInfo: 'Ouch!' ].

self
assert: logger recordings size equals: 1;
assert: ( logger recordings first printString endsWith: '[DEBUG] Ouch!' )
]

{ #category : #tests }
LaunchpadLogRecordTest >> testEmitError [

Expand Down Expand Up @@ -87,6 +97,16 @@ LaunchpadLogRecordTest >> testEmitInfoDuringWhenActionFails [
assert: ( logger recordings last printString endsWith: '[ERROR] Starting... [FAILED]' )
]

{ #category : #tests }
LaunchpadLogRecordTest >> testEmitTrace [

logger runDuring: [ LaunchpadLogRecord emitTraceInfo: 'Ouch!' ].

self
assert: logger recordings size equals: 1;
assert: ( logger recordings first printString endsWith: '[TRACE] Ouch!' )
]

{ #category : #tests }
LaunchpadLogRecordTest >> testEmitWarning [

Expand Down
30 changes: 29 additions & 1 deletion source/Launchpad-Logging/LaunchpadLogRecord.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Class {
#category : #'Launchpad-Logging'
}

{ #category : #actions }
LaunchpadLogRecord class >> emitDebuggingInfo: aString [

^ ( self withMessage: aString )
beForDebugging;
emit
]

{ #category : #actions }
LaunchpadLogRecord class >> emitError: aString [

Expand All @@ -28,6 +36,14 @@ LaunchpadLogRecord class >> emitInfo: aString during: aBlock [
] ifCurtailed: [ self emitError: aString , '... [FAILED]' ]
]

{ #category : #actions }
LaunchpadLogRecord class >> emitTraceInfo: aString [

^ ( self withMessage: aString )
beForTracing;
emit
]

{ #category : #actions }
LaunchpadLogRecord class >> emitWarning: aString [

Expand All @@ -48,6 +64,18 @@ LaunchpadLogRecord >> beError [
self properties at: #logLevel put: 'ERROR'
]

{ #category : #private }
LaunchpadLogRecord >> beForDebugging [

self properties at: #logLevel put: 'DEBUG'
]

{ #category : #private }
LaunchpadLogRecord >> beForTracing [

self properties at: #logLevel put: 'TRACE'
]

{ #category : #private }
LaunchpadLogRecord >> beWarning [

Expand All @@ -63,7 +91,7 @@ LaunchpadLogRecord >> initializeWithMessage: aString [
{ #category : #testing }
LaunchpadLogRecord >> isInformational [

^ self logLevel = 'INFO'
^ #( 'INFO' 'TRACE' 'DEBUG' ) includes: self logLevel
]

{ #category : #accessing }
Expand Down

0 comments on commit fb27e25

Please sign in to comment.