
144 Ill. App.3d 250 (1986)
494 N.E.2d 267
THE PEOPLE OF THE STATE OF ILLINOIS, Plaintiff-Appellee,
v.
DAVID R. SEYLER, Defendant-Appellant.
No. 5-85-0216.
Illinois Appellate Court  Fifth District.
Opinion filed June 11, 1986.
Randy E. Blue and Dan W. Evers, both of State Appellate Defender's Office, of Mt. Vernon, for appellant.
Dick Allen, State's Attorney, of Edwardsville (Kenneth R. Boyle, Stephen E. Norris, and Anne C. Fohne, all of State's Attorneys Appellate Service Commission, of counsel), for the People.
Judgment affirmed.
JUSTICE JONES delivered the opinion of the court:
Following a jury trial the defendant, David Seyler, was found guilty of the unlawful delivery of a controlled substance, specifically, cocaine in the amount of approximately 38 grams. Following a sentencing hearing he was sentenced to a term of eight years' imprisonment. He presents a single issue for our review, whether he was denied his sixth amendment right to a public trial when the trial court ordered the courtroom closed to the public, although not to members of the news media, during the testimony of undercover narcotics *251 agent John Parisi.
At the beginning of the trial the State informed the court that one of its witnesses, John Parisi, was still operating in an undercover capacity for the Metropolitan Enforcement Group of Southwestern Illinois and asked the court, in order to protect this witness, to clear the courtroom of any "unnecessary" persons. In response defense counsel stated his belief that the courtroom should not be closed to the general public. The court asked the State whether it could suggest any less restrictive measure that would protect the defendant's right to a public trial. The State answered that the proposal was the least restrictive method it believed to be available. The defendant objected, saying, "This is a situation wherein the State's Attorney's Office knew when they [sic] began the prosecution that this person would allegedly lose his cover." In making its ruling the trial court commented:
"The Court is unable to think of any less restrictive alternatives, and in balancing the Defendant's right to a public trial with the need of the State to preserve the anonymity of the agent who is still working under cover, the Court rules that the State's Motion will be allowed. However, the courtroom will remain open during the public  excuse me  during the testimony of Officer Parisi to any members of the news media who wish to be here so that they may report upon and preserve the public aspects of this trial and fulfill the news media's function of enlightening the public to criminal procedures and to pointing out that this Defendant is receiving a fair trial, and that the news media, if they care to be present, will only be enjoined with the same restriction that always applies in Illinois, that there are to be no cameras in the courtroom, and I acknowledge, Mr. Mendelsohn [defense counsel], that this case is not one which is drawing the interest of the news media, but the Court certainly feels that those gentlemen are welcome if they wish to come here.
So, the motion will be allowed."
For the record the defense stated:
"If the press is allowed to be in, then obviously they can report on John Parisi's undercover actions. Therefore, we are objecting to this Court's ruling by allowing the press but restricting it to the other general public because the accomplishment is nothing to protect Mr. John Parisi and that was the Assistant State's Attorney's whole argument to this Court."
The court inquired of counsel whether the witness, when he works undercover, *252 uses the name "John Parisi." By examining the witness the court established that he uses another name while working undercover. Thereafter the court announced that it was standing by its original ruling.
 1 The guarantee of the sixth amendment to a public trial is a safeguard against any attempt to employ the courts as instruments of persecution; the knowledge that every criminal trial is subject to contemporaneous review in the forum of public opinion is an effective restraint on possible abuse of judicial power. (In re Oliver (1948), 333 U.S. 257, 92 L.Ed.2d 682, 68 S.Ct. 499.) It is well recognized, however, that the interest of a defendant in having ordinary spectators present during trial is not an absolute right but must be balanced against other interests that might justify excluding them. (United States ex rel. Latimore v. Sielaff (7th Cir.1977), 561 F.2d 691, cert. denied (1978), 434 U.S. 1076, 55 L.Ed.2d 782, 98 S.Ct. 1266; People v. Rufus (1982), 104 Ill. App.3d 467, 432 N.E.2d 1089.) Because the guarantee of a public trial not only prohibits secrecy but also reflects a preference for an open forum, prejudice to the defendant is implied whenever the trial judge lacks substantial justification for excluding spectators, and an affirmative showing of harm is unnecessary to establish a violation of the defendant's right to a public trial. (United States ex rel. Latimore v. Sielaff (7th Cir.1977), 561 F.2d 691.) The propriety of the trial court's action depends on the circumstances of each case, and the exclusion of spectators may not exceed the scope necessary to serve the legitimate purpose for which the trial court acted. (561 F.2d 691.) The standard to be applied in determining whether there is a sufficient record to support a trial judge's finding that grounds exist to exclude spectators from a courtroom is whether there has been an abuse of discretion. 561 F.2d 691.
