Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output provider logs as JSON #1517

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/provider_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: provider_image
on:
pull_request:
branches: [main, dev, staging, release/*]
types:
types:
- opened # when a PR is opened
- synchronize # when a PR is pushed to
- reopened # when a PR is reopened
Expand Down Expand Up @@ -151,7 +151,7 @@ jobs:
sleep 20s
docker logs "$CONTAINER" >& provider.log
cat provider.log
grep -oE "Version: \".*\"" provider.log || (cat provider.log && exit 1)
grep -oE "Version: \\\\\".*\\\\\"" provider.log || (cat provider.log && exit 1)

- name: Build the provider-mock package
id: build_provider_mock_package
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ async function main() {
unsolved: { count: 0 },
});

log.info(config);

if (config.devOnlyWatchEvents) {
log.warn(
`
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/tests/bundle/bundle.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ describe("provider bundle", () => {
const { stdout: runOut, stderr: runErr } = await execPromise(
`cd ${rootDir} && node dist/bundle/provider.cli.bundle.js version`,
);
assert(runOut.includes("Version:"));
assert(runErr.includes("Version:"));
}, 120000);
});
15 changes: 14 additions & 1 deletion packages/common/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { LogLevels as ConsolaLogLevels, createConsola } from "consola/browser";
import consola, {
LogLevels as ConsolaLogLevels,
createConsola,
} from "consola/browser";
import { enum as zEnum, type infer as zInfer } from "zod";
import { ProsopoEnvError } from "./error.js";

Expand Down Expand Up @@ -47,8 +50,18 @@ export function getLoggerDefault(): Logger {
return defaultLogger;
}

// biome-ignore lint/suspicious/noExplicitAny: we should be able to log anything we want, plus we can't control what external libraries log
const JSONReporter = (message: any) => {
process.stderr.write(`${JSON.stringify(message)}\n`);
};

const getLoggerAdapterConsola = (logLevel: LogLevel, scope: string): Logger => {
const logger = createConsola({
reporters: [
{
log: JSONReporter,
},
],
formatOptions: { colors: true, date: true },
}).withTag(scope);
let currentLevel = logLevel;
Expand Down