@@ -6,7 +6,7 @@ import type { LogType } from '../lib/log-types';
66import { BalenaLogBackend } from './balena-backend' ;
77import { LocalLogBackend } from './local-backend' ;
88import type { LogBackend } from './log-backend' ;
9- import type { LogMessage } from './types' ;
9+ import { LogLevel , type LogMessage } from './types' ;
1010import logMonitor from './monitor' ;
1111
1212import * as globalEventBus from '../event-bus' ;
@@ -126,18 +126,31 @@ export function logSystemMessage(
126126 }
127127}
128128
129- type ServiceInfo = { serviceId : number } ;
130- export function attach ( containerId : string , { serviceId } : ServiceInfo ) : void {
129+ type ServiceInfo = { serviceId : number ; logLevel : LogLevel } ;
130+ export function attach (
131+ containerId : string ,
132+ { serviceId, logLevel } : ServiceInfo ,
133+ ) : void {
131134 // First detect if we already have an attached log stream
132135 // for this container
133136 if ( logMonitor . isAttached ( containerId ) ) {
134137 return ;
135138 }
136139
140+ // skip service attach LogLevel is None
141+ if ( logLevel === LogLevel . None ) {
142+ return ;
143+ }
144+
137145 // We do not grab a container lock here as we are only adding it to the list of container ids to monitor
138146 // and not directly affecting the container itself, and grabbing the lock can cause a delay which means
139147 // that early messages logged from the container are missed and never sent to the backend.
140148 logMonitor . attach ( containerId , async ( message ) => {
149+ // ignore non stderr messages for an error only service
150+ if ( logLevel === LogLevel . Err && ! message . isStdErr ) {
151+ return ;
152+ }
153+
141154 await log ( { ...message , serviceId } ) ;
142155 } ) ;
143156}
0 commit comments