In United States ex rel. Lloyd v. Vincent (2d Cir.1975), 520 F.2d 1272, cert. denied (1975), 423 U.S. 937, 46 L.Ed.2d 269, 96 S.Ct. 296, involving an application for a writ of habeas corpus vacating a judgment of conviction rendered by a New York State court, the State's primary witnesses at trial had been two undercover agents from the narcotics squad of the Nassau County police department. The prosecutor had sought to close the court to spectators while the undercover agents testified on the ground that the exclusion was necessary in order to maintain the confidentiality of the agents who, at the time of trial, were still actively engaged in undercover work in the area of Nassau County. The trial court ordered the courtroom cleared of all spectators during the agents' testimony. In reaffirming its ruling the trial court stated that it was required to weigh the *253 defendant's constitutional rights against the countervailing need for confidentiality. It cited in support of its decision to close the courtroom the need to protect the identity of the agents in view of the continuing investigation they were undertaking and the danger to their lives posed by testifying publicly. On the basis of the principle that a defendant's right to a public trial must be balanced against other interests that might justify closing the courtroom to the public, the court of review concluded that the interest of the State and of the witnesses in preserving the confidentiality of undercover agents in narcotics cases presented a persuasive justification for the exclusion of the public during the limited time of the undercover agents' testimony. The court of review stated that in reaching its decision it was not unmindful of the fact that the right to a public trial fulfills important functions in our system of jurisprudence in protecting the defendant from injustice and preserving public trust in the judicial process by preventing the abuses of secret tribunals. The court acknowledged the precept that a court's discretion to order exclusion should be exercised sparingly and limited to situations where such action is deemed necessary to further the administration of justice. Of these two considerations the court observed that they must, however, "be balanced against our recognition of the risks both to the agent and to the law enforcement process attendant upon the public testimony of a police witness who is actively engaged in ongoing narcotics investigations in an undercover capacity. It is obvious that exposure in a public courtroom would not only imperil the agent but would render him useless for any further investigative activities. Moreover, the restriction on public attendance under consideration here is a limited one, covering only the period when an undercover agent is on the stand; we think it highly improbable that an exclusion thus circumscribed will seriously deprive defendants of the benefits of a public trial. [Citation.] Accordingly, we conclude, as have the New York courts, that shielding the identity of a police witness, preserving his future usefulness, and safeguarding his life provides an adequate justification for excluding the public for that limited period while an undercover agent is testifying. [Citations.]" United States ex rel. Lloyd v. Vincent (2d Cir.1975), 520 F.2d 1272, 1274-75.
 2 In his brief on appeal, as he did in the trial court, the defendant asserts that, because members of the news media were permitted in the courtroom and were, therefore, able to report on Parisi's testimony, the exclusion of spectators by the trial court was ineffective to preserve the witness' anonymity and was consequently without substantial justification. The remarks of the trial court here reveal an express *254 effort by the court to preserve the defendant's right to a public trial and the benefits to be derived therefrom while at the same time attempting to preserve the anonymity of the undercover narcotics agent, Parisi. The court allowed in the courtroom any members of the news media who wished to be present for the express purpose of preserving "the public aspect of this trial and fulfill[ing] the news media's function of enlightening the public to criminal procedures and to pointing out that this Defendant is receiving a fair trial." Like the court in Lloyd, we consider the preservation of the anonymity of a narcotics agent working undercover to be a persuasive and substantial justification for the exclusion of spectators during the agent's testimony. The trial court expressly balanced the competing considerations of the defendant's right to a public trial and the preservation of the undercover narcotics agent's anonymity without exceeding the scope necessary to preserve to some extent the agent's anonymity. Hence, we find no abuse of discretion by the trial court in excluding spectators from the courtroom during the testimony of this particular witness.
Affirmed.
WELCH and HARRISON, JJ., concur.
