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

How can I write logs to a file #1600

Closed
xieao opened this issue Nov 9, 2020 · 8 comments
Closed

How can I write logs to a file #1600

xieao opened this issue Nov 9, 2020 · 8 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@xieao
Copy link

xieao commented Nov 9, 2020

I have a custom exporter, and i used the log like following code:

public CompletableResultCode export(Collection<SpanData> collection) {
    Gson gson = new Gson();
    ……
    log.info(gson.toJson(jsonObject)); 
    return CompletableResultCode.ofSuccess();
}

but the log show on STDOUT. How can I write the log to a file,how to configure this agent?

@xieao xieao added the bug Something isn't working label Nov 9, 2020
@iNikem iNikem added documentation Improvements or additions to documentation enhancement New feature or request and removed bug Something isn't working labels Nov 9, 2020
@trask
Copy link
Member

trask commented Nov 23, 2020

hi @xieao! are you trying to export spans to a file, or send agent debug logging to a file?

@Jayden-onl
Copy link

I also think that writing files is the right choice in many scenarios.
So we need another exporter for file writing?

@yingziisme
Copy link
Contributor

hi @xieao! are you trying to export spans to a file, or send agent debug logging to a file?

so how to export spans to a file?

@trask
Copy link
Member

trask commented Nov 1, 2021

@yingziisme
Copy link
Contributor

are you looking for something like this? https://github.com/open-telemetry/opentelemetry-java/tree/main/exporters/logging-otlp

we haven't hooked that up to the javaagent yet, primarily because there's no specification for it: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#exporter-selection

no. how can i config the file path. use java.util.logging.Logger will remapping io.opentelemetry.javaagent.bootstrap.PatchLogger

i try to use this config below, but it doesn't work

private final Logger javaUtilLogger = Logger.getLogger("TRACING_JAVA_UTIL_LOGGER");
Handler tracingFileHandler = new FileHandler(this.traceLogPath + ".%u.log", this.traceLogSize, this.traceLogCount);
tracingFileHandler.setFormatter(new TracingFormatter());
this.javaUtilLogger.addHandler(tracingFileHandler);
this.javaUtilLogger.setLevel(Level.ALL);

@trask
Copy link
Member

trask commented Nov 3, 2021

ah, that's an interesting use case, can you open an issue so we don't lose track of it?

@mateuszrzeszutek
Copy link
Member

There's already #3413 -- @yingziisme would implementing that issue fix your problem?

@trask
Copy link
Member

trask commented Aug 8, 2022

Closing in favor of #3413

@trask trask closed this as completed Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